diff --git a/KREngine/kraken_standard_assets_osx/Shaders/ObjectShader_osx.fsh b/KREngine/kraken_standard_assets_osx/Shaders/ObjectShader_osx.fsh index 0c38606..bf70c98 100644 --- a/KREngine/kraken_standard_assets_osx/Shaders/ObjectShader_osx.fsh +++ b/KREngine/kraken_standard_assets_osx/Shaders/ObjectShader_osx.fsh @@ -25,7 +25,7 @@ // or implied, of Kearwood Gilbert. // -//#extension GL_EXT_shadow_samplers : require +// #extension GL_EXT_shadow_samplers : require #if FOG_TYPE > 0 // FOG_TYPE 1 - Linear @@ -272,14 +272,14 @@ void main() if(shadowMapCoord1.x >= -1.0 && shadowMapCoord1.x <= 1.0 && shadowMapCoord1.y >= -1.0 && shadowMapCoord1.y <= 1.0 && shadowMapCoord1.z >= 0.0 && shadowMapCoord1.z <= 1.0) { #if DEBUG_PSSM == 1 - diffuseMaterial = diffuseMaterial * vec4(0.75, 0.75, 0.5, 1.0) + vec4(0.0, 0.0, 0.5, 0.0); + diffuseMaterial = diffuseMaterial * vec4(0.75, 0.75, 0.5, 1.0) + vec4(0.0, 0.0, 0.5 * diffuseMaterial.a, 0.0); #endif highp vec2 shadowMapPos = (shadowMapCoord1 / shadowMapCoord1.w).st; shadowMapDepth = texture2D(shadowTexture1, shadowMapPos).z; vertexShadowDepth = (shadowMapCoord1 / shadowMapCoord1.w).z; } else if(shadowMapCoord2.s >= -1.0 && shadowMapCoord2.s <= 1.0 && shadowMapCoord2.t >= -1.0 && shadowMapCoord2.t <= 1.0 && shadowMapCoord2.z >= 0.0 && shadowMapCoord2.z <= 1.0) { #if DEBUG_PSSM == 1 - diffuseMaterial = diffuseMaterial * vec4(0.75, 0.50, 0.75, 1.0) + vec4(0.0, 0.5, 0.0, 0.0); + diffuseMaterial = diffuseMaterial * vec4(0.75, 0.50, 0.75, 1.0) + vec4(0.0, 0.5 * diffuseMaterial.a, 0.0, 0.0); #endif highp vec2 shadowMapPos = (shadowMapCoord2 / shadowMapCoord2.w).st; shadowMapDepth = texture2D(shadowTexture2, shadowMapPos).z; @@ -288,7 +288,7 @@ void main() #if SHADOW_QUALITY >= 3 else if(shadowMapCoord3.s >= -1.0 && shadowMapCoord3.s <= 1.0 && shadowMapCoord3.t >= -1.0 && shadowMapCoord3.t <= 1.0 && shadowMapCoord3.z >= 0.0 && shadowMapCoord3.z <= 1.0) { #if DEBUG_PSSM == 1 - diffuseMaterial = diffuseMaterial * vec4(0.50, 0.75, 0.75, 1.0) + vec4(0.5, 0.0, 0.0, 0.0); + diffuseMaterial = diffuseMaterial * vec4(0.50, 0.75, 0.75, 1.0) + vec4(0.5 * diffuseMaterial.a, 0.0, 0.0, 0.0); #endif highp vec2 shadowMapPos = (shadowMapCoord3 / shadowMapCoord3.w).st; shadowMapDepth = texture2D(shadowTexture3, shadowMapPos).z; @@ -320,11 +320,37 @@ void main() #if ENABLE_DIFFUSE == 1 // -------------------- Add diffuse light -------------------- - gl_FragColor += diffuseMaterial * vec4(material_diffuse, 1.0) * vec4(vec3(lamberFactor), 1.0); + gl_FragColor += diffuseMaterial * vec4(material_diffuse * lamberFactor, 1.0); + #endif + + // -------------------- Apply material_alpha -------------------- + + #if ALPHA_BLEND == 1 + gl_FragColor.a = diffuseMaterial.a; + gl_FragColor *= material_alpha; #endif + // -------------------- Add specular light -------------------- + // Additive, not masked against diffuse alpha + #if ENABLE_SPECULAR == 1 + #if HAS_SPEC_MAP == 1 && ENABLE_PER_PIXEL == 1 + gl_FragColor.rgb += material_specular * vec3(texture2D(specularTexture, spec_uv)) * specularFactor; + #else + gl_FragColor.rgb += material_specular * specularFactor; + #endif + #endif + + // -------------------- Multiply light map -------------------- + #if HAS_LIGHT_MAP == 1 + mediump vec3 lightMapColor = vec3(texture2D(lightmapTexture, lightmap_uv)); + //gl_FragColor = vec4(gl_FragColor.r * lightMapColor.r, gl_FragColor.g * lightMapColor.g, gl_FragColor.b * lightMapColor.b, gl_FragColor.a); + gl_FragColor.rgb *= lightMapColor; + #endif + + + // -------------------- Add reflected light -------------------- #if HAS_REFLECTION_CUBE_MAP == 1 - // -------------------- Add reflected light -------------------- + // Reflected light is additive and not modulated by the light map #if HAS_NORMAL_MAP == 1 // Calculate reflection vector as I - 2.0 * dot(N, I) * N mediump vec3 incidenceVec = -normalize(eyeVec); @@ -338,43 +364,33 @@ void main() #endif #endif - // -------------------- Add specular light -------------------- - #if ENABLE_SPECULAR == 1 - #if HAS_SPEC_MAP == 1 && ENABLE_PER_PIXEL == 1 - gl_FragColor += vec4(material_specular * vec3(texture2D(specularTexture, spec_uv)) * specularFactor, 0.0); - #else - gl_FragColor += vec4(material_specular * specularFactor, 0.0); + // -------------------- Apply Fog -------------------- + #if FOG_TYPE == 1 || FOG_TYPE == 2 || FOG_TYPE == 3 + + #if FOG_TYPE == 1 + // Linear fog + lowp float fog_alpha = clamp((fog_far - gl_FragCoord.z / gl_FragCoord.w) * fog_scale, 0.0, 1.0); + #endif + + #if FOG_TYPE == 2 + // Exponential fog + mediump float fog_z = gl_FragCoord.z / gl_FragCoord.w - fog_near; + lowp float fog_alpha = clamp(exp2(fog_density_premultiplied_exponential * fog_z), 0.0, 1.0); + #endif + + #if FOG_TYPE == 3 + // Exponential squared fog + mediump float fog_z = max(gl_FragCoord.z / gl_FragCoord.w - fog_near, 0.0); + lowp float fog_alpha = clamp(exp2(fog_density_premultiplied_squared * fog_z * fog_z), 0.0, 1.0); + #endif + + #if ALPHA_BLEND == 1 + gl_FragColor.rgb = mix(fog_color.rgb * gl_FragColor.a, gl_FragColor.rgb, fog_alpha); + #else + gl_FragColor.rgb = mix(fog_color.rgb, gl_FragColor.rgb, fog_alpha); #endif - - #endif - - #if ALPHA_BLEND == 1 - gl_FragColor.a = gl_FragColor.a * material_alpha; - #endif - - // -------------------- Multiply light map -------------------- - - #if HAS_LIGHT_MAP == 1 - mediump vec3 lightMapColor = vec3(texture2D(lightmapTexture, lightmap_uv)); - gl_FragColor = vec4(gl_FragColor.r * lightMapColor.r, gl_FragColor.g * lightMapColor.g, gl_FragColor.b * lightMapColor.b, gl_FragColor.a); #endif - // -------------------- Apply Fog -------------------- - #if FOG_TYPE == 1 - // Linear fog - gl_FragColor.rgb = mix(fog_color.rgb, gl_FragColor.rgb, clamp((fog_far - gl_FragCoord.z / gl_FragCoord.w) * fog_scale, 0.0, 1.0)); - #endif - - #if FOG_TYPE == 2 - // Exponential fog - mediump float fog_z = gl_FragCoord.z / gl_FragCoord.w - fog_near; - gl_FragColor.rgb = mix(fog_color.rgb, gl_FragColor.rgb, clamp(exp2(fog_density_premultiplied_exponential * fog_z), 0.0, 1.0)); - #endif - - #if FOG_TYPE == 3 - // Exponential squared fog - mediump float fog_z = max(gl_FragCoord.z / gl_FragCoord.w - fog_near, 0.0); - gl_FragColor.rgb = mix(fog_color.rgb, gl_FragColor.rgb, clamp(exp2(fog_density_premultiplied_squared * fog_z * fog_z), 0.0, 1.0)); - #endif + #endif }