unity3d - Water normals don't offset -


i working on water shader have run problems. looks normals aren't getting same offset vertexes. can see white plane belof water shadow of water cast upon, exept white plane not object normals of water mesh didn't move block part of shadow. please need can't find knows is.

enter image description here

this code:

shader "custom/noobshader_04" {      properties {          _color ("color", color) = (0,0.55,0.83,1)          _diffuse ("diffuse map", 2d) = "white" {}          _displacement ("displacement map", 2d) = "white" {}           _scale ("wave scale", float) = 0.7          _frequency ("frequency", float) = 0.6          _speed ("speed", float) = 0.5       }      subshader {          pass{          tags { "lightmode" = "forwardbase"}          cgprogram          #pragma vertex vert          #pragma fragment frag           float4 _color;          sampler2d _displacement;          sampler2d _diffuse;           float _scale;          float _frequency;          float _speed;           float4 _lightcolor0;           struct vertexoutput          {              float4 pos : sv_position;              float3 nor : normal;              float4 col : color;              float4 tex : texcoord0;          };           struct vertexinput          {              float4 vertex : position;              float3 normal : normal;              float4 texcoord : texcoord0;          };           struct fragmentoutput          {              float4 color : color;          };           vertexoutput vert (vertexinput i)          {              vertexoutput vout;               float4 disp = tex2dlod(_displacement, float4(i.texcoord.x * _frequency + (_time.x * _speed), i.texcoord.y * _frequency + (_time.x * _speed),0.0,0.0));              float4 newpos = i.vertex;              float3 newnor = i.normal;              newpos.y += _scale * disp.y;               newnor.y += _scale * disp.y;               vout.nor = newnor;              vout.pos = mul(unity_matrix_mvp,newpos);              vout.tex = i.texcoord;               float3 normaldirection = normalize( mul(float4(newnor,0.0),_world2object).xyz);              float3 lightdirection = normalize(_worldspacelightpos0.xyz);              float atten = 1.0;               float3 diffuserefflection = atten * _lightcolor0.xyz * _color.rgb *  max( 0.0, dot(normaldirection, lightdirection));               vout.col = float4(diffuserefflection, 1.0);               return vout;          }           fragmentoutput frag(vertexoutput v)           {              fragmentoutput fout;              float4 tex = tex2d(_diffuse,float4(v.tex.x * _frequency + (_time.x * _speed), v.tex.y * _frequency + (_time.x * _speed),0.0,0.0));              fout.color = tex * v.col + unity_lightmodel_ambient.xyzw;              return fout;          }          endcg          }      }       fallback "diffuse"  } 

you can see white plane belof water shadow of water cast upon, exept white plane not object normals of water mesh didn't move block part of shadow.

i tried shader , can't see plane, except 1 add scene receive casted shadow. in case, water's normals don't have plane.

it looks normals aren't getting same offset vertexes

again, not sure mean here. offset has no effect on normals, because express orientation, not position.

if mean projected shadow on plane, doesn't account vertex offset, it's because auto generated shadow caster pass, can't take in consideration vertex offset. need explicitly implement it.

something like:

pass     {          name "shadowcaster"         tags { "lightmode" = "shadowcaster" }          fog {mode off}         zwrite on ztest less cull off         offset 1, 1          cgprogram          #pragma vertex vert         #pragma fragment frag         #pragma fragmentoption arb_precision_hint_fastest         #pragma multi_compile_shadowcaster         #include "unitycg.cginc"           v2f vert( appdata_full v )         {             v2f o;             //transfer_shadow_caster(o) how default shadow casted             o.pos = ...;// put here calculation taking account vertex offset. repeating same calculation wrote forward pass in regards vertex position            return o;         }          float4 frag( v2f ) : color         {             fixed4 texcol = tex2d( _maintex, i.uv );             clip( texcol.a - _cutoff );             shadow_caster_fragment(i)         }         endcg     }  

Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -