I found this example for storing normal, texture and position in three textures. What if I need multi texturing. Do I have to use
gl_FragData[3] = texture2D(Tex1, gl_TexCoord[1].st);
also, how does it work?
#extension GL_ARB_draw_buffers : enable
varying vec3 position, normal;
uniform sampler2D Tex0;
void main(void)
{
gl_FragData[0] = vec4(position.xyz, 0.0);
gl_FragData[1] = vec4(normalize(normal.xyz), 0.0);
gl_FragData[2] = texture2D(Tex0, gl_TexCoord[0].st);
}
A) You don’t need position as you can always recover it from the depth buffer.
B) You can bake whatever consider to be useful into the G buffer.
I’m, for example, baking the following attributes:
surface diffuse color (may be taken from multiple textures)
surface specular color + shininess factor
world-space normal
#extension GL_ARB_draw_buffers : enable
varying vec3 position, normal;
uniform sampler2D Tex0;
uniform sampler2D Tex1;
void main(void)
{
vec4 color0 = texture2D(Tex0, gl_TexCoord[0].st);
vec4 color1 = texture2D(Tex1, gl_TexCoord[1].st);
gl_FragData[0] = vec4(position.xyz, 0.0); // you don't need this
gl_FragData[1] = vec4(normalize(normal.xyz), 0.0);
gl_FragData[2] = color0 * color1; // multiplicative blend
}
system
Closed
October 19, 2021, 7:26pm
4
This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.