hi there,
due to unity’s new feature of batching shadow collectors and shadow casters shaders which use a custom vertex animation seem to cast and receive wrong shadows (tested in unity 4.2.1 indie, forward rendering): the position of the projected shadows does not fit the position of the drawn mesh:
can anybody confirm this or does even have a solution for this?
lars
Are they object-space vertex animations?
You might have to make them world-space if you can, so that no matter how they’re batched, it’ll look correct.
hi farfarer,
many thanks for the answer.
the animations are object space based, right.
and i have already tested to make them use world space but then scaled instances got distorted…
well i will have to test some more,
lars
hi there,
finally i have solved my problem.
i had to covert ALL vertex related inputs (position and normal) into world space AND use unity scale…
so this might be how a vertex animation could look like this:
inline float4 myVertecAnimation (float4 pos, float3 normal, float your animationParameter) {
pos.xyz = mul( _Object2World, pos).xyz;
normal.xyz = mul( _Object2World, float4(normal, 0.0) ).xyz;
// your animation here, eg.:
pos.xyz += normal.xyz * animationParameter.xxx;
// finally bring pos back to local space and scale it!
pos.xyz = mul( _World2Object, pos).xyz * unity_Scale.w;
return pos;
}
this function will work in all passes: the regular one, shadow collector and shadow caster pass.
absolutely no rocket science but nevertheless it took me quite a while…
lars