Skip to content

Commit

Permalink
Update shaders
Browse files Browse the repository at this point in the history
  • Loading branch information
zmertens committed Nov 2, 2024
1 parent 8637cc7 commit 699753b
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 17 deletions.
14 changes: 7 additions & 7 deletions examples/Voxels/shaders/block_fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ void main() {
if (cloud && is_ortho) {
discard;
}
float df = cloud ? 1.0 - diffuse * 0.2 : diffuse;
float ao = cloud ? 1.0 - (1.0 - fragment_ao) * 0.2 : fragment_ao;
float df = cloud ? diffuse * 1.2 : diffuse;
float ao = cloud ? fragment_ao * 1.2 : fragment_ao;

ao = min(1.0, ao + fragment_light);
df = min(1.0, df + fragment_light);
float value = min(1.0, daylight + fragment_light);
ao += fragment_light;
df += fragment_light;
float value = daylight + fragment_light;
vec3 light_color = vec3(value * 0.3 + 0.2);
vec3 ambient = vec3(value * 0.3 + 0.2);
vec3 light = ambient + light_color * df;
color = clamp(color * light * ao, vec3(0.0), vec3(1.0));
color *= light * ao;
vec3 fog_mix = vec3(timer, fog_height, 0.0);
color = mix(color, vec3(0.0), fog_mix.y * fog_factor);
fragColor = vec4(color, 1.0);

float brightness = dot(fragColor.rgb, vec3(0.2126, 0.7152, 0.0722));
if (!cloud) {
if (brightness > 1.0) {
brightColor = vec4(fragColor.rgb, 1.0);
} else {
brightColor = vec4(0.0, 0.0, 0.0, 1.0);
Expand Down
17 changes: 8 additions & 9 deletions examples/Voxels/shaders/es/block_fragment.es.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
precision mediump float;

uniform sampler2D sampler;
uniform sampler2D sky_sampler;
uniform float timer;
uniform float daylight;
uniform bool is_ortho;
Expand All @@ -28,18 +27,18 @@ void main() {
if (cloud && is_ortho) {
discard;
}
float df = cloud ? 1.0 - diffuse * 0.2 : diffuse;
float ao = cloud ? 1.0 - (1.0 - fragment_ao) * 0.2 : fragment_ao;
float df = cloud ? diffuse * 1.2 : diffuse;
float ao = cloud ? fragment_ao * 1.2 : fragment_ao;

ao = min(1.0, ao + fragment_light);
df = min(1.0, df + fragment_light);
float value = min(1.0, daylight + fragment_light);
ao += fragment_light;
df += fragment_light;
float value = daylight + fragment_light;
vec3 light_color = vec3(value * 0.3 + 0.2);
vec3 ambient = vec3(value * 0.3 + 0.2);
vec3 light = ambient + light_color * df;
color = clamp(color * light * ao, vec3(0.0), vec3(1.0));
vec3 sky_color = texture(sky_sampler, vec2(timer, fog_height)).rgb;
color = mix(color, sky_color, fog_factor);
color *= light * ao;
vec3 fog_mix = vec3(timer, fog_height, 0.0);
color = mix(color, vec3(0.0), fog_mix.y * fog_factor);
fragColor = vec4(color, 1.0);

float brightness = dot(fragColor.rgb, vec3(0.2126, 0.7152, 0.0722));
Expand Down
21 changes: 21 additions & 0 deletions examples/Voxels/shaders/es/sky_fragment.es.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#version 300 es
precision mediump float;

layout (location = 0) out vec4 fragColor;
layout (location = 1) out vec4 brightColor;

in vec3 TexCoords;

uniform samplerCube skybox;

void main()
{
fragColor = texture(skybox, TexCoords);

float brightness = dot(fragColor.rgb, vec3(0.2126, 0.7152, 0.0722));
if (brightness > 0.2) {
brightColor = vec4(fragColor.rgb, 1.0);
} else {
brightColor = vec4(0.0, 0.0, 0.0, 1.0);
}
}
15 changes: 15 additions & 0 deletions examples/Voxels/shaders/es/sky_vertex.es.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#version 300 es
precision mediump float;

layout (location = 0) in vec3 aPos;

out vec3 TexCoords;

uniform mat4 matrix;

void main()
{
TexCoords = aPos;
vec4 pos = matrix * vec4(aPos, 1.0);
gl_Position = pos.xyww;
}
2 changes: 1 addition & 1 deletion examples/Voxels/shaders/skybox_fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void main()
fragColor = texture(skybox, TexCoords);

float brightness = dot(fragColor.rgb, vec3(0.2126, 0.7152, 0.0722));
if (brightness > 1.0) {
if (brightness > 0.2) {
brightColor = vec4(fragColor.rgb, 1.0);
} else {
brightColor = vec4(0.0, 0.0, 0.0, 1.0);
Expand Down

0 comments on commit 699753b

Please sign in to comment.