examples/gkurve: adjust frag shader to show barycentric coordinates
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
2b2ba15332
commit
ff5636c6f6
1 changed files with 13 additions and 16 deletions
|
|
@ -6,14 +6,13 @@ struct FragUniform {
|
||||||
|
|
||||||
@stage(fragment) fn main(
|
@stage(fragment) fn main(
|
||||||
@location(0) uv: vec2<f32>,
|
@location(0) uv: vec2<f32>,
|
||||||
@interpolate(linear) @location(1) bary: vec3<f32>,
|
@interpolate(linear) @location(1) bary: vec2<f32>,
|
||||||
@interpolate(flat) @location(2) triangle_index: u32,
|
@interpolate(flat) @location(2) triangle_index: u32,
|
||||||
) -> @location(0) vec4<f32> {
|
) -> @location(0) vec4<f32> {
|
||||||
// Example 1: Visualize barycentric coordinates:
|
// Example 1: Visualize barycentric coordinates:
|
||||||
// return vec4<f32>(bary.x, bary.y, bary.z, 1.0);
|
// return vec4<f32>(bary.x, bary.y, 0.0, 1.0);
|
||||||
// return vec4<f32>(0.0, bary.x, 0.0, 1.0); // bottom-left of triangle
|
// return vec4<f32>(0.0, bary.x, 0.0, 1.0); // [1.0 (bottom-left vertex), 0.0 (bottom-right vertex)]
|
||||||
// return vec4<f32>(0.0, bary.y, 0.0, 1.0); // bottom-right of triangle
|
// return vec4<f32>(0.0, bary.y, 0.0, 1.0); // [1.0 (bottom-left vertex), 1.0 (top-right face)]
|
||||||
// return vec4<f32>(0.0, bary.z, 0.0, 1.0); // top of triangle
|
|
||||||
|
|
||||||
// Example 2: Render gkurve primitives
|
// Example 2: Render gkurve primitives
|
||||||
var inversion = -1.0;
|
var inversion = -1.0;
|
||||||
|
|
@ -38,11 +37,9 @@ struct FragUniform {
|
||||||
|
|
||||||
// Signed distance
|
// Signed distance
|
||||||
var dist = (bary.x * bary.x - bary.y) / sqrt(fx * fx + fy * fy);
|
var dist = (bary.x * bary.x - bary.y) / sqrt(fx * fx + fy * fy);
|
||||||
// var dist = bary.z*bary.z - bary.y;
|
|
||||||
|
|
||||||
dist *= inversion;
|
dist *= inversion;
|
||||||
dist /= 128.0;
|
dist /= 300.0;
|
||||||
dist /= 1.75;
|
|
||||||
|
|
||||||
// Border rendering.
|
// Border rendering.
|
||||||
if (dist > 0.0 && dist <= 0.1) { return vec4<f32>(1.0, 0.0, 0.0, 1.0); }
|
if (dist > 0.0 && dist <= 0.1) { return vec4<f32>(1.0, 0.0, 0.0, 1.0); }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue