Improve compatibility with GLES back-end

This commit is contained in:
Edwin Jakobs
2024-03-10 18:39:21 +01:00
parent b9b1b95ca0
commit e3f5e07b86
62 changed files with 182 additions and 195 deletions

View File

@@ -41,7 +41,7 @@ private fun PointLight.fs(index: Int, hasNormalAttribute: Boolean): String = """
| vec3 L = normalize(Lr);
|
| float side = ${if (hasNormalAttribute) "dot(L, N)" else "3.1415"};
| f_diffuse += attenuation * max(0, side / 3.1415) * p_lightColor$index.rgb * m_color.rgb;
| f_diffuse += attenuation * max(0.0, side / 3.1415) * p_lightColor$index.rgb * m_color.rgb;
| f_specular += attenuation * ggx(N, V, L, m_roughness, m_f0) * p_lightColor$index.rgb * m_color.rgb;
}
""".trimMargin()
@@ -71,7 +71,7 @@ private fun DirectionalLight.fs(index: Int, hasNormalAttribute: Boolean) = """
private fun HemisphereLight.fs(index: Int, hasNormalAttribute: Boolean): String = """
|{
| float f = ${if (hasNormalAttribute) "dot(N, p_lightDirection$index) * 0.5 + 0.5" else "1"};
| float f = ${if (hasNormalAttribute) "dot(N, p_lightDirection$index) * 0.5 + 0.5" else "1.0"};
| vec3 irr = ${irradianceMap?.let { "texture(p_lightIrradianceMap$index, N).rgb" } ?: "vec3(1.0)"};
| f_diffuse += mix(p_lightDownColor$index.rgb, p_lightUpColor$index.rgb, f) * irr * ((1.0 - m_metalness) * m_color.rgb) * m_ambientOcclusion;
|}
@@ -460,7 +460,7 @@ class PBRMaterial : Material {
vec3 Vr = ep - v_worldPosition;
vec3 V = normalize(Vr);
float NoV = ${if (primitiveContext.hasNormalAttribute) "abs(dot(N, V)) + 1e-5" else "1"};
float NoV = ${if (primitiveContext.hasNormalAttribute) "abs(dot(N, V)) + 1e-5" else "1.0"};
${if (environmentMap && materialContext.meshCubemaps.isNotEmpty() && primitiveContext.hasNormalAttribute) """
{

View File

@@ -84,7 +84,7 @@ class SceneRenderer {
}
val target = shadowLightTargets.getOrPut(shadowLight) {
val mapSize = (shadowLight.shadows as Shadows.MappedShadows).mapSize
pass.createPassTarget(mapSize, mapSize, DepthFormat.DEPTH16)
pass.createPassTarget(mapSize, mapSize, DepthFormat.DEPTH_STENCIL)
}
target.clearDepth(depth = 1.0)

View File

@@ -93,7 +93,7 @@ val shaderVSM = """
|// -- shaderVSM
|float linstep(float min, float max, float v)
|{
| return clamp((v - min) / (max - min), 0, 1);
| return clamp((v - min) / (max - min), 0.0, 1.0);
|}
|// https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch08.html
|float chebyshevUpperBound(vec2 moments, float t, float minVariance) {
@@ -224,7 +224,7 @@ float ggx(vec3 N, vec3 V, vec3 L, float roughness, float F0)
D = alphaSqr/(pi * denom * denom);
// F
float dotLH5 = pow(1.0f-dotLH,5);
float dotLH5 = pow(1.0f-dotLH,5.0);
F = F0 + (1.0-F0)*(dotLH5);
// V

View File

@@ -27,7 +27,7 @@ fun Shadows.VSM.fs(index: Int) : String = """
|{
| vec4 smc = (p_lightTransform$index * vec4(v_worldPosition,1.0));
| vec3 lightProj = (smc.xyz/smc.w) * 0.5 + 0.5;
| if (lightProj.x > 0.0 && lightProj.x < 1.0 && lightProj.y > 0 && lightProj.y < 1) {
| if (lightProj.x > 0.0 && lightProj.x < 1.0 && lightProj.y > 0.0 && lightProj.y < 1.0) {
| vec2 moments = texture(p_lightShadowMap$index, lightProj.xy).xy;
| attenuation *= (chebyshevUpperBound(moments, length(Lr), 50.0));
| }
@@ -38,9 +38,9 @@ fun Shadows.Simple.fs(index: Int): String = """
|{
| vec4 smc = (p_lightTransform$index * vec4(v_worldPosition,1.0));
| vec3 lightProj = (smc.xyz/smc.w) * 0.5 + 0.5;
| if (lightProj.x > 0.0 && lightProj.x < 1.0 && lightProj.y > 0 && lightProj.y < 1) {
| if (lightProj.x > 0.0 && lightProj.x < 1.0 && lightProj.y > 0.0 && lightProj.y < 1.0) {
| vec3 smz = texture(p_lightShadowMap$index, lightProj.xy).rgb;
| vec2 step = 1.0 / textureSize(p_lightShadowMap$index,0);
| vec2 step = 1.0 / vec2(textureSize(p_lightShadowMap$index,0));
| float result = 0.0;
| float compToZ = (lightProj.z- 0.0020 * tan(acos(NoL))) - 0.0003;
| float currentDepth = lightProj.z;
@@ -69,19 +69,19 @@ fun Shadows.PCF.fs(index: Int): String = """
| fTaps_Poisson[11] = vec2(-.792,-.598);
| vec4 smc = (p_lightTransform$index * vec4(v_worldPosition,1.0));
| vec3 lightProj = (smc.xyz/smc.w) * 0.5 + 0.5;
| if (lightProj.x > 0.0 && lightProj.x < 1.0 && lightProj.y > 0 && lightProj.y < 1) {
| if (lightProj.x > 0.0 && lightProj.x < 1.0 && lightProj.y > 0.0 && lightProj.y < 1.0) {
| vec3 smz = texture(p_lightShadowMap$index, lightProj.xy).rgb;
| vec2 stepSize = 1.0 / textureSize(p_lightShadowMap$index,0);
| vec2 stepSize = 1.0 / vec2(textureSize(p_lightShadowMap$index,0));
| float result = 0.0;
| float compToZ = (lightProj.z- 0.0020 * tan(acos(NoL))) - 0.0003;
| float noise = hash22(lightProj.xy*10.0).x;
| float r = noise * 3.1415926535 * 2.0;
| mat2 rot = mat2( vec2(cos(r), -sin(r)), vec2(sin(r),cos(r)));
| for (int i = 0; i < 12; ++i) {
| float depth = texture(p_lightShadowMap$index, lightProj.xy + rot*fTaps_Poisson[i]*i*lrl*stepSize ).r;
| float depth = texture(p_lightShadowMap$index, lightProj.xy + rot*fTaps_Poisson[i]*float(i)*lrl*stepSize ).r;
| result += step(compToZ, depth);
| }
| result /= 12;
| result /= 12.0;
| float currentDepth = lightProj.z;
| float closestDepth = smz.x;
| float shadow = result;// (currentDepth - 0.0020 * tan(acos(NoL))) - 0.0003 >= closestDepth ? 0.0 : 1.0;

View File

@@ -97,7 +97,7 @@ fun GltfFile.buildSceneNodes(): GltfSceneData {
val cb = loadImage(MPPBuffer(localBuffer))
cb.generateMipmaps()
cb.filter(MinifyingFilter.LINEAR_MIPMAP_LINEAR, MagnifyingFilter.LINEAR)
cb.anisotropy = 100.0
cb.anisotropy = 10.0
localBuffer.limit(localBuffer.capacity())
cb
} ?: error("no uri and no bufferview")

View File

@@ -295,7 +295,7 @@ void main() {
float angle = abs(dot(reflected, viewNormal));
float frontalFade = clamp(-reflected.z,0, 1);
float frontalFade = clamp(-reflected.z,0.0, 1.0);
if ( true ) {
bool hit = traceScreenSpaceRay1(
viewPos,

View File

@@ -1,12 +1,10 @@
#version 330
uniform usampler2D tex0;
uniform highp usampler2D tex0;
in vec2 v_texCoord0;
out vec4 o_output;
void main() {
ivec2 ts = textureSize(tex0, 0);
ivec2 pixel = ivec2(v_texCoord0 * ts);
ivec2 pixel = ivec2(v_texCoord0 * vec2(ts));
ivec2 c = pixel;
ivec2 n = c + ivec2(0, -1);