-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a107e6
commit bbac066
Showing
7 changed files
with
203 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// vertex shader | ||
|
||
struct Uniforms { | ||
MVP: mat4x4<f32> | ||
} | ||
@binding(0) @group(0) var<uniform> uniforms: Uniforms; | ||
|
||
struct VertexInput { | ||
@location(0) pos: vec4<f32>, | ||
@location(1) color: vec4<f32>, | ||
@location(2) normal: vec4<f32> | ||
}; | ||
|
||
struct VertexOutput { | ||
@builtin(position) position: vec4<f32>, | ||
@location(0) vPosition: vec3<f32>, | ||
@location(1) vColor: vec4<f32>, | ||
@location(2) vNormal: vec3<f32> | ||
}; | ||
|
||
@vertex | ||
fn vs_main(in: VertexInput) -> VertexOutput { | ||
var output: VertexOutput; | ||
output.position = uniforms.MVP * in.pos; | ||
output.vPosition = in.pos.xyz; | ||
output.vColor = in.color; | ||
output.vNormal = in.normal.xyz; | ||
return output; | ||
} | ||
|
||
struct FragUniforms { | ||
light_dir: vec3<f32>, | ||
camera_position: vec3<f32>, | ||
max_height: f32, | ||
sphere_radius: f32 | ||
}; | ||
@binding(1) @group(0) var<uniform> frag_uniforms : FragUniforms; | ||
|
||
@fragment | ||
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> { | ||
let height01 = (length(in.vPosition) - frag_uniforms.sphere_radius) / frag_uniforms.max_height; | ||
let grass_color = vec3(0.0, 0.5, 0.0); | ||
let snow_color = vec3(1.0, 1.0, 1.0); | ||
|
||
let flat_color = mix(grass_color, snow_color, smoothstep(0.5, 0.6, height01)); | ||
|
||
let slope = 1.0 - pow(dot(normalize(in.vNormal), normalize(in.vPosition)), 32.0); | ||
let slope_color = vec3(0.2, 0.1, 0.1); | ||
|
||
let ndl: f32 = max(dot(in.vNormal, normalize(frag_uniforms.light_dir)), 0.01); | ||
|
||
let color: vec3<f32> = mix(flat_color, slope_color, smoothstep(0.8, 0.9, slope)); | ||
|
||
return vec4(ndl * color, 1.0); | ||
} |