Friday 8 March 2013

Real-Time, Seamless Box Projection Mapping



I sample 3 times the same texture and The UV are created with the world position.


Code sample:
.......
float2 uvX = pos.yz;
float2 uvY = pos.zx;
float2 uvZ = pos.xy;
float4 textureX = tex2D(texSampler, uvX);
float4 textureY = tex2D(texSampler, uvY);
float4 textureZ = tex2D(texSampler, uvZ);
......
The  normals are used to lerp the textures.
......
float maskY = smoothstep(0.5f, 0.8f, abs(normal.y));
float maskZ = smoothstep(0.5f, 0.8f, abs(normal.z));
float4 finalLerp = lerp(textureX, textureY, maskY);
finalLerp = lerp(final, textureZ, maskZ);
......
This technique is more suitable for organic materials.

Video of the hlsl shader in 3dsmax



No comments:

Post a Comment