Skip to content

Commit

Permalink
[rs] Merge gfx-rs#382
Browse files Browse the repository at this point in the history
382: Remove interface blocks from the water shaders r=kvark a=kvark

Fixes gfx-rs/gfx#3274

Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
  • Loading branch information
bors[bot] and kvark authored Jun 17, 2020
2 parents 0d807b7 + 9cd109e commit 2369c74
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 27 deletions.
Binary file modified wgpu/examples/cube/shader.frag.spv
Binary file not shown.
Binary file modified wgpu/examples/hello-compute/shader.comp.spv
Binary file not shown.
8 changes: 3 additions & 5 deletions wgpu/examples/water/terrain_shader.frag
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

layout(early_fragment_tests) in;

layout(location = 0) in PerVertex {
vec4 v_Colour;
// Comment this out if using user-clipping planes:
float v_ClipDist;
};
layout(location = 0) in vec4 v_Colour;
// Comment this out if using user-clipping planes:
layout(location = 1) in float v_ClipDist;

layout(location = 0) out vec4 outColour;

Expand Down
Binary file modified wgpu/examples/water/terrain_shader.frag.spv
Binary file not shown.
8 changes: 3 additions & 5 deletions wgpu/examples/water/terrain_shader.vert
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ layout(location = 0) in vec3 position;
layout(location = 1) in vec3 normal;
layout(location = 2) in vec4 colour;

layout(location = 0) out PerVertex {
vec4 v_Colour;
// Comment this out if using user-clipping planes:
float v_ClipDist;
};
layout(location = 0) out vec4 v_Colour;
// Comment this out if using user-clipping planes:
layout(location = 1) out float v_ClipDist;

void main() {
gl_Position = projection_view * vec4(position, 1.0);
Expand Down
Binary file modified wgpu/examples/water/terrain_shader.vert.spv
Binary file not shown.
16 changes: 7 additions & 9 deletions wgpu/examples/water/water_shader.frag
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ layout(set = 0, binding = 1) uniform texture2D reflection;
layout(set = 0, binding = 2) uniform texture2D terrain_depth_tex;
layout(set = 0, binding = 3) uniform sampler colour_sampler;

layout(location = 0) in PerVertex {
vec2 f_WaterScreenPos;
float f_Fresnel;
vec3 f_Light;
} f_In;
layout(location = 0) in vec2 f_WaterScreenPos;
layout(location = 1) in float f_Fresnel;
layout(location = 2) in vec3 f_Light;

layout(location = 0) out vec4 outColor;

Expand All @@ -30,17 +28,17 @@ float to_linear_depth(float depth) {
}

void main() {
vec3 reflection_colour = texture(sampler2D(reflection, colour_sampler), f_In.f_WaterScreenPos.xy).xyz;
vec3 reflection_colour = texture(sampler2D(reflection, colour_sampler), f_WaterScreenPos.xy).xyz;

float pixel_depth = to_linear_depth(gl_FragCoord.z);
float terrain_depth = to_linear_depth(texture(sampler2D(terrain_depth_tex, colour_sampler), gl_FragCoord.xy / vec2(time_size_width.w, viewport_height)).r);

float dist = terrain_depth - pixel_depth;
float clamped = smoothstep(0.0, 1.0, dist);
float clamped = pow(smoothstep(0.0, 1.5, dist), 4.8);

outColor.a = clamped * (1.0 - f_In.f_Fresnel);
outColor.a = clamped * (1.0 - f_Fresnel);

vec3 final_colour = f_In.f_Light + reflection_colour;
vec3 final_colour = f_Light + reflection_colour;

vec3 depth_colour = mix(final_colour, water_colour, smoothstep(1.0, 5.0, dist) * 0.2);

Expand Down
Binary file modified wgpu/examples/water/water_shader.frag.spv
Binary file not shown.
14 changes: 6 additions & 8 deletions wgpu/examples/water/water_shader.vert
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ const float INV_1_CURVE_BIAS = 1.0 / (1.0 + CURVE_BIAS);
layout(location = 0) in ivec2 position;
layout(location = 1) in ivec4 offsets;

layout(location = 0) out PerVertex {
vec2 f_WaterScreenPos;
float f_Fresnel;
vec3 f_Light;
} f_In;
layout(location = 0) out vec2 f_WaterScreenPos;
layout(location = 1) out float f_Fresnel;
layout(location = 2) out vec3 f_Light;

//
// The following code to calculate simplex 3D
Expand Down Expand Up @@ -201,13 +199,13 @@ void main() {

vec4 transformed_light = vm * vec4(light_point, 1.0);

f_In.f_Light = light_colour * calc_specular(eye, normal, normalize(water_pos.xyz - (transformed_light.xyz / transformed_light.w)));
f_In.f_Fresnel = calc_fresnel(eye, normal);
f_Light = light_colour * calc_specular(eye, normal, normalize(water_pos.xyz - (transformed_light.xyz / transformed_light.w)));
f_Fresnel = calc_fresnel(eye, normal);

vec4 projected_pos = projection * transformed_pos;

gl_Position = projected_pos;

vec4 gridpos = projection * vm * original_pos;
f_In.f_WaterScreenPos.xy = (0.5 * gridpos.xy / gridpos.w) + 0.5;
f_WaterScreenPos.xy = (0.5 * gridpos.xy / gridpos.w) + 0.5;
}
Binary file modified wgpu/examples/water/water_shader.vert.spv
Binary file not shown.

0 comments on commit 2369c74

Please sign in to comment.