IOS shadowmapping

Greetings long time no post,
I posted this on the apple developer website yesterday but seeing as they only appear to get 1 topic per day in the gl forum, the site looks a bit dead, Ill try here
If I run the code on the IOS device I get the two following errors
GL_INVALID_ENUM <- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE)
[LEFT]GL_INVALID_ENUM <- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL)
When I run the run example on the IOS device the depthtexture is being treated as a standard rgba texture, but on the IOS simulator its being treated as a depthtexture

Im pretty sure Ive got everything set up correct (though theres a total lack of shadowmapping examples using a depthtexture on the web for IOS)

if I run in the IOS simulator then no errors

this may be related. In both the simulator & the device I get the following message
2012-07-08 11:41:16.477 RollyBolly[1402:11003] Program validate log:
Validation Error: Program does not contain vertex shader. Results will be undefined.
Validation Error: Program does not contain fragment shader. Results will be undefined.
(sounds major right) but it works correct on the IOS simulator

[/LEFT]

#extension GL_EXT_shadow_samplers : require

uniform sampler2DShadow TEX7;

float shadow = shadow2DProjEXT( TEX7, v_shadowCoord );

now if I change it to the following, then it gives no error message
uniform sampler2D TEX7;
float shadow = texture2DProj( TEX7, v_shadowCoord.xyz ).x;

cheers zed

Things to try:
Make sure filtering is GL_NEAREST, and set before the compare mode;
Try doing the ref comparison manually.
glTexParameterf instead of glTexParameteri, the enum handling might have been forgotten in the i version.

Did the shader compile and link at all?

Ta Ilian, I tried glTexParameterf same result

The programs compile & link even though this gets reported back (both IOS & simulator)
Validation Error: Program does not contain vertex shader. Results will be undefined.
Validation Error: Program does not contain fragment shader. Results will be undefined.
I would expect the shader not to work based on this text, but it works 100% correct on simulator (boolean result) but on the device the depthtexture is a colortexture
float shadow = shadow2DProjEXT( TEX7, v_shadowCoord ); on simulator returns 0.0 or 1.0
on device it returns between 0.0 and 1.0 i.e. a grey color

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_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_MODE_EXT, GL_COMPARE_REF_TO_TEXTURE_EXT );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_EXT, GL_LEQUAL);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NULL ); // also tried UNSIGNED_INT
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, texID, 0);

What about manual comparison of Z ? I think it should work, and furthermore not require that extension.

  1. if you’ve included the proper headers, GL_COMPARE_REF_TO_TEXTURE should not compile. You meant GL_COMPARE_REF_TO_TEXTURE_EXT, since this functionality is an extension to ES2.

  2. what device are you using, and does it export EXT_shadow_samplers?

@Ilian yes
float shadow = (v_shadowCoord.z / v_shadowCoord.w <= texture2DProj(TEX7, v_shadowCoord).x ) ? 1.0 : 0.0;
works but this is obviously gonna be much slower than
float shadow = shadow2DProjEXT( TEX7, v_shadowCoord );

I wouldnt mind if it was only a few objects/fragments onscreen, but this is gonna be applied to practically every pixel, and the powervr hardware aint exactly fast to start with
Surely someone heres using GL_OES_depth_texture on IOS hardware, is it working for them?

@arekkusu yes see the above code Im using _EXT, I think the apple profiler program strips off the _EXT etc tags when reporting the error
ipod touch 4, yes heres the extension string
GL_OES_depth_texture GL_OES_depth24 GL_OES_element_index_uint GL_OES_fbo_render_mipmap GL_OES_mapbuffer GL_OES_packed_depth_stencil GL_OES_rgb8_rgba8 GL_OES_standard_derivatives GL_OES_texture_float GL_OES_texture_half_float GL_OES_vertex_array_object GL_EXT_blend_minmax GL_EXT_debug_label GL_EXT_debug_marker GL_EXT_discard_framebuffer GL_EXT_read_format_bgra GL_EXT_separate_shader_objects GL_EXT_shader_texture_lod GL_EXT_texture_filter_anisotropic GL_APPLE_framebuffer_multisample GL_APPLE_rgb_422 GL_APPLE_texture_format_BGRA8888 GL_APPLE_texture_max_level GL_IMG_read_format GL_IMG_texture_compression_pvrtc

It looks to me like EXT_shadow_samplers is not exported by your device, so you’ll need to perform the depth comparison manually, as Ilian suggested.

EXT_shadow_samplers is exported on SGX543-based devices (and the simulator.)

cheers arekkusu I think youre right I saw GL_OES_depth_texture & assumed shadowmapping is supported (as the original & most common usage of depth textures is shadowmapping), its a bit crazy why they dont

I think I’d go with a solution like:


#ifdef GL_EXT_shadow_samplers
#define SHADOW2DPROJ(tex,coord) shadow2DProjEXT( tex, coord );
#define SHADOWSAMPLER(tex) uniform sampler2DShadow tex
#else
// 1 varying, 2 fmad, zero-cost saturation = 3 USSE cycles
#define SHADOW2DPROJ(tex,coord)  clamp((coord.w * texture2DProj(tex, coord).x - coord.z) * 1000000.0 + 1.0, 0.0, 1.0);
#define SHADOWSAMPLER(tex) uniform sampler2D tex
#endif

Though I don’t know enough about SGX.

P.S. The alternative, with “/ … <= … 1.0 : 0.0” would be 3 to 5 cycles instead, afaik (and less precise).

…as a side note, SGX GLES1/2 drivers on IOS are going to behave differently than on any other device often… essentially from Apple putting their pixie dust on the GLES1/2 implementations… also the “GL_EXT_separate_shader_objects” of GLES1/2 is not at all the same as GL_EXT_separate_shader_objects of OpenGL… it is more like GL_ARB_separate_shader_objects but not quite the same either (I think)…

thanks for that Ilian
@kRogue yes Ive come across a few things with the powervr hardware that you have to do differently esp if you want to have decent performance