Skip to content

Commit

Permalink
change: Move light texture transformations into VS stage
Browse files Browse the repository at this point in the history
  • Loading branch information
jellysquid3 committed May 5, 2020
1 parent d477649 commit ebec0bc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
5 changes: 1 addition & 4 deletions src/main/resources/assets/sodium/shaders/chunk.f.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ uniform vec4 u_FogColor;
uniform sampler2D u_BlockTex;
uniform sampler2D u_LightTex;

const float LIGHT_COORD_SCALE = 1.0 / 256.0;
const float LIGHT_COORD_OFFSET = 1.0 / 32.0;

void main() {
vec4 sampleBlockTex = texture2D(u_BlockTex, v_TexCoord);
vec4 sampleLightTex = texture2D(u_LightTex, (v_LightCoord * LIGHT_COORD_SCALE) + LIGHT_COORD_OFFSET);
vec4 sampleLightTex = texture2D(u_LightTex, v_LightCoord);

vec4 texColor = v_Color * sampleBlockTex * sampleLightTex;

Expand Down
8 changes: 5 additions & 3 deletions src/main/resources/assets/sodium/shaders/chunk.v.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ uniform mat4 u_ProjectionMatrix;
uniform mat4 u_ModelViewMatrix;
uniform vec3 u_ModelOffset;

const float LIGHT_COORD_SCALE = 1.0 / 256.0;
const float LIGHT_COORD_OFFSET = 1.0 / 32.0;

void main() {
vec4 viewSpacePos = u_ModelViewMatrix * vec4(a_Pos + u_ModelOffset, 1.0);
gl_Position = u_ProjectionMatrix * viewSpacePos;

#ifdef USE_FOG_EXP2
float dist = length(viewSpacePos) * u_FogDensity;
Expand All @@ -41,7 +45,5 @@ void main() {

v_Color = a_Color;
v_TexCoord = a_TexCoord;
v_LightCoord = a_LightCoord;

gl_Position = u_ProjectionMatrix * viewSpacePos;
v_LightCoord = (a_LightCoord * LIGHT_COORD_SCALE) + LIGHT_COORD_OFFSET;
}

0 comments on commit ebec0bc

Please sign in to comment.