diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 9c711dfe6a..5c589af529 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -5,6 +5,7 @@ A new header is inserted each time a *tag* is created. ## Next release +- gltfio now uses high precision for texture coordinates. - Fixed regression in JavaScript IcoSphere that caused tutorial to fail. - gltf_viewer now supports viewing with glTF cameras. - gltfio now supports importing glTF cameras. diff --git a/libs/gltfio/materials/ubershader.mat.in b/libs/gltfio/materials/ubershader.mat.in index f0bd1821ef..aeb759b198 100644 --- a/libs/gltfio/materials/ubershader.mat.in +++ b/libs/gltfio/materials/ubershader.mat.in @@ -61,20 +61,20 @@ material { fragment { void material(inout MaterialInputs material) { - float2 uvs[2]; + highp float2 uvs[2]; uvs[0] = getUV0(); uvs[1] = getUV1(); #if !defined(SHADING_MODEL_UNLIT) if (materialParams.normalIndex > -1) { - float2 uv = uvs[materialParams.normalIndex]; + highp float2 uv = uvs[materialParams.normalIndex]; uv = (vec3(uv, 1.0) * materialParams.normalUvMatrix).xy; material.normal = texture(materialParams_normalMap, uv).xyz * 2.0 - 1.0; material.normal.xy *= materialParams.normalScale; } #if defined(SHADING_MODEL_LIT) if (materialParams.clearCoatNormalIndex > -1) { - float2 uv = uvs[materialParams.clearCoatNormalIndex]; + highp float2 uv = uvs[materialParams.clearCoatNormalIndex]; uv = (vec3(uv, 1.0) * materialParams.clearCoatNormalUvMatrix).xy; material.clearCoatNormal = texture(materialParams_clearCoatNormalMap, uv).xyz * 2.0 - 1.0; material.clearCoatNormal.xy *= materialParams.clearCoatNormalScale; @@ -86,7 +86,7 @@ fragment { material.baseColor = materialParams.baseColorFactor; if (materialParams.baseColorIndex > -1) { - float2 uv = uvs[materialParams.baseColorIndex]; + highp float2 uv = uvs[materialParams.baseColorIndex]; uv = (vec3(uv, 1.0) * materialParams.baseColorUvMatrix).xy; material.baseColor *= texture(materialParams_baseColorMap, uv); } @@ -109,12 +109,12 @@ fragment { material.clearCoatRoughness = materialParams.clearCoatRoughnessFactor; if (materialParams.clearCoatIndex > -1) { - float2 uv = uvs[materialParams.clearCoatIndex]; + highp float2 uv = uvs[materialParams.clearCoatIndex]; uv = (vec3(uv, 1.0) * materialParams.clearCoatUvMatrix).xy; material.clearCoat *= texture(materialParams_clearCoatMap, uv).r; } if (materialParams.clearCoatRoughnessIndex > -1) { - float2 uv = uvs[materialParams.clearCoatRoughnessIndex]; + highp float2 uv = uvs[materialParams.clearCoatRoughnessIndex]; uv = (vec3(uv, 1.0) * materialParams.clearCoatRoughnessUvMatrix).xy; material.clearCoatRoughness *= texture(materialParams_clearCoatRoughnessMap, uv).g; } @@ -128,7 +128,7 @@ fragment { #endif if (materialParams.metallicRoughnessIndex > -1) { - float2 uv = uvs[materialParams.metallicRoughnessIndex]; + highp float2 uv = uvs[materialParams.metallicRoughnessIndex]; uv = (vec3(uv, 1.0) * materialParams.metallicRoughnessUvMatrix).xy; #if defined(SHADING_MODEL_SPECULAR_GLOSSINESS) @@ -143,13 +143,13 @@ fragment { } if (materialParams.aoIndex > -1) { - float2 uv = uvs[materialParams.aoIndex]; + highp float2 uv = uvs[materialParams.aoIndex]; uv = (vec3(uv, 1.0) * materialParams.occlusionUvMatrix).xy; material.ambientOcclusion = texture(materialParams_occlusionMap, uv).r * materialParams.aoStrength; } if (materialParams.emissiveIndex > -1) { - float2 uv = uvs[materialParams.emissiveIndex]; + highp float2 uv = uvs[materialParams.emissiveIndex]; uv = (vec3(uv, 1.0) * materialParams.emissiveUvMatrix).xy; material.emissive.rgb *= texture(materialParams_emissiveMap, uv).rgb; } diff --git a/libs/gltfio/src/MaterialGenerator.cpp b/libs/gltfio/src/MaterialGenerator.cpp index ca7ba9de03..854c53855c 100644 --- a/libs/gltfio/src/MaterialGenerator.cpp +++ b/libs/gltfio/src/MaterialGenerator.cpp @@ -80,7 +80,7 @@ std::string shaderFromKey(const MaterialKey& config) { std::string shader = "void material(inout MaterialInputs material) {\n"; if (config.hasNormalTexture && !config.unlit) { - shader += "float2 normalUV = ${normal};\n"; + shader += "highp float2 normalUV = ${normal};\n"; if (config.hasTextureTransforms) { shader += "normalUV = (vec3(normalUV, 1.0) * materialParams.normalUvMatrix).xy;\n"; } @@ -91,7 +91,7 @@ std::string shaderFromKey(const MaterialKey& config) { } if (config.hasClearCoat && config.hasClearCoatNormalTexture && !config.unlit) { - shader += "float2 clearCoatNormalUV = ${clearCoatNormal};\n"; + shader += "highp float2 clearCoatNormalUV = ${clearCoatNormal};\n"; if (config.hasTextureTransforms) { shader += "clearCoatNormalUV = (vec3(clearCoatNormalUV, 1.0) * " "materialParams.clearCoatNormalUvMatrix).xy;\n"; @@ -116,7 +116,7 @@ std::string shaderFromKey(const MaterialKey& config) { )SHADER"; if (config.hasBaseColorTexture) { - shader += "float2 baseColorUV = ${color};\n"; + shader += "highp float2 baseColorUV = ${color};\n"; if (config.hasTextureTransforms) { shader += "baseColorUV = (vec3(baseColorUV, 1.0) * " "materialParams.baseColorUvMatrix).xy;\n"; @@ -161,7 +161,7 @@ std::string shaderFromKey(const MaterialKey& config) { )SHADER"; } if (config.hasMetallicRoughnessTexture) { - shader += "float2 metallicRoughnessUV = ${metallic};\n"; + shader += "highp float2 metallicRoughnessUV = ${metallic};\n"; if (config.hasTextureTransforms) { shader += "metallicRoughnessUV = (vec3(metallicRoughnessUV, 1.0) * " "materialParams.metallicRoughnessUvMatrix).xy;\n"; @@ -181,7 +181,7 @@ std::string shaderFromKey(const MaterialKey& config) { } } if (config.hasOcclusionTexture) { - shader += "float2 aoUV = ${ao};\n"; + shader += "highp float2 aoUV = ${ao};\n"; if (config.hasTextureTransforms) { shader += "aoUV = (vec3(aoUV, 1.0) * materialParams.occlusionUvMatrix).xy;\n"; } @@ -191,7 +191,7 @@ std::string shaderFromKey(const MaterialKey& config) { )SHADER"; } if (config.hasEmissiveTexture) { - shader += "float2 emissiveUV = ${emissive};\n"; + shader += "highp float2 emissiveUV = ${emissive};\n"; if (config.hasTextureTransforms) { shader += "emissiveUV = (vec3(emissiveUV, 1.0) * " "materialParams.emissiveUvMatrix).xy;\n"; @@ -207,7 +207,7 @@ std::string shaderFromKey(const MaterialKey& config) { )SHADER"; if (config.hasClearCoatTexture) { - shader += "float2 clearCoatUV = ${clearCoat};\n"; + shader += "highp float2 clearCoatUV = ${clearCoat};\n"; if (config.hasTextureTransforms) { shader += "clearCoatUV = (vec3(clearCoatUV, 1.0) * " "materialParams.clearCoatUvMatrix).xy;\n"; @@ -218,7 +218,7 @@ std::string shaderFromKey(const MaterialKey& config) { } if (config.hasClearCoatRoughnessTexture) { - shader += "float2 clearCoatRoughnessUV = ${clearCoatRoughness};\n"; + shader += "highp float2 clearCoatRoughnessUV = ${clearCoatRoughness};\n"; if (config.hasTextureTransforms) { shader += "clearCoatRoughnessUV = (vec3(clearCoatRoughnessUV, 1.0) * " "materialParams.clearCoatRoughnessUvMatrix).xy;\n";