Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ function createScene(options) {
}
for(var i = 0; i < numObjsNow(); ++i) {
var o = objects[i]
if(o.isOpaque && o.isOpaque()) o.draw(cameraParams)
if(o.isOpaque && o.isOpaque() && !o.alwaysOnTop) o.draw(cameraParams)
}

gl.colorMask(true, true, true, true)
Expand Down Expand Up @@ -1002,10 +1002,10 @@ function createScene(options) {
var obj = objects[i]
obj.axes = axes
obj.pixelRatio = scene.pixelRatio
if(obj.isOpaque && obj.isOpaque()) {
if(obj.isOpaque && obj.isOpaque() && !obj.alwaysOnTop) {
obj.draw(cameraParams)
}
if(obj.isTransparent && obj.isTransparent()) {
if(obj.isTransparent && obj.isTransparent() && !obj.alwaysOnTop) {
hasTransparent = true
}
}
Expand All @@ -1016,7 +1016,7 @@ function createScene(options) {
var legacyObjs = false
for(var i=0; i<numObjs; ++i) {
var obj = objects[i]
if(obj.isTransparent && obj.isTransparent()) {
if(obj.isTransparent && obj.isTransparent() && !obj.alwaysOnTop) {
if(obj.drawOIT) {
oitObjs.push(obj)
} else {
Expand Down Expand Up @@ -1047,7 +1047,7 @@ function createScene(options) {
}
for(var i=0; i<numObjs; ++i) {
var obj = objects[i]
if(obj.isOpaque && obj.isOpaque()) {
if(obj.isOpaque && obj.isOpaque() && !obj.alwaysOnTop) {
obj.draw(cameraParams)
}
}
Expand All @@ -1067,7 +1067,7 @@ function createScene(options) {

for(var i=0; i<numObjs; ++i) {
var obj = objects[i]
if(obj.isTransparent && obj.isTransparent() && !(oitUse && obj.drawOIT)) {
if(obj.isTransparent && obj.isTransparent() && !obj.alwaysOnTop && !(oitUse && obj.drawOIT)) {
obj.drawTransparent(cameraParams)
}
}
Expand Down Expand Up @@ -1097,6 +1097,29 @@ function createScene(options) {
oitSetStatus(OIT_NONE)
}

// objects flagged alwaysOnTop: drawn last, over the composite, no depth test, premultiplied blending
var topDrawn = false
for(var i=0; i<numObjs; ++i) {
var obj = objects[i]
if(obj.alwaysOnTop) {
if(!topDrawn) {
topDrawn = true
gl.bindFramebuffer(gl.FRAMEBUFFER, null)
gl.viewport(0, 0, width, height)
gl.colorMask(true, true, true, true)
gl.disable(gl.DEPTH_TEST)
gl.enable(gl.BLEND)
gl.blendEquation(gl.FUNC_ADD)
gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA)
}
obj.draw(cameraParams)
obj.drawTransparent(cameraParams)
}
}
if(topDrawn) {
gl.disable(gl.BLEND)
}

//Clear dirty flags
dirty = false
for(var i=0; i<numObjs; ++i) {
Expand Down