Add precision qualifier in fragment shaders for struct fields

This commit is contained in:
Gabriel Calero 2018-02-15 12:17:13 -03:00
parent b4fbeacc5d
commit 28c7ed761e
5 changed files with 52 additions and 25 deletions

View file

@ -32,8 +32,16 @@ vec3 getLightIrradiance(Light l) { return lightIrradiance_getIrradiance(l.irradi
// AMbient lighting needs extra info provided from a different Buffer // AMbient lighting needs extra info provided from a different Buffer
<@include graphics/SphericalHarmonics.shared.slh@> <@include graphics/SphericalHarmonics.shared.slh@>
// Light Ambient // Light Ambient
#ifndef PRECISIONQ
#ifdef GL_ES
#define PRECISIONQ highp
#else
#define PRECISIONQ
#endif
#endif
struct LightAmbient { struct LightAmbient {
vec4 _ambient; PRECISIONQ vec4 _ambient;
SphericalHarmonics _ambientSphere; SphericalHarmonics _ambientSphere;
}; };

View file

@ -12,11 +12,17 @@
#define LightIrradianceConstRef LightIrradiance #define LightIrradianceConstRef LightIrradiance
#ifndef PRECISIONQ
#ifdef GL_ES
#define PRECISIONQ highp
#else
#define PRECISIONQ
#endif
#endif
struct LightIrradiance { struct LightIrradiance {
vec4 colorIntensity; PRECISIONQ vec4 colorIntensity;
// falloffRadius, cutoffRadius, falloffSpot, spare // falloffRadius, cutoffRadius, falloffSpot, spare
vec4 attenuation; PRECISIONQ vec4 attenuation;
}; };

View file

@ -15,9 +15,17 @@
#define LightVolumeConstRef LightVolume #define LightVolumeConstRef LightVolume
#ifndef PRECISIONQ
#ifdef GL_ES
#define PRECISIONQ highp
#else
#define PRECISIONQ
#endif
#endif
struct LightVolume { struct LightVolume {
vec4 positionRadius; PRECISIONQ vec4 positionRadius;
vec4 directionSpotCos; PRECISIONQ vec4 directionSpotCos;
}; };
bool lightVolume_isPoint(LightVolume lv) { return bool(lv.directionSpotCos.w < 0.f); } bool lightVolume_isPoint(LightVolume lv) { return bool(lv.directionSpotCos.w < 0.f); }

View file

@ -14,17 +14,17 @@
// The material values (at least the material key) must be precisely bitwise accurate // The material values (at least the material key) must be precisely bitwise accurate
// to what is provided by the uniform buffer, or the material key has the wrong bits // to what is provided by the uniform buffer, or the material key has the wrong bits
#ifdef GL_ES #ifdef GL_ES
precision highp float;
#define BITFIELD highp int #define BITFIELD highp int
#define PRECISIONQ highp
#else #else
#define BITFIELD int #define BITFIELD int
#define PRECISIONQ
#endif #endif
struct Material {
struct Material { PRECISIONQ vec4 _emissiveOpacity;
vec4 _emissiveOpacity; PRECISIONQ vec4 _albedoRoughness;
vec4 _albedoRoughness; PRECISIONQ vec4 _fresnelMetallic;
vec4 _fresnelMetallic; PRECISIONQ vec4 _scatteringSpare2Key;
vec4 _scatteringSpare2Key;
}; };
uniform materialBuffer { uniform materialBuffer {
@ -70,8 +70,5 @@ const BITFIELD OCCLUSION_MAP_BIT = 0x00004000;
const BITFIELD LIGHTMAP_MAP_BIT = 0x00008000; const BITFIELD LIGHTMAP_MAP_BIT = 0x00008000;
const BITFIELD SCATTERING_MAP_BIT = 0x00010000; const BITFIELD SCATTERING_MAP_BIT = 0x00010000;
#ifdef GL_ES
precision lowp float;
#endif
<@endif@> <@endif@>

View file

@ -15,16 +15,24 @@
#define SphericalHarmonicsConstRef SphericalHarmonics #define SphericalHarmonicsConstRef SphericalHarmonics
#ifndef PRECISIONQ
#ifdef GL_ES
#define PRECISIONQ highp
#else
#define PRECISIONQ
#endif
#endif
struct SphericalHarmonics { struct SphericalHarmonics {
vec4 L00; PRECISIONQ vec4 L00;
vec4 L1m1; PRECISIONQ vec4 L1m1;
vec4 L10; PRECISIONQ vec4 L10;
vec4 L11; PRECISIONQ vec4 L11;
vec4 L2m2; PRECISIONQ vec4 L2m2;
vec4 L2m1; PRECISIONQ vec4 L2m1;
vec4 L20; PRECISIONQ vec4 L20;
vec4 L21; PRECISIONQ vec4 L21;
vec4 L22; PRECISIONQ vec4 L22;
}; };
vec4 sphericalHarmonics_evalSphericalLight(SphericalHarmonicsConstRef sh, vec3 direction) { vec4 sphericalHarmonics_evalSphericalLight(SphericalHarmonicsConstRef sh, vec3 direction) {