- Home /
Object Space Normal Map - Object Clones break Normals
I wrote a shader that does lighting in Object Space. The problem is if I clone the object with same material the lighting gets broken (wrong lighting angle and lighting looks baked), if I clone the material and use that for the clone object I loose batching.
So unless this is an expected behaviour for objects using O-S Normal Maps, this is buggy. It's like correct lighing gets rotated by some degree and gets baked like a texture, as soon as I delete the clone lighting returns to correct and expected behaviour.
As a simple test if I set Directional Light Rotation to (0,45,0) to gets same lighting when cloning the object i need to rotate Light to (45,90,0). But this doesn't solve the problem where the lighting getting baked to the object.
In vertex function I calculate these:
float3 OS_LightDir = normalize(ObjSpaceLightDir(i.vertex));
float3 OS_ViewDir = normalize(ObjSpaceViewDir(i.vertex));
float3 OS_HalfDir = normalize(OS_LightDir + OS_ViewDir);
In fragment normal direction is read directly from the texture and doesn't need any conversion except for being in range [-1,1]. This is the code:
float3 normalDirection = normalize(2 * tex2D(_BumpMap, o.tex.xy) - 1.0);
Can this be solved, or OS-Normal map is good only for single objects or no batching with multiple materials ?
Your answer
Follow this Question
Related Questions
How to force the compilation of a shader in Unity? 5 Answers
Shader Not Blending Textures on Mobile 1 Answer
Shader error in ... : Syntax error at line 30 1 Answer
CG Programming, Points Lights attenuation and light range 3 Answers
Multiple tex2D commands in fragment shader needed, is there a workaround? 0 Answers