Skip to content

Commit c70461d

Browse files
authored
fix depth write when depth testing is off (playcanvas#2604)
1 parent ac90b87 commit c70461d

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/scene/forward-renderer.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
CLEARFLAG_COLOR, CLEARFLAG_DEPTH, CLEARFLAG_STENCIL,
1616
CULLFACE_BACK, CULLFACE_FRONT, CULLFACE_FRONTANDBACK, CULLFACE_NONE,
1717
FILTER_LINEAR, FILTER_NEAREST,
18-
FUNC_ALWAYS, FUNC_LESS,
18+
FUNC_ALWAYS, FUNC_LESS, FUNC_LESSEQUAL,
1919
PIXELFORMAT_DEPTH, PIXELFORMAT_R8_G8_B8_A8, PIXELFORMAT_RGBA16F, PIXELFORMAT_RGBA32F,
2020
PRIMITIVE_TRIANGLES,
2121
SEMANTIC_ATTR, SEMANTIC_POSITION,
@@ -1813,7 +1813,16 @@ Object.assign(ForwardRenderer.prototype, {
18131813
}
18141814
device.setColorWrite(material.redWrite, material.greenWrite, material.blueWrite, material.alphaWrite);
18151815
device.setDepthWrite(material.depthWrite);
1816-
device.setDepthTest(material.depthTest);
1816+
1817+
// this fixes the case where the user wishes to turn off depth testing but wants to write depth
1818+
if (material.depthWrite && !material.depthTest){
1819+
device.setDepthFunc(FUNC_ALWAYS);
1820+
device.setDepthTest(true);
1821+
} else {
1822+
device.setDepthFunc(FUNC_LESSEQUAL);
1823+
device.setDepthTest(material.depthTest);
1824+
}
1825+
18171826
device.setAlphaToCoverage(material.alphaToCoverage);
18181827

18191828
if (material.depthBias || material.slopeDepthBias) {

0 commit comments

Comments
 (0)