Skip to content
Permalink
Browse files

fix texture 3d OpenGL problem on MacOS

  • Loading branch information
PeterPetrik committed Nov 19, 2020
1 parent f3f0522 commit e096c4484d5a258e660f6184646ac72f5478a79a
Showing with 8 additions and 8 deletions.
  1. +6 −6 src/3d/shaders/postprocess.frag
  2. +2 −2 src/3d/shaders/preview.frag
@@ -1,4 +1,4 @@
#version 150 core
#version 330

uniform sampler2D colorTexture;
uniform sampler2D depthTexture;
@@ -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;
}
}
@@ -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)
{
@@ -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);
@@ -1,4 +1,4 @@
#version 150 core
#version 330

uniform sampler2D previewTexture;
uniform bool isDepth;
@@ -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.
You can’t perform that action at this time.