Skip to content

Commit

Permalink
Apply depthBias (similar to glPolygonOffset)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhochsteger committed Oct 16, 2024
1 parent 16c54b5 commit c056fd6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 0 additions & 1 deletion shader.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ fn mainVertexTrig(@builtin(vertex_index) vertexId: u32, @builtin(instance_index)
var vid: u32 = trig.v[vertexId];
var p = vertices[vid];
var position = calcPosition(p);
position.z = 0.01;
var lam: vec3<f32> = vec3<f32>(0.);
lam[vertexId] = 1.0;
var value: f32 = p.x;
Expand Down
13 changes: 10 additions & 3 deletions webgpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(self, device, canvas):
self.depth_stencil = {
"format": self.depth_format,
"depthWriteEnabled": True,
"depthCompare": "less-equal",
"depthCompare": "less",
}

self.depth_texture = device.createTexture(
Expand Down Expand Up @@ -302,7 +302,9 @@ def _create_pipelines(self, shader_code):
"targets": [{"format": self.gpu.format}],
},
"primitive": {"topology": "line-list"},
"depthStencil": self.gpu.depth_stencil,
"depthStencil": {
**self.gpu.depth_stencil,
},
}
)
)
Expand All @@ -321,7 +323,12 @@ def _create_pipelines(self, shader_code):
"targets": [{"format": self.gpu.format}],
},
"primitive": {"topology": "triangle-list"},
"depthStencil": self.gpu.depth_stencil,
"depthStencil": {
**self.gpu.depth_stencil,
# shift trigs behind to ensure that edges are rendered properly
"depthBias": 1.0,
"depthBiasSlopeScale": 1,
},
}
)
)
Expand Down

0 comments on commit c056fd6

Please sign in to comment.