ptitSeb / gl4es

GL4ES is a OpenGL 2.1/1.5 to GL ES 2.0/1.1 translation library, with support for Pandora, ODroid, OrangePI, CHIP, Raspberry PI, Android, Emscripten and AmigaOS4.
http://ptitseb.github.io/gl4es/
MIT License
711 stars 160 forks source link

gl_EyePlane uniform #334

Open Sisah2 opened 3 years ago

Sisah2 commented 3 years ago

Hello, it seems that this uniform is emulated, but not filled with any values. Would it be possible to implement it to gles2? This thing is crucial for shadows in openmw.

ptitSeb commented 3 years ago

It's not filled? Maybe there is a bug in fpe.c, because IIRC, the values are stored and ready to be injected in gles2 shaders.

Sisah2 commented 3 years ago

It using custom shaders, not ffp emulated ones, problem is maybe only here.

ptitSeb commented 3 years ago

No, it should work on custom shaders too.

ptitSeb commented 3 years ago

The uniform is setup here: https://github.com/ptitSeb/gl4es/blob/master/src/gl/fpe.c#L1345 it should be renamed to _gl4es_eyePlane by shaderconv.

Sisah2 commented 3 years ago

if i dump the values here it look like this

08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[0].S_E = 1.000000,0.000000,0.000000,0.000000 08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[0].T_E = 0.000000,1.000000,0.000000,0.000000 08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[0].R_E = 0.000000,0.000000,0.000000,0.000000 08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[0].Q_E = 0.000000,0.000000,0.000000,0.000000 08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[1].S_E = 1.000000,0.000000,0.000000,0.000000 08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[1].T_E = 0.000000,1.000000,0.000000,0.000000 08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[1].R_E = 0.000000,0.000000,0.000000,0.000000 08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[1].Q_E = 0.000000,0.000000,0.000000,0.000000 08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[2].S_E = 1.000000,0.000000,0.000000,0.000000 08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[2].T_E = 0.000000,1.000000,0.000000,0.000000 08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[2].R_E = 0.000000,0.000000,0.000000,0.000000 08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[2].Q_E = 0.000000,0.000000,0.000000,0.000000 08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[3].S_E = 1.000000,0.000000,0.000000,0.000000 08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[3].T_E = 0.000000,1.000000,0.000000,0.000000 08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[3].R_E = 0.000000,0.000000,0.000000,0.000000 08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[3].Q_E = 0.000000,0.000000,0.000000,0.000000 08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[4].S_E = 1.000000,0.000000,0.000000,0.000000 08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[4].T_E = 0.000000,1.000000,0.000000,0.000000 08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[4].R_E = 0.000000,0.000000,0.000000,0.000000 08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[4].Q_E = 0.000000,0.000000,0.000000,0.000000 08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[5].S_E = -151.780090,-8978.771484,-605004.750000,2.299689 08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[5].T_E = -350.975281,-20762.382812,-1399004.375000,5.317767 08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[5].R_E = 7415.657715,438682.593750,29559172.000000,-112.357620 08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[5].Q_E = -303.561157,-17957.542969,-1210009.500000,4.599377 08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[6].S_E = -82.697777,-4892.102539,-329638.093750,1.252990 08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[6].T_E = -157.731552,-9330.807617,-628725.562500,2.389854 08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[6].R_E = 2861.062500,169249.765625,11404334.000000,-43.349110 08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[6].Q_E = -165.395935,-9784.205078,-659276.187500,2.505980 08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[7].S_E = -42.766129,-2529.888428,-170468.140625,0.647968 08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[7].T_E = -46.031006,-2723.021729,-183481.781250,0.697434 08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[7].R_E = 1466.929443,86778.070312,5847252.500000,-22.226040 08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[7].Q_E = -85.532402,-5059.776855,-340936.281250,1.295936 08-14 18:04:37.702 16633 19749 I LIBGL : glstate->texgen[8].S_E = 1.000000,0.000000,0.000000,0.000000 08-14 18:04:37.703 16633 19749 I LIBGL : glstate->texgen[8].T_E = 0.000000,1.000000,0.000000,0.000000 08-14 18:04:37.703 16633 19749 I LIBGL : glstate->texgen[8].R_E = 0.000000,0.000000,0.000000,0.000000 08-14 18:04:37.703 16633 19749 I LIBGL : glstate->texgen[8].Q_E = 0.000000,0.000000,0.000000,0.000000 08-14 18:04:37.703 16633 19749 I LIBGL : glstate->texgen[9].S_E = 1.000000,0.000000,0.000000,0.000000 08-14 18:04:37.703 16633 19749 I LIBGL : glstate->texgen[9].T_E = 0.000000,1.000000,0.000000,0.000000 08-14 18:04:37.703 16633 19749 I LIBGL : glstate->texgen[9].R_E = 0.000000,0.000000,0.000000,0.000000 08-14 18:04:37.703 16633 19749 I LIBGL : glstate->texgen[9].Q_E = 0.000000,0.000000,0.000000,0.000000 08-14 18:04:37.703 16633 19749 I LIBGL : glstate->texgen[10].S_E = 1.000000,0.000000,0.000000,0.000000 08-14 18:04:37.703 16633 19749 I LIBGL : glstate->texgen[10].T_E = 0.000000,1.000000,0.000000,0.000000 08-14 18:04:37.703 16633 19749 I LIBGL : glstate->texgen[10].R_E = 0.000000,0.000000,0.000000,0.000000 08-14 18:04:37.703 16633 19749 I LIBGL : glstate->texgen[10].Q_E = 0.000000,0.000000,0.000000,0.000000 08-14 18:04:37.703 16633 19749 I LIBGL : glstate->texgen[11].S_E = 1.000000,0.000000,0.000000,0.000000 08-14 18:04:37.703 16633 19749 I LIBGL : glstate->texgen[11].T_E = 0.000000,1.000000,0.000000,0.000000 08-14 18:04:37.703 16633 19749 I LIBGL : glstate->texgen[11].R_E = 0.000000,0.000000,0.000000,0.000000 08-14 18:04:37.703 16633 19749 I LIBGL : glstate->texgen[11].Q_E = 0.000000,0.000000,0.000000,0.000000 08-14 18:04:37.703 16633 19749 I LIBGL : glstate->texgen[12].S_E = 1.000000,0.000000,0.000000,0.000000 08-14 18:04:37.703 16633 19749 I LIBGL : glstate->texgen[12].T_E = 0.000000,1.000000,0.000000,0.000000 08-14 18:04:37.703 16633 19749 I LIBGL : glstate->texgen[12].R_E = 0.000000,0.000000,0.000000,0.000000 08-14 18:04:37.703 16633 19749 I LIBGL : glstate->texgen[12].Q_E = 0.000000,0.000000,0.000000,0.000000 08-14 18:04:37.703 16633 19749 I LIBGL : glstate->texgen[13].S_E = 1.000000,0.000000,0.000000,0.000000 08-14 18:04:37.703 16633 19749 I LIBGL : glstate->texgen[13].T_E = 0.000000,1.000000,0.000000,0.000000 08-14 18:04:37.703 16633 19749 I LIBGL : glstate->texgen[13].R_E = 0.000000,0.000000,0.000000,0.000000 08-14 18:04:37.703 16633 19749 I LIBGL : glstate->texgen[13].Q_E = 0.000000,0.000000,0.000000,0.000000 08-14 18:04:37.703 16633 19749 I LIBGL : glstate->texgen[14].S_E = 1.000000,0.000000,0.000000,0.000000 08-14 18:04:37.703 16633 19749 I LIBGL : glstate->texgen[14].T_E = 0.000000,1.000000,0.000000,0.000000 08-14 18:04:37.703 16633 19749 I LIBGL : glstate->texgen[14].R_E = 0.000000,0.000000,0.000000,0.000000 08-14 18:04:37.703 16633 19749 I LIBGL : glstate->texgen[14].Q_E = 0.000000,0.000000,0.000000,0.000000 08-14 18:04:37.703 16633 19749 I LIBGL : glstate->texgen[15].S_E = 1.000000,0.000000,0.000000,0.000000 08-14 18:04:37.703 16633 19749 I LIBGL : glstate->texgen[15].T_E = 0.000000,1.000000,0.000000,0.000000 08-14 18:04:37.703 16633 19749 I LIBGL : glstate->texgen[15].R_E = 0.000000,0.000000,0.000000,0.000000 08-14 18:04:37.703 16633 19749 I LIBGL : glstate->texgen[15].Q_E = 0.000000,0.000000,0.000000,0.000000

textures 5 6 7 are shadow maps hopefully, but if i check for them in shaders with for(int i = 0; i < 16; i++) { if(gl_EyePlaneS[i] != vec4(0.0) || gl_EyePlaneR[i] != vec4(0.0) || gl_EyePlaneT[i] != vec4(0.0) || gl_EyePlaneQ[i] != vec4(0.0) ) gl_FragData[0].x = 1.0; }

then nothing happen, all of them are zeroes

Sisah2 commented 3 years ago

it failing/returning in GoUniformfv at location ==-1 and sometimes at memcmp(glprogram->cache.cache + m->cache_offs, value, rsize)==0

its called with arguments like this GoUniformfv(0x790a272000[207], -1, 4, 1, 0x7a2b5a5d08) =>(0.000688...)

Sisah2 commented 3 years ago

seems like _gl4esEyePlaneQ uniforms are filled instead of _gl4es_EyePlaneQ[] are those two supposed to contain same values? or its a different thing? one is reffered as "texgeneye_code" second "texgeneye_fpe_code"

Sisah2 commented 3 years ago

Seems like there is more in this, gl_EyePlaneX[N] is definitely broken, _gl4es_EyePlaneX_N contain values, but they seems to be wrong (created also new uniform with values from here https://github.com/ptitSeb/gl4es/blob/master/src/gl/fpe.c#L1345 yet its wrong too) , openmw shadows shader is basically simple, its result of all 4 gl_eyeplanes multiplied by view vector ( gl_ModelViewMatrix * gl_Vertex) which is then passed to texture2dproj. Shadow texture is fine so it seems to be only about texgen :(

Sisah2 commented 3 years ago

Just small update about openmw shadows, the devs found a way to calculate shadow texture coordinates, but there is new issue, openmw shadows technique use GL_DEPTH_CLAMP which is not supported by gl4es (even opengl 2.0, without special extension) do you think it can be emulated by gl4es?

ptitSeb commented 3 years ago

I don't think so. This seems quite hardcoded for gles2 hardware, I don't see any practicle workaround for this.

Sisah2 commented 1 year ago

Can gl4es use this extension when available? https://registry.khronos.org/OpenGL/extensions/EXT/EXT_depth_clamp.txt

ptitSeb commented 1 year ago

Maybe, but I'm a bit unsure how it works in detail. I suppose it's to handle the clip planes not in shaders.

AnyOldName3 commented 1 year ago

The eye plane stuff is no longer relevant to OpenMW as of a couple of days ago as we now use explicit uniforms seeing as our shadows always require shaders anyway.

As for depth clamping, usually it's used by shadow volume implementations using the Carmack Reverse technique to ensure end caps end up in the stencil buffer when they're on the wrong side of the near or far plane. It was specifically designed for this one task. The effect is basically to clamp the depth between zero and one after rasterisation, but before the depth test. The behaviour's specified as

If enabled, the −wc≤zc≤wc plane equation is ignored by view volume clipping (effectively, there is no near or far plane clipping). See glDepthRange.

Given that the depth buffer can't normally hold values outside the depth range, that's basically the same thing. For shadow volume end caps, it tends to work okayish if you do the clamping in the vertex shader, at least according to people writing code that does so on StackOverflow.

OpenMW doesn't use depth clamping for its intended purpose, though. We've got shadow mapping, which is completely different to shadow volumes. In order to increase depth precision of the shadow maps, we restrict their depth range to the bit that overlaps the view frustum instead of everywhere shadow casters can be. This means that we have shadow casters on the wrong side of the near plane, so need depth clamping to make them show up in the shadow map. It doesn't matter that we don't know their true depth as they'll cast shadows on everything in the view frustum. Technically we also end up keeping shadow casters on the wrong side of the far plane, too, but the GLSL shadow sampling functions treat the maximum depth value as there being no caster, so it makes no difference.