-
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
Showing
4 changed files
with
23 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
@fragment | ||
fn fragmentMain(input : VertexOutput) -> @location(0) vec4f { | ||
let grid = vec2f(22, 12); | ||
return vec4f(input.cell / grid, 0, 1); | ||
} | ||
fn fragmentMain() -> @location(0) vec4f { | ||
return vec4<f32>(1.0, 0.0, 0.0, 1.0); // 红色 | ||
} |
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 |
---|---|---|
@@ -1,24 +1,5 @@ | ||
@group(0) @binding(0) var<uniform> grid : vec2f; | ||
struct VertexOutput { | ||
@builtin(position) pos : vec4f, | ||
@location(0) cell : vec2f | ||
}; | ||
|
||
@vertex | ||
fn vertexMain(@location(0) pos : vec2 < f32>, @builtin(instance_index) instance : u32) -> | ||
VertexOutput { | ||
//网格大小:12*12 | ||
let grid = vec2f(22, 12); | ||
//第一个单元格下标 | ||
let i = f32(instance); | ||
let cell = vec2f(i % grid.x, floor(i / grid.x)); | ||
//将左边系从-1,1转换成0,2 | ||
let convertPos = pos + 1; | ||
//计算偏移量 | ||
let cellOffset = cell / grid * 2; | ||
let gridPos = convertPos / grid - 1 + cellOffset; | ||
var output : VertexOutput; | ||
output.pos = vec4f(gridPos, 0, 1); | ||
output.cell = cell; | ||
return output; | ||
fn vertexMain(@location(0) position: vec2<f32>) -> | ||
@builtin(position) vec4<f32> { | ||
return vec4<f32>(position, 0.0, 1.0); | ||
} |
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