Tangent and write depth to render target ! !!

I am programming in 3d game, very need tangent to normal mapping and write depth info of scene to render target for shadow mapping.

1 Like

Yeah, I didn’t find tangent variables in the shader. Would be very useful.
For depth you could use a separate render target or write depth to the alpha channel if you don’t need it.

1 Like

Can you describe how to write depth to the alpha channel in detail ?

You calculate the distance from the camera and assign this value to the .a or .z component of the gl_FragColor. In the very basic terms and fixed camera it could be as simple as

-- Vertex shader
var_depth = (1.0 + gl_Position.z) * 1.5;

-- Fragment shader
gl_FragColor = vec4(color.rgb, var_depth);

I had it this way in one of my projects, you can change depth calculation to something more meaningful.

1 Like

Can you share me some demo or example code ? I have tried several times but failed.