Skip to content

Commit

Permalink
[rs] Mipmapping example
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Jun 17, 2019
1 parent 154ed3a commit 2b047f9
Show file tree
Hide file tree
Showing 7 changed files with 475 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# Other
.DS_Store
2 changes: 1 addition & 1 deletion wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ gl = ["wgn/gfx-backend-gl"]

[dependencies]
#TODO: only depend on the published version
wgn = { package = "wgpu-native", features = ["local", "window-winit"], git = "https://github.com/gfx-rs/wgpu", rev = "8cc50253c428fb0a9aab3c74639a866465d65272" }
wgn = { package = "wgpu-native", version = "0.2.6", features = ["local", "window-winit"], git = "https://github.com/gfx-rs/wgpu", rev = "a667d50d01c3df03b8540c523278e111da7fc82a" }
arrayvec = "0.4"

[dev-dependencies]
Expand Down
10 changes: 10 additions & 0 deletions wgpu/examples/mipmap/blit.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#version 450

layout(location = 0) in vec2 v_TexCoord;
layout(location = 0) out vec4 o_Target;
layout(set = 0, binding = 0) uniform texture2D t_Color;
layout(set = 0, binding = 1) uniform sampler s_Color;

void main() {
o_Target = textureLod(sampler2D(t_Color, s_Color), v_TexCoord, 0.0);
}
15 changes: 15 additions & 0 deletions wgpu/examples/mipmap/blit.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#version 450

layout(location = 0) out vec2 v_TexCoord;

void main() {
vec2 tc = vec2(0.0);
switch(gl_VertexIndex) {
case 0: tc = vec2(1.0, 0.0); break;
case 1: tc = vec2(1.0, 1.0); break;
case 2: tc = vec2(0.0, 0.0); break;
case 3: tc = vec2(0.0, 1.0); break;
}
v_TexCoord = tc;
gl_Position = vec4(tc * 2.0 - 1.0, 0.5, 1.0);
}
12 changes: 12 additions & 0 deletions wgpu/examples/mipmap/draw.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#version 450

layout(location = 0) in vec2 v_TexCoord;
layout(location = 0) out vec4 o_Target;
layout(set = 0, binding = 1) uniform texture2D t_Color;
layout(set = 0, binding = 2) uniform sampler s_Color;

void main() {
vec4 tex = texture(sampler2D(t_Color, s_Color), v_TexCoord);
float mag = length(v_TexCoord-vec2(0.5));
o_Target = mix(tex, vec4(0.0), mag*mag);
}
15 changes: 15 additions & 0 deletions wgpu/examples/mipmap/draw.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#version 450

layout(location = 0) in vec4 a_Pos;
layout(location = 0) out vec2 v_TexCoord;

layout(set = 0, binding = 0) uniform Locals {
mat4 u_Transform;
};

void main() {
v_TexCoord = a_Pos.xy / 10.0;
gl_Position = u_Transform * a_Pos;
// convert from -1,1 Z to 0,1
gl_Position.z = 0.5 * (gl_Position.z + gl_Position.w);
}
Loading

0 comments on commit 2b047f9

Please sign in to comment.