Skip to content

Commit

Permalink
fix texture 3d OpenGL problem on MacOS
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterPetrik committed Nov 19, 2020
1 parent f3f0522 commit e096c44
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/3d/shaders/postprocess.frag
@@ -1,4 +1,4 @@
#version 150 core
#version 330

uniform sampler2D colorTexture;
uniform sampler2D depthTexture;
Expand Down Expand Up @@ -73,7 +73,7 @@ float CalcShadowFactor(vec4 LightSpacePos)
{
for(int y = -k; y <= k; ++y)
{
float pcfDepth = texture2D(shadowTexture, UVCoords + vec2(x, y) * texelSize).r;
float pcfDepth = texture(shadowTexture, UVCoords + vec2(x, y) * texelSize).r;
shadow += z - shadowBias >= pcfDepth ? 0.5 : 1.0;
}
}
Expand All @@ -92,11 +92,11 @@ float edlFactor(vec2 coords)
vec2 texelSize = 2.0 / textureSize(depthTexture, 0);
vec2 neighbours[4] = vec2[4](vec2(-1.0f, 0.0f), vec2(1.0f, 0.0f), vec2(0.0f, -1.0f), vec2(0.0f, 1.0f) );
float factor = 0.0f;
float centerDepth = linearizeDepth( texture2D(depthTexture, coords).r ) / farPlane;
float centerDepth = linearizeDepth( texture(depthTexture, coords).r ) / farPlane;
for (int i = 0; i < 4; i++)
{
vec2 neighbourCoords = coords + edlDistance * texelSize * neighbours[i];
float neighbourDepth = linearizeDepth( texture2D(depthTexture, neighbourCoords).r ) / farPlane;
float neighbourDepth = linearizeDepth( texture(depthTexture, neighbourCoords).r ) / farPlane;
neighbourDepth = (neighbourDepth == 1.0) ? 0.0 : neighbourDepth;
if (neighbourDepth != 0.0f)
{
Expand All @@ -109,10 +109,10 @@ float edlFactor(vec2 coords)

void main()
{
vec3 worldPosition = WorldPosFromDepth(texture2D(depthTexture, texCoord).r);
vec3 worldPosition = WorldPosFromDepth(texture(depthTexture, texCoord).r);
vec4 positionInLightSpace = projectionMatrix * viewMatrix * vec4(worldPosition, 1.0f);
positionInLightSpace /= positionInLightSpace.w;
vec3 color = texture2D(colorTexture, texCoord).rgb;
vec3 color = texture(colorTexture, texCoord).rgb;
// if shadow rendering is disabled or the pixel is outside the shadow rendering distance don't render shadows
if (renderShadows == 0 || worldPosition.x > shadowMaxX || worldPosition.x < shadowMinX || worldPosition.z > shadowMaxZ || worldPosition.z < shadowMinZ) {
fragColor = vec4(color.rgb, 1.0f);
Expand Down
4 changes: 2 additions & 2 deletions src/3d/shaders/preview.frag
@@ -1,4 +1,4 @@
#version 150 core
#version 330

uniform sampler2D previewTexture;
uniform bool isDepth;
Expand All @@ -14,7 +14,7 @@ void main()
// When trying to display a depth texture make sure to linearize the depth value
// if you are using a perspective projection
if (isDepth)
fragColor = vec4(vec3(texture2D(previewTexture, texCoord).r), 1.0f);
fragColor = vec4(vec3(texture(previewTexture, texCoord).r), 1.0f);
else
fragColor = vec4(texture(previewTexture, texCoord).rgb, 1.0f);
}

0 comments on commit e096c44

Please sign in to comment.