I have complete-filled depth texture, but it seems not to get a proper value from it.
GLSL code, fragment shader:
uniform sampler2D depth_tex;
uniform float viewport_w;
uniform float viewport_h;
void main()
{
vec2 coord = vec2(gl_FragCoord.xy);
float depth = texture2D(depth_tex, vec2(coord.x / viewport_w, coord.y / viewport.h)).r;
float c = material_amb * depth; // material_amb is preset by host
out_color = vec4(c, c, c, 1.0f);
}
I expect model's color will be changed by vertices' depth, but I can't see everything. Of course, I can see model without multiplying depth. depth texture's type is GL_DEPTH_COMPONENT, GL_FLOAT. What's the problem? I think a solution to get a depth value from a texture is wrong, but I don't know the reason. Where is a depth value stored in? And How can I get a depth value?
depthdirectly, multiply byfract(depth), that way you can figure out if the values are outside the[0..1]range to begin with. - UncleZeivviewport.hshould beviewport_h... maybe the shader is not compiling when you are usingdepth? - UncleZeiv