mirror of
https://github.com/overte-org/overte.git
synced 2025-08-12 13:54:16 +02:00
FIx shaders for mac
This commit is contained in:
parent
b8e44a3e7a
commit
e3d474db3d
3 changed files with 38 additions and 27 deletions
|
@ -14,6 +14,17 @@
|
|||
// the shadow texture
|
||||
uniform sampler2DShadow shadowMap;
|
||||
|
||||
// Fetching it
|
||||
float fetchShadow(vec3 texcoord) {
|
||||
<@if GLPROFILE == PC_GL @>
|
||||
return texture(shadowMap, texcoord);
|
||||
<@elif GLPROFILE == MAC_GL@>
|
||||
return shadow2D(shadowMap, texcoord).r;
|
||||
<@else@>
|
||||
return shadow2D(shadowMap, texcoord).r;
|
||||
<@endif@>
|
||||
}
|
||||
|
||||
// the distances to the cascade sections
|
||||
uniform vec3 shadowDistances;
|
||||
|
||||
|
@ -32,6 +43,12 @@ vec2 samples[8] = vec2[8](
|
|||
);
|
||||
|
||||
vec4 evalShadowTexcoord(vec4 position) {
|
||||
// compute the corresponding texture coordinates
|
||||
vec3 shadowTexcoord = vec3(dot(gl_EyePlaneS[0], position), dot(gl_EyePlaneT[0], position), dot(gl_EyePlaneR[0], position));
|
||||
return vec4(shadowTexcoord, 0.0);
|
||||
}
|
||||
|
||||
vec4 evalCascadedShadowTexcoord(vec4 position) {
|
||||
// compute the index of the cascade to use and the corresponding texture coordinates
|
||||
int shadowIndex = int(dot(step(vec3(position.z), shadowDistances), vec3(1.0, 1.0, 1.0)));
|
||||
vec3 shadowTexcoord = vec3(dot(gl_EyePlaneS[shadowIndex], position), dot(gl_EyePlaneT[shadowIndex], position),
|
||||
|
@ -43,19 +60,19 @@ vec4 evalShadowTexcoord(vec4 position) {
|
|||
float evalShadowAttenuationPCF(vec4 shadowTexcoord) {
|
||||
float radiusScale = (shadowTexcoord.w + 1.0);
|
||||
float shadowAttenuation = (0.25 * (
|
||||
texture(shadowMap, shadowTexcoord.xyz + radiusScale * shadowScale * vec3(samples[0], 0.0)) +
|
||||
texture(shadowMap, shadowTexcoord.xyz + radiusScale * shadowScale * vec3(samples[1], 0.0)) +
|
||||
texture(shadowMap, shadowTexcoord.xyz + radiusScale * shadowScale * vec3(samples[2], 0.0)) +
|
||||
texture(shadowMap, shadowTexcoord.xyz + radiusScale * shadowScale * vec3(samples[3], 0.0))
|
||||
fetchShadow(shadowTexcoord.xyz + radiusScale * shadowScale * vec3(samples[0], 0.0)) +
|
||||
fetchShadow(shadowTexcoord.xyz + radiusScale * shadowScale * vec3(samples[1], 0.0)) +
|
||||
fetchShadow(shadowTexcoord.xyz + radiusScale * shadowScale * vec3(samples[2], 0.0)) +
|
||||
fetchShadow(shadowTexcoord.xyz + radiusScale * shadowScale * vec3(samples[3], 0.0))
|
||||
));
|
||||
|
||||
if ((shadowAttenuation > 0) && (shadowAttenuation < 1.0)) {
|
||||
radiusScale *= 0.5;
|
||||
shadowAttenuation = 0.5 * shadowAttenuation + (0.125 * (
|
||||
texture(shadowMap, shadowTexcoord.xyz + radiusScale * shadowScale * vec3(samples[4], 0.0)) +
|
||||
texture(shadowMap, shadowTexcoord.xyz + radiusScale * shadowScale * vec3(samples[5], 0.0)) +
|
||||
texture(shadowMap, shadowTexcoord.xyz + radiusScale * shadowScale * vec3(samples[6], 0.0)) +
|
||||
texture(shadowMap, shadowTexcoord.xyz + radiusScale * shadowScale * vec3(samples[7], 0.0))
|
||||
fetchShadow(shadowTexcoord.xyz + radiusScale * shadowScale * vec3(samples[4], 0.0)) +
|
||||
fetchShadow(shadowTexcoord.xyz + radiusScale * shadowScale * vec3(samples[5], 0.0)) +
|
||||
fetchShadow(shadowTexcoord.xyz + radiusScale * shadowScale * vec3(samples[6], 0.0)) +
|
||||
fetchShadow(shadowTexcoord.xyz + radiusScale * shadowScale * vec3(samples[7], 0.0))
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -65,10 +82,10 @@ float evalShadowAttenuationPCF(vec4 shadowTexcoord) {
|
|||
float evalShadowAttenuationBasic(vec4 shadowTexcoord) {
|
||||
float radiusScale = 0.5;
|
||||
float shadowAttenuation = (0.25 * (
|
||||
texture(shadowMap, shadowTexcoord.xyz + radiusScale * shadowScale * vec3(samples[0], 0.0)) +
|
||||
texture(shadowMap, shadowTexcoord.xyz + radiusScale * shadowScale * vec3(samples[1], 0.0)) +
|
||||
texture(shadowMap, shadowTexcoord.xyz + radiusScale * shadowScale * vec3(samples[2], 0.0)) +
|
||||
texture(shadowMap, shadowTexcoord.xyz + radiusScale * shadowScale * vec3(samples[3], 0.0))
|
||||
fetchShadow(shadowTexcoord.xyz + radiusScale * shadowScale * vec3(samples[0], 0.0)) +
|
||||
fetchShadow(shadowTexcoord.xyz + radiusScale * shadowScale * vec3(samples[1], 0.0)) +
|
||||
fetchShadow(shadowTexcoord.xyz + radiusScale * shadowScale * vec3(samples[2], 0.0)) +
|
||||
fetchShadow(shadowTexcoord.xyz + radiusScale * shadowScale * vec3(samples[3], 0.0))
|
||||
));
|
||||
return shadowAttenuation;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ uniform sampler2D specularMap;
|
|||
// the depth texture
|
||||
uniform sampler2D depthMap;
|
||||
|
||||
// Everything about shadow
|
||||
<@include Shadow.slh@>
|
||||
|
||||
// the distance to the near clip plane
|
||||
|
@ -49,7 +50,7 @@ void main(void) {
|
|||
vec4 position = vec4((depthTexCoordOffset + gl_TexCoord[0].st * depthTexCoordScale) * z, z, 1.0);
|
||||
|
||||
// Eval shadow Texcoord and then Attenuation
|
||||
vec4 shadowTexcoord = evalShadowTexcoord(position);
|
||||
vec4 shadowTexcoord = evalCascadedShadowTexcoord(position);
|
||||
float shadowAttenuation = evalShadowAttenuation(shadowTexcoord);
|
||||
|
||||
// get the normal from the map
|
||||
|
@ -94,7 +95,9 @@ void main(void) {
|
|||
gl_FragColor = vec4(baseColor.rgb + pow(specular, specularColor.a * 128.0) * specularColor.rgb, normalVal.a);
|
||||
}
|
||||
|
||||
/* //DEBUG:
|
||||
if (gl_FragCoord.x > 1024) {
|
||||
gl_FragColor = vec4(debugShadowMap(shadowAttenuation, shadowTexcoord) * diffuse, normalVal.a);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -24,11 +24,8 @@ uniform sampler2D specularMap;
|
|||
// the depth texture
|
||||
uniform sampler2D depthMap;
|
||||
|
||||
// the shadow texture
|
||||
uniform sampler2DShadow shadowMap;
|
||||
|
||||
// the inverse of the size of the shadow map
|
||||
uniform float shadowScale;
|
||||
// Everything about shadow
|
||||
<@include Shadow.slh@>
|
||||
|
||||
// the distance to the near clip plane
|
||||
uniform float near;
|
||||
|
@ -52,15 +49,9 @@ void main(void) {
|
|||
float z = near / (depthVal * depthScale - 1.0);
|
||||
vec4 position = vec4((depthTexCoordOffset + gl_TexCoord[0].st * depthTexCoordScale) * z, z, 1.0);
|
||||
|
||||
// compute the corresponding texture coordinates
|
||||
vec3 shadowTexCoord = vec3(dot(gl_EyePlaneS[0], position), dot(gl_EyePlaneT[0], position), dot(gl_EyePlaneR[0], position));
|
||||
|
||||
// evaluate the shadow test but only relevant for light facing fragments
|
||||
float shadowAttenuation = (0.25 *
|
||||
(shadow2D(shadowMap, shadowTexCoord + vec3(-shadowScale, -shadowScale, 0.0)).r +
|
||||
shadow2D(shadowMap, shadowTexCoord + vec3(-shadowScale, shadowScale, 0.0)).r +
|
||||
shadow2D(shadowMap, shadowTexCoord + vec3(shadowScale, -shadowScale, 0.0)).r +
|
||||
shadow2D(shadowMap, shadowTexCoord + vec3(shadowScale, shadowScale, 0.0)).r));
|
||||
// Eval shadow Texcoord and then Attenuation
|
||||
vec4 shadowTexcoord = evalShadowTexcoord(position);
|
||||
float shadowAttenuation = evalShadowAttenuation(shadowTexcoord);
|
||||
|
||||
// get the normal from the map
|
||||
vec3 normalizedNormal = normalize(normalVal.xyz * 2.0 - vec3(1.0));
|
||||
|
|
Loading…
Reference in a new issue