关于Unity动态物体无法向使用使用custom shader和lightmap的物体投射阴影
最近在做unity shader forge和marmoset的优化,TA那边遇到了一个阴影显示的问题,具体如下:
- "Test" {
- SubShader {
- Tags { "RenderType" = "Opaque"}
- // This pass acts the same as the surface shader first pass.
- // Calculates per-pixel the most important directional light with shadows,
- // then per-vertex the next 4 most important lights,
- // then per-vertex spherical harmionics the rest of the lights,
- // and the ambient light value.
- Pass {
- Tags {"LightMode" = "ForwardBase"}
- CGPROGRAM
- #pragma multi_compile_fwdbase
- #pragma vertex vert
- #pragma fragment frag
- #pragma fragmentoption ARB_precision_hint_fastest
- #include "UnityCG.cginc"
- #include "AutoLight.cginc"
- struct Input
- {
- float4 pos : SV_POSITION;
- float3 vlight : COLOR;
- float3 lightDir : TEXCOORD1;
- float3 vNormal : TEXCOORD2;
- LIGHTING_COORDS(,)
- };
- Input vert(appdata_full v)
- {
- Input o;
- o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
- // Calc normal and light dir.
- o.lightDir = normalize(ObjSpaceLightDir(v.vertex));
- o.vNormal = normalize(v.normal).xyz;
- // Calc spherical harmonics and vertex lights. Ripped from compiled surface shader
- float3 worldPos = mul(_Object2World, v.vertex).xyz;
- float3 worldNormal = mul((float3x3)_Object2World, SCALED_NORMAL);
- o.vlight = float3();
- #ifdef LIGHTMAP_OFF
- float3 shlight = ShadeSH9(float4(worldNormal, 1.0));
- o.vlight = shlight;
- #ifdef VERTEXLIGHT_ON
- o.vlight += Shade4PointLights (
- unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0,
- unity_LightColor[].rgb, unity_LightColor[].rgb, unity_LightColor[].rgb, unity_LightColor[].rgb,
- unity_4LightAtten0, worldPos, worldNormal
- );
- #endif // VERTEXLIGHT_ON
- #endif // LIGHTMAP_OFF
- TRANSFER_VERTEX_TO_FRAGMENT(o);
- return o;
- }
- float4 _LightColor0; // Contains the light color for this pass.
- half4 frag(Input IN) : COLOR
- {
- IN.lightDir = normalize ( IN.lightDir );
- IN.vNormal = normalize ( IN.vNormal );
- float atten = LIGHT_ATTENUATION(IN);
- float3 color;
- float NdotL = saturate( dot (IN.vNormal, IN.lightDir ));
- color = UNITY_LIGHTMODEL_AMBIENT.rgb * ;
- color += IN.vlight;
- color += _LightColor0.rgb * NdotL * ( atten * );
- return half4(color, 1.0f);
- }
- ENDCG
- }
- // Take this pass out if you don't want extra per-pixel lights.
- // Just set the other lights' Render Mode to "Not Important",
- // and they will be calculated as Spherical Harmonics or Vertex Lights in the above pass instead.
- Pass {
- Tags {"LightMode" = "ForwardAdd"}
- CGPROGRAM
- #pragma multi_compile_fwdadd
- #pragma vertex vert
- #pragma fragment frag
- #pragma fragmentoption ARB_precision_hint_fastest
- #include "UnityCG.cginc"
- #include "AutoLight.cginc"
- struct Input
- {
- float4 pos : SV_POSITION;
- float3 lightDir : TEXCOORD1;
- float3 vNormal : TEXCOORD2;
- };
- Input vert(appdata_full v)
- {
- Input o;
- o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
- // Calc normal and light dir.
- o.lightDir = normalize(ObjSpaceLightDir(v.vertex));
- o.vNormal = normalize(v.normal).xyz;
- // Don't need any ambient or vertex lights in here as this is just an additive pass for each extra light.
- // Shadows won't work here, either.
- return o;
- }
- float4 _LightColor0; // Contains the light color for this pass.
- half4 frag(Input IN) : COLOR
- {
- IN.lightDir = normalize ( IN.lightDir );
- IN.vNormal = normalize ( IN.vNormal );
- float3 color;
- float NdotL = saturate( dot (IN.vNormal, IN.lightDir ));
- color = _LightColor0.rgb * NdotL;
- return half4(color, 1.0f);
- }
- ENDCG
- }
- }
- FallBack "Diffuse"
- }
- "Test" {
#pragma surface MarmosetSurfMarmosetDirect vertex:MarmosetVert fullforwardshadows






关于Unity动态物体无法向使用使用custom shader和lightmap的物体投射阴影的更多相关文章
- Unity 3D动态修改Shader状态,使物体透明等等
Unity动态改Shader状态透明 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- ...
- Unity动态加载和内存管理(三合一)
原址:http://game.ceeger.com/forum/read.php?tid=4394#info 最近一直在和这些内容纠缠,把心得和大家共享一下: Unity里有两种动态加载机制:一是Re ...
- Unity动态批处理和静态批处理学习
本文转自:http://blog.csdn.net/lyh916/article/details/45725499,请点击链接查看楼主大神原文,尊重楼主版权. 参考链接:Unity圣典:http:// ...
- [Unity][Heap sort]用Unity动态演示堆排序的过程(How Heap Sort Works)
[Unity][Heap sort]用Unity动态演示堆排序的过程 How Heap Sort Works 最近做了一个用Unity3D动态演示堆排序过程的程序. I've made this ap ...
- Unity动态字体在手机上出现字体丢失问题解决
在我们游戏的开发过程中,在部分手机上运行游戏的时候,出现了字体丢失的问题,出问题的手机似乎用的都是高通芯片. 使用的unity是4.2.0版本,ngui是3.4.9版本. 在unity的论坛及unit ...
- 【Unity Shaders】使用CgInclude让你的Shader模块化——Unity内置的CgInclude文件
本系列主要參考<Unity Shaders and Effects Cookbook>一书(感谢原书作者),同一时候会加上一点个人理解或拓展. 这里是本书全部的插图. 这里是本书所需的代码 ...
- Unity动态改变物体遮挡关系
在动态创建物体时,通常同父级下先创建的子物体会被后创建的遮挡,此时就需要我们用代码改变对象的层级. GameObject go;go.transform.SetAsLastSibling();//设置 ...
- unity动态加载(翻译) .
AssetBundles are files which you can export from Unity to contain assets of your choice. These files ...
- Unity 动态载入Panel并实现淡入淡出
unity版本:4.5 NGUI版本:3.6.5 参考链接:http://tieba.baidu.com/p/3206366700,作者:百度贴吧 水岸上 动态载入NGUI控件,这里用Panel为例说 ...
随机推荐
- jsrender for array 和for object语法
for array 循环数组 循环使用案例 定义数组数据 var data = { names: ["Maradona","Pele","Ronald ...
- selenium3各种报错解决办法
解决办法全在这个链接里 http://learn-automation.com/use-firefox-selenium-using-geckodriver-selenium-3
- Noip2016のmengbier
Day0 上午10点多上了火车,向三位学长问了一路去年noip他们是用什么心态去考的,明明老师和同学都说我正常发挥应该没什么问题但心里就是紧张的不行,就是害怕犯个sb错误爆上一道题TAT. 去试机.. ...
- css-使用line-height实现垂直居中的一些问题
网上都是这么说的,把line-height值设置为height一样大小的值可以实现单行文字的垂直居中.这句话确实是正确的,但其实也是有问题的.问题在于height,看我的表述:"把line- ...
- jquery使用历经
1.动态绑定 当要绑定事件时忽然没有效果了,这种情况出现在通过给通过js拼出来的button绑定的事件,后来查了资料,可以用live事件委托,或者用on,因为是给button绑定事件所以还可以直接写在 ...
- 【PowerOJ1740】 圆桌问题
https://www.oj.swust.edu.cn/problem/show/1740 (题目链接) 题意 n个单位的人去吃饭,m张餐桌,同一单位的人不能在同一餐桌,问可行方案. Solution ...
- 【bzoj1597】 土地购买
http://www.lydsy.com/JudgeOnline/problem.php?id=1597 (题目链接) 题意 购买n个矩形,每块土地的价格是它的面积,但可以同时购买多快土地. 这些土地 ...
- eclipse无法识别javax.servlet.*的问题
这个问题对应的jar包为servlet-api.jar,默认jdk是没有这个包,需要在web容器上找到这个包,比如我用的是tomcat,那么可以在:“\Tomcat 7.0\lib\servlet-a ...
- css选择器([class*=" icon-"], [class^=icon-] 的区别)
官方解释: [attribute^=value],a[src^="https"],选择其 src 属性值以 "https" 开头的每个 <a> 元素 ...
- Linux下的删除命令
Linux:rm Windows:del rm parameter: -f, --force 忽略不存在的文件,从不给出提示.-i, --interactive 进行交互式删除-r, -R, - ...