Skip to content

Commit

Permalink
Fix uniforms issue on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
lwjglgamedev committed Mar 9, 2024
1 parent 93a593e commit a2f2edf
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 24 deletions.
12 changes: 2 additions & 10 deletions chapter-17/resources/shaders/scene.frag
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ uniform SpotLight spotLights[MAX_SPOT_LIGHTS];
uniform DirLight dirLight;
uniform Fog fog;
uniform CascadeShadow cascadeshadows[NUM_CASCADES];
uniform sampler2D shadowMap_0;
uniform sampler2D shadowMap_1;
uniform sampler2D shadowMap_2;
uniform sampler2D shadowMap[NUM_CASCADES];

vec4 calcAmbient(AmbientLight ambientLight, vec4 ambient) {
return vec4(ambientLight.factor * ambientLight.color, 1) * ambient;
Expand Down Expand Up @@ -156,13 +154,7 @@ float textureProj(vec4 shadowCoord, vec2 offset, int idx) {

if (shadowCoord.z > -1.0 && shadowCoord.z < 1.0) {
float dist = 0.0;
if (idx == 0) {
dist = texture(shadowMap_0, vec2(shadowCoord.xy + offset)).r;
} else if (idx == 1) {
dist = texture(shadowMap_1, vec2(shadowCoord.xy + offset)).r;
} else {
dist = texture(shadowMap_2, vec2(shadowCoord.xy + offset)).r;
}
dist = texture(shadowMap[idx], vec2(shadowCoord.xy + offset)).r;
if (shadowCoord.w > 0 && dist < shadowCoord.z - BIAS) {
shadow = SHADOW_FACTOR;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private void createUniforms() {
uniformsMap.createUniform("fog.density");

for (int i = 0; i < CascadeShadow.SHADOW_MAP_CASCADE_COUNT; i++) {
uniformsMap.createUniform("shadowMap_" + i);
uniformsMap.createUniform("shadowMap[" + i + "]");
uniformsMap.createUniform("cascadeshadows[" + i + "]" + ".projViewMatrix");
uniformsMap.createUniform("cascadeshadows[" + i + "]" + ".splitDistance");
}
Expand Down Expand Up @@ -102,7 +102,7 @@ public void render(Scene scene, ShadowRender shadowRender) {
int start = 2;
List<CascadeShadow> cascadeShadows = shadowRender.getCascadeShadows();
for (int i = 0; i < CascadeShadow.SHADOW_MAP_CASCADE_COUNT; i++) {
uniformsMap.setUniform("shadowMap_" + i, start + i);
uniformsMap.setUniform("shadowMap[" + i + "]", start + i);
CascadeShadow cascadeShadow = cascadeShadows.get(i);
uniformsMap.setUniform("cascadeshadows[" + i + "]" + ".projViewMatrix", cascadeShadow.getProjViewMatrix());
uniformsMap.setUniform("cascadeshadows[" + i + "]" + ".splitDistance", cascadeShadow.getSplitDistance());
Expand Down
12 changes: 2 additions & 10 deletions chapter-18/resources/shaders/scene.frag
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ uniform SpotLight spotLights[MAX_SPOT_LIGHTS];
uniform DirLight dirLight;
uniform Fog fog;
uniform CascadeShadow cascadeshadows[NUM_CASCADES];
uniform sampler2D shadowMap_0;
uniform sampler2D shadowMap_1;
uniform sampler2D shadowMap_2;
uniform sampler2D shadowMap[NUM_CASCADES];
uniform int selected;

vec4 calcAmbient(AmbientLight ambientLight, vec4 ambient) {
Expand Down Expand Up @@ -157,13 +155,7 @@ float textureProj(vec4 shadowCoord, vec2 offset, int idx) {

if (shadowCoord.z > -1.0 && shadowCoord.z < 1.0) {
float dist = 0.0;
if (idx == 0) {
dist = texture(shadowMap_0, vec2(shadowCoord.xy + offset)).r;
} else if (idx == 1) {
dist = texture(shadowMap_1, vec2(shadowCoord.xy + offset)).r;
} else {
dist = texture(shadowMap_2, vec2(shadowCoord.xy + offset)).r;
}
dist = texture(shadowMap[idx], vec2(shadowCoord.xy + offset)).r;
if (shadowCoord.w > 0 && dist < shadowCoord.z - BIAS) {
shadow = SHADOW_FACTOR;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private void createUniforms() {
uniformsMap.createUniform("fog.density");

for (int i = 0; i < CascadeShadow.SHADOW_MAP_CASCADE_COUNT; i++) {
uniformsMap.createUniform("shadowMap_" + i);
uniformsMap.createUniform("shadowMap[" + i + "]");
uniformsMap.createUniform("cascadeshadows[" + i + "]" + ".projViewMatrix");
uniformsMap.createUniform("cascadeshadows[" + i + "]" + ".splitDistance");
}
Expand Down Expand Up @@ -103,7 +103,7 @@ public void render(Scene scene, ShadowRender shadowRender) {
int start = 2;
List<CascadeShadow> cascadeShadows = shadowRender.getCascadeShadows();
for (int i = 0; i < CascadeShadow.SHADOW_MAP_CASCADE_COUNT; i++) {
uniformsMap.setUniform("shadowMap_" + i, start + i);
uniformsMap.setUniform("shadowMap[" + i + "]", start + i);
CascadeShadow cascadeShadow = cascadeShadows.get(i);
uniformsMap.setUniform("cascadeshadows[" + i + "]" + ".projViewMatrix", cascadeShadow.getProjViewMatrix());
uniformsMap.setUniform("cascadeshadows[" + i + "]" + ".splitDistance", cascadeShadow.getSplitDistance());
Expand Down

0 comments on commit a2f2edf

Please sign in to comment.