Merge pull request #8779 from gcalero/shaders_gl_es

Adapt shader for GL ES support
This commit is contained in:
Brad Davis 2016-10-12 08:32:50 -07:00 committed by GitHub
commit 4e0fffb8b7
15 changed files with 27 additions and 27 deletions

View file

@ -23,7 +23,7 @@ vec2 float32x3_to_oct(in vec3 v) {
vec3 oct_to_float32x3(in vec2 e) {
vec3 v = vec3(e.xy, 1.0 - abs(e.x) - abs(e.y));
if (v.z < 0) {
if (v.z < 0.0) {
v.xy = (1.0 - abs(v.yx)) * signNotZero(v.xy);
}
return normalize(v);

View file

@ -108,7 +108,7 @@ float evalLightAttenuation(Light l, float d) {
// "Fade" the edges of light sources to make things look a bit more attractive.
// Note: this tends to look a bit odd at lower exponents.
attenuation *= min(1, max(0, -(d - cutoff)));
attenuation *= min(1.0, max(0.0, -(d - cutoff)));
return attenuation;
}
@ -118,7 +118,7 @@ SphericalHarmonics getLightAmbientSphere(Light l) {
}
bool getLightHasAmbientMap(Light l) {
return l._control.x > 0;
return l._control.x > 0.0;
}
float getLightAmbientMapNumMips(Light l) {

View file

@ -51,7 +51,7 @@ DeferredFragment unpackDeferredFragmentNoPosition(vec2 texcoord) {
vec4 specularVal;
DeferredFragment frag;
frag.depthVal = -1;
frag.depthVal = -1.0;
normalVal = texture(normalMap, texcoord);
diffuseVal = texture(albedoMap, texcoord);
specularVal = texture(specularMap, texcoord);
@ -138,8 +138,8 @@ void unpackMidLowNormalCurvature(vec2 texcoord, out vec4 midNormalCurvature, out
lowNormalCurvature = fetchDiffusedCurvature(texcoord);
midNormalCurvature.xyz = normalize((midNormalCurvature.xyz - 0.5f) * 2.0f);
lowNormalCurvature.xyz = normalize((lowNormalCurvature.xyz - 0.5f) * 2.0f);
midNormalCurvature.w = (midNormalCurvature.w * 2 - 1);
lowNormalCurvature.w = (lowNormalCurvature.w * 2 - 1);
midNormalCurvature.w = (midNormalCurvature.w * 2.0 - 1.0);
lowNormalCurvature.w = (lowNormalCurvature.w * 2.0 - 1.0);
}
<@endfunc@>

View file

@ -27,8 +27,8 @@ float evalOpaqueFinalAlpha(float alpha, float mapAlpha) {
}
const float DEFAULT_ROUGHNESS = 0.9;
const float DEFAULT_SHININESS = 10;
const float DEFAULT_METALLIC = 0;
const float DEFAULT_SHININESS = 10.0;
const float DEFAULT_METALLIC = 0.0;
const vec3 DEFAULT_SPECULAR = vec3(0.1);
const vec3 DEFAULT_EMISSIVE = vec3(0.0);
const float DEFAULT_OCCLUSION = 1.0;

View file

@ -23,7 +23,7 @@
// prepareGlobalLight
// Transform directions to worldspace
vec3 fragNormal = vec3((normal));
vec3 fragEyeVector = vec3(invViewMat * vec4(-position, 0.0));
vec3 fragEyeVector = vec3(invViewMat * vec4(-1.0*position, 0.0));
vec3 fragEyeDir = normalize(fragEyeVector);
// Get light
@ -143,13 +143,13 @@ vec3 evalLightmappedColor(mat4 invViewMat, float shadowAttenuation, float obscur
float facingLight = step(PERPENDICULAR_THRESHOLD, diffuseDot);
// Reevaluate the shadow attenuation for light facing fragments
float lightAttenuation = (1 - facingLight) + facingLight * shadowAttenuation;
float lightAttenuation = (1.0 - facingLight) + facingLight * shadowAttenuation;
// Diffuse light is the lightmap dimmed by shadow
vec3 diffuseLight = lightAttenuation * lightmap;
// Ambient light is the lightmap when in shadow
vec3 ambientLight = (1 - lightAttenuation) * lightmap * getLightAmbientIntensity(light);
vec3 ambientLight = (1.0 - lightAttenuation) * lightmap * getLightAmbientIntensity(light);
return isLightmapEnabled() * obscurance * albedo * (diffuseLight + ambientLight);
}

View file

@ -23,7 +23,7 @@ vec4 evalSkyboxLight(vec3 direction, float lod) {
<@func declareEvalAmbientSpecularIrradiance(supportAmbientSphere, supportAmbientMap, supportIfAmbientMapElseAmbientSphere)@>
vec3 fresnelSchlickAmbient(vec3 fresnelColor, vec3 lightDir, vec3 halfDir, float gloss) {
return fresnelColor + (max(vec3(gloss), fresnelColor) - fresnelColor) * pow(1.0 - clamp(dot(lightDir, halfDir), 0.0, 1.0), 5);
return fresnelColor + (max(vec3(gloss), fresnelColor) - fresnelColor) * pow(1.0 - clamp(dot(lightDir, halfDir), 0.0, 1.0), 5.0);
}
<@if supportAmbientMap@>
@ -32,7 +32,7 @@ vec3 fresnelSchlickAmbient(vec3 fresnelColor, vec3 lightDir, vec3 halfDir, float
vec3 evalAmbientSpecularIrradiance(Light light, vec3 fragEyeDir, vec3 fragNormal, float roughness, vec3 fresnel) {
vec3 direction = -reflect(fragEyeDir, fragNormal);
vec3 ambientFresnel = fresnelSchlickAmbient(fresnel, fragEyeDir, fragNormal, 1 - roughness);
vec3 ambientFresnel = fresnelSchlickAmbient(fresnel, fragEyeDir, fragNormal, 1.0 - roughness);
vec3 specularLight;
<@if supportIfAmbientMapElseAmbientSphere@>
if (getLightHasAmbientMap(light))
@ -76,7 +76,7 @@ void evalLightingAmbient(out vec3 diffuse, out vec3 specular, Light light, vec3
// Diffuse from ambient
diffuse = (1 - metallic) * evalSphericalLight(getLightAmbientSphere(light), normal).xyz;
diffuse = (1.0 - metallic) * evalSphericalLight(getLightAmbientSphere(light), normal).xyz;
// Specular highlight from ambient
specular = evalAmbientSpecularIrradiance(light, eyeDir, normal, roughness, fresnel) * obscurance * getLightAmbientIntensity(light);

View file

@ -40,7 +40,7 @@ void evalLightingPoint(out vec3 diffuse, out vec3 specular, Light light,
if (isShowLightContour() > 0.0) {
// Show edge
float edge = abs(2.0 * ((getLightRadius(light) - fragLightDistance) / (0.1)) - 1.0);
if (edge < 1) {
if (edge < 1.0) {
float edgeCoord = exp2(-8.0*edge*edge);
diffuse = vec3(edgeCoord * edgeCoord * getLightShowContour(light) * getLightColor(light));
}

View file

@ -44,7 +44,7 @@ void evalLightingSpot(out vec3 diffuse, out vec3 specular, Light light,
float edgeDistS = dot(fragLightDistance * vec2(cosSpotAngle, sqrt(1.0 - cosSpotAngle * cosSpotAngle)), -getLightSpotOutsideNormal2(light));
float edgeDist = min(edgeDistR, edgeDistS);
float edge = abs(2.0 * (edgeDist / (0.1)) - 1.0);
if (edge < 1) {
if (edge < 1.0) {
float edgeCoord = exp2(-8.0*edge*edge);
diffuse = vec3(edgeCoord * edgeCoord * getLightColor(light));
}

View file

@ -118,8 +118,8 @@ vec3 fresnelSchlickColor(vec3 fresnelColor, vec3 lightDir, vec3 halfDir) {
float specularDistribution(float roughness, vec3 normal, vec3 halfDir) {
float ndoth = clamp(dot(halfDir, normal), 0.0, 1.0);
float gloss2 = pow(0.001 + roughness, 4);
float denom = (ndoth * ndoth*(gloss2 - 1) + 1);
float gloss2 = pow(0.001 + roughness, 4.0);
float denom = (ndoth * ndoth*(gloss2 - 1.0) + 1.0);
float power = gloss2 / (3.14159 * denom * denom);
return power;
}
@ -142,7 +142,7 @@ vec4 evalPBRShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, float m
float power = specularDistribution(roughness, fragNormal, halfDir);
vec3 specular = power * fresnelColor * diffuse;
return vec4(specular, (1.0 - metallic) * diffuse * (1 - fresnelColor.x));
return vec4(specular, (1.0 - metallic) * diffuse * (1.0 - fresnelColor.x));
}
<@endfunc@>

View file

@ -137,7 +137,7 @@ vec3 integrate(float cosTheta, float skinRadius) {
uniform sampler2D scatteringLUT;
vec3 fetchBRDF(float LdotN, float curvature) {
return texture(scatteringLUT, vec2( clamp(LdotN * 0.5 + 0.5, 0.0, 1.0), clamp(2 * curvature, 0.0, 1.0))).xyz;
return texture(scatteringLUT, vec2( clamp(LdotN * 0.5 + 0.5, 0.0, 1.0), clamp(2.0 * curvature, 0.0, 1.0))).xyz;
}
vec3 fetchBRDFSpectrum(vec3 LdotNSpectrum, float curvature) {
@ -183,7 +183,7 @@ float tuneCurvatureUnsigned(float curvature) {
}
float unpackCurvature(float packedCurvature) {
return (packedCurvature * 2 - 1);
return (packedCurvature * 2.0 - 1.0);
}
vec3 evalScatteringBentNdotL(vec3 normal, vec3 midNormal, vec3 lowNormal, vec3 lightDir) {
@ -210,7 +210,7 @@ vec3 evalSkinBRDF(vec3 lightDir, vec3 normal, vec3 midNormal, vec3 lowNormal, fl
return lowNormal * 0.5 + vec3(0.5);
}
if (showCurvature()) {
return (curvature > 0 ? vec3(curvature, 0.0, 0.0) : vec3(0.0, 0.0, -curvature));
return (curvature > 0.0 ? vec3(curvature, 0.0, 0.0) : vec3(0.0, 0.0, -curvature));
}
vec3 bentNdotL = evalScatteringBentNdotL(normal, midNormal, lowNormal, lightDir);

View file

@ -26,7 +26,7 @@ void main(void) {
);
vec4 pos = UNIT_QUAD[gl_VertexID];
_texCoord0 = (pos.xy + 1) * 0.5;
_texCoord0 = (pos.xy + 1.0) * 0.5;
_texCoord0 *= texcoordFrameTransform.zw;
_texCoord0 += texcoordFrameTransform.xy;

View file

@ -47,7 +47,7 @@ void main(void) {
);
vec4 pos = UNIT_QUAD[gl_VertexID];
_texCoord0 = vec4((pos.xy + 1) * 0.5, 0.0, 1.0);
_texCoord0 = vec4((pos.xy + 1.0) * 0.5, 0.0, 1.0);
if (cam_isStereo()) {
_texCoord0.x = 0.5 * (_texCoord0.x + cam_getStereoSide());

View file

@ -60,7 +60,7 @@ void main(void) {
);
vec4 pos = UNIT_QUAD[gl_VertexID];
_texCoord0 = vec4((pos.xy + 1) * 0.5, 0.0, 1.0);
_texCoord0 = vec4((pos.xy + 1.0) * 0.5, 0.0, 1.0);
if (cam_isStereo()) {
_texCoord0.x = 0.5 * (_texCoord0.x + cam_getStereoSide());
}

View file

@ -2,7 +2,7 @@
<$VERSION_HEADER$>
// Generated on <$_SCRIBE_DATE$>
//
// directional_light.frag
// directional_ambient_light.frag
// fragment shader
//
// Created by Andrzej Kapolka on 9/3/14.

View file

@ -2,7 +2,7 @@
<$VERSION_HEADER$>
// Generated on <$_SCRIBE_DATE$>
//
// directional_light.frag
// directional_skybox_light.frag
// fragment shader
//
// Created by Sam Gateau on 5/8/2015.