glsl - OpenGL ES3 framebuffer draw depth in red scale -


so after hard work make directional light shadow map work can see shadow map rendered on quad drawn depth gl_depth_component16 , type gl_unsigned_short , or gl_depth_component32f , type gl_float in red scale not gray scale

depth map

the problem used many methods calculate depth draw shadow no shadow appears.

glcullface(gl_front);             glgenframebuffers(1, &depthmapfbo);             glbindframebuffer(gl_framebuffer, depthmapfbo);             glgentextures(1, &depthmap);             glbindtexture(gl_texture_2d, depthmap);             glteximage2d(gl_texture_2d, 0, gl_depth_component16, shadow_width, shadow_height, 0, gl_depth_component, gl_unsigned_short, null);             gltexparameteri(gl_texture_2d, gl_texture_min_filter, gl_nearest);             gltexparameteri(gl_texture_2d, gl_texture_mag_filter, gl_nearest);             gltexparameteri(gl_texture_2d, gl_texture_wrap_s, gl_clamp_to_edge);             gltexparameteri(gl_texture_2d, gl_texture_wrap_t, gl_clamp_to_edge);              gltexparameteri(gl_texture_2d, gl_texture_compare_func, gl_lequal);             gltexparameteri(gl_texture_2d, gl_texture_compare_mode, gl_compare_ref_to_texture);              glframebuffertexture2d(gl_framebuffer, gl_depth_stencil_attachment, gl_texture_2d, depthmap, 0);             gldrawbuffers(1, gl_none);             glreadbuffer(gl_none);             glbindframebuffer(gl_framebuffer, 0);             glbindtexture(gl_texture_2d, 0);             glcullface(gl_back); if (glcheckframebufferstatus(gl_framebuffer) != gl_framebuffer_complete) {     logi("framebuffer incomplete"); } 

and fragment is:

uniform mediump sampler2dshadow  shadowmap; ...... float bias = 0.005; float visibility = 1.0; (int i=0;i<4;i++){     int index = i;     visibility -= 0.2*(1.0-texture( shadowmap, vec3(fragposlightspace.xy + poissondisk[index]/700.0,  (fragposlightspace.z-bias)/fragposlightspace.w) ));            } result =light.intensity* (visibility * (diffuse + specular)); 

...but in red scale not gray scale

a texture depth component format, sutch gl_depth_component16 or gl_depth_component32f has 1 color channel, red color channel.
if read data texture sampler, depth component texture bound to, green, blue , alpha channel set automatically.

the image format specification of khronos group says:

image formats not have store each component. when shader samples such texture, still resolve 4-value rgba vector. components not stored image format filled in automatically. zeros used if r, g, or b missing, while missing alpha resolves 1.

note: texture swizzling can change missing values are.

because of that, red color set, green , blue color set 0 , alpha channel 1. causes opaque red surface.

if want read grayscale color depth component texture, have read red color channel , have apply red color channel green , blue color, too.

you have adapt code this:

float depth          = texture( shadowmap, ..... ).r; vec3  depthgrayscale = vec3( depth ); 

or this:

vec3  depthgrayscale = texture( shadowmap, ..... ).rrr; 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -