Skip to content

Commit

Permalink
Workaround for yet another AMD driver bug.
Browse files Browse the repository at this point in the history
It crashed with newer versions of the driver on Windows and Linux if an instance name is used for the frame SSBO block. It doesn't crash with older versions (was introduced in driver release 15.12 or 15.11 IIRC and still crashes on 16.5.3). Also it doesn't crash on Nvidia hardware.
  • Loading branch information
Yves-G committed Jun 9, 2016
1 parent 5db4d9a commit 43110f2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
30 changes: 15 additions & 15 deletions binaries/data/mods/public/shaders/glsl/model_common.fs
Expand Up @@ -41,7 +41,7 @@ layout(shared) buffer FrameUBO
layout (bindless_sampler) sampler2D shadowTex;
#endif

} frame;
};

#if USE_SHADOW
in vec4 v_shadow;
Expand Down Expand Up @@ -136,19 +136,19 @@ float get_shadow()
#if USE_SHADOW_PCF
vec2 offset = fract(v_shadow.xy - 0.5);
vec4 size = vec4(offset + 1.0, 2.0 - offset);
vec4 weight = (vec4(1.0, 1.0, -0.5, -0.5) + (v_shadow.xy - 0.5*offset).xyxy) * frame.shadowScale.zwzw;
vec4 weight = (vec4(1.0, 1.0, -0.5, -0.5) + (v_shadow.xy - 0.5*offset).xyxy) * shadowScale.zwzw;
return (1.0/9.0)*dot(size.zxzx*size.wwyy,
vec4(texture(frame.shadowTex, vec3(weight.zw, biasedShdwZ)).r,
texture(frame.shadowTex, vec3(weight.xw, biasedShdwZ)).r,
texture(frame.shadowTex, vec3(weight.zy, biasedShdwZ)).r,
texture(frame.shadowTex, vec3(weight.xy, biasedShdwZ)).r));
vec4(texture(shadowTex, vec3(weight.zw, biasedShdwZ)).r,
texture(shadowTex, vec3(weight.xw, biasedShdwZ)).r,
texture(shadowTex, vec3(weight.zy, biasedShdwZ)).r,
texture(shadowTex, vec3(weight.xy, biasedShdwZ)).r));
#else
return texture(frame.shadowTex, vec3(v_shadow.xy, biasedShdwZ)).r;
return texture(shadowTex, vec3(v_shadow.xy, biasedShdwZ)).r;
#endif
//#else
// if (biasedShdwZ >= 1.0)
// return 1.0;
// return (biasedShdwZ < texture(frame.shadowTex, v_shadow.xy).x ? 1.0 : 0.0);
// return (biasedShdwZ < texture(shadowTex, v_shadow.xy).x ? 1.0 : 0.0);
//#endif
#else
return 1.0;
Expand All @@ -157,8 +157,8 @@ float get_shadow()

vec3 get_fog(vec3 color)
{
float density = frame.fogParams.x;
float maxFog = frame.fogParams.y;
float density = fogParams.x;
float maxFog = fogParams.y;

const float LOG2 = 1.442695;
float z = gl_FragCoord.z / gl_FragCoord.w;
Expand All @@ -168,7 +168,7 @@ vec3 get_fog(vec3 color)

fogFactor = clamp(fogFactor, 0.0, 1.0);

return mix(frame.fogColor, color, fogFactor);
return mix(fogColor, color, fogFactor);
}

void main()
Expand Down Expand Up @@ -255,7 +255,7 @@ void main()
vec3 ntex = texture(material[materialIDVal].normTex, coord).rgb * 2.0 - 1.0;
ntex.y = -ntex.y;
normal = normalize(tbn * ntex);
vec3 bumplight = max(dot(-frame.sunDir, normal), 0.0) * frame.sunColor;
vec3 bumplight = max(dot(-sunDir, normal), 0.0) * sunColor;
vec3 sundiffuse = (bumplight - v_lighting.rgb) * matTempl[matTemplIdVal].effectSettings.x + v_lighting.rgb;
#else
vec3 sundiffuse = v_lighting.rgb;
Expand All @@ -274,11 +274,11 @@ void main()
specCol = matTempl[matTemplIdVal].specularColor;
specPow = matTempl[matTemplIdVal].specularPower;
#endif
specular.rgb = frame.sunColor * specCol * pow(max(0.0, dot(normalize(normal), v_half)), specPow);
specular.rgb = sunColor * specCol * pow(max(0.0, dot(normalize(normal), v_half)), specPow);
#endif

vec3 color = (texdiffuse * sundiffuse + specular.rgb) * get_shadow();
vec3 ambColor = texdiffuse * frame.ambient;
vec3 ambColor = texdiffuse * ambient;

#if (USE_INSTANCING || USE_GPU_SKINNING) && USE_AO
vec3 ao = texture(material[materialIDVal].aoTex, v_tex2).rrr;
Expand All @@ -295,7 +295,7 @@ void main()
color = get_fog(color);

#if !IGNORE_LOS
float los = texture(frame.losTex, v_los).a;
float los = texture(losTex, v_los).a;
los = los < 0.03 ? 0.0 : los;
color *= los;
#endif
Expand Down
22 changes: 11 additions & 11 deletions binaries/data/mods/public/shaders/glsl/model_common.vs
Expand Up @@ -41,7 +41,7 @@ layout(shared) buffer FrameUBO
layout (bindless_sampler) sampler2D shadowTex;
#endif

} frame;
};

// TODO: make block members conditional again
struct DrawStruct
Expand Down Expand Up @@ -241,9 +241,9 @@ void main()
vec4 cosVec;
// these determine the speed of the wind's "cosine" waves.
cosVec.w = 0.0;
cosVec.x = frame.sim_time.x * modelPos[0] + position.x;
cosVec.y = frame.sim_time.x * modelPos[2] / 3.0 + draws[drawID].instancingTransform[3][0];
cosVec.z = frame.sim_time.x * abswind / 4.0 + position.z;
cosVec.x = sim_time.x * modelPos[0] + position.x;
cosVec.y = sim_time.x * modelPos[2] / 3.0 + draws[drawID].instancingTransform[3][0];
cosVec.z = sim_time.x * abswind / 4.0 + position.z;

// calculate "cosines" in parallel, using a smoothed triangle wave
cosVec = fakeCos(cosVec);
Expand All @@ -261,7 +261,7 @@ void main()
#endif


gl_Position = frame.transform * position;
gl_Position = transform * position;

#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_PARALLAX
v_normal.xyz = normal;
Expand All @@ -275,9 +275,9 @@ void main()
#endif

#if USE_SPECULAR || USE_SPECULAR_MAP || USE_PARALLAX
vec3 eyeVec = frame.cameraPos.xyz - position.xyz;
vec3 eyeVec = cameraPos.xyz - position.xyz;
#if USE_SPECULAR || USE_SPECULAR_MAP
vec3 sunVec = -frame.sunDir;
vec3 sunVec = -sunDir;
v_half = normalize(sunVec + normalize(eyeVec));
#endif
#if (USE_INSTANCING || USE_GPU_SKINNING) && USE_PARALLAX
Expand All @@ -286,7 +286,7 @@ void main()
#endif
#endif

v_lighting.xyz = max(0.0, dot(normal, -frame.sunDir)) * frame.sunColor;
v_lighting.xyz = max(0.0, dot(normal, -sunDir)) * sunColor;

v_tex = a_uv0;

Expand All @@ -295,12 +295,12 @@ void main()
#endif

#if USE_SHADOW
v_shadow = frame.shadowTransform * position;
v_shadow = shadowTransform * position;
#if USE_SHADOW_SAMPLER && USE_SHADOW_PCF
v_shadow.xy *= frame.shadowScale.xy;
v_shadow.xy *= shadowScale.xy;
#endif
#endif

v_los = position.xz * frame.losTransform.x + frame.losTransform.y;
v_los = position.xz * losTransform.x + losTransform.y;

}
8 changes: 4 additions & 4 deletions binaries/data/mods/public/shaders/glsl/solid_player.fs
Expand Up @@ -37,7 +37,7 @@ layout(shared) buffer FrameUBO
layout (bindless_sampler) sampler2D shadowTex;
#endif

} frame;
};


// TODO: make block members conditional again
Expand Down Expand Up @@ -67,8 +67,8 @@ layout(shared) buffer ModelBlock

vec3 get_fog(vec3 color)
{
float density = frame.fogParams.x;
float maxFog = frame.fogParams.y;
float density = fogParams.x;
float maxFog = fogParams.y;

const float LOG2 = 1.442695;
float z = gl_FragCoord.z / gl_FragCoord.w;
Expand All @@ -78,7 +78,7 @@ vec3 get_fog(vec3 color)

fogFactor = clamp(fogFactor, 0.0, 1.0);

return mix(frame.fogColor, color, fogFactor);
return mix(fogColor, color, fogFactor);
}

void main()
Expand Down

0 comments on commit 43110f2

Please sign in to comment.