diff --git a/extensions/obviousAlexC/penPlus.js b/extensions/obviousAlexC/penPlus.js index 966b4c162c..c3866f2695 100644 --- a/extensions/obviousAlexC/penPlus.js +++ b/extensions/obviousAlexC/penPlus.js @@ -94,6 +94,7 @@ ); gl.enable(gl.DEPTH_TEST); + gl.depthFunc(gl.LEQUAL); gl.bindFramebuffer(gl.FRAMEBUFFER, lastFB); @@ -136,8 +137,6 @@ null ); - console.log(nativeSize) - gl.activeTexture(gl.TEXTURE0); gl.bindFramebuffer(gl.FRAMEBUFFER, lastFB); @@ -157,7 +156,10 @@ let lastHQPen = renderer.useHighQualityRender; vm.runtime.on("BEFORE_EXECUTE", () => { - if (lastURL != window.location.href || lastHQPen != renderer.useHighQualityRender) { + if ( + lastURL != window.location.href || + lastHQPen != renderer.useHighQualityRender + ) { lastURL = window.location.href; lastHQPen = renderer.useHighQualityRender; updateCanvasSize(); @@ -179,7 +181,7 @@ let penPlusImportWrapMode = gl.CLAMP_TO_EDGE; //?Debug for depth - //penPlusCostumeLibrary["!Debug_Depth"] = depthBufferTexture; + penPlusCostumeLibrary["!Debug_Depth"] = depthBufferTexture; const checkForPen = (util) => { const curTarget = util.target; @@ -221,116 +223,116 @@ untextured: { Shaders: { vert: ` - attribute highp vec4 a_position; - attribute highp vec4 a_color; - varying vec4 v_color; - - varying highp float v_depth; - - void main() - { - v_color = a_color; - v_depth = a_position.z; - gl_Position = a_position * vec4(a_position.w,a_position.w,0,1); - } - `, - frag: ` - varying highp vec4 v_color; - - uniform mediump vec2 u_res; - uniform sampler2D u_depthTexture; - - varying highp float v_depth; - - void main() - { - gl_FragColor = v_color; - highp vec4 v_depthPart = texture2D(u_depthTexture,gl_FragCoord.xy/u_res); - highp float v_depthcalc = (v_depthPart.r+v_depthPart.g+v_depthPart.b)/3.0; - if (v_depth >= v_depthcalc - 0.075){ - gl_FragColor.a = 0.0; - } - gl_FragColor.rgb *= gl_FragColor.a; - } - `, - }, - ProgramInf: null, - }, - textured: { - Shaders: { - vert: ` - attribute highp vec4 a_position; - attribute highp vec4 a_color; - attribute highp vec2 a_texCoord; - - varying highp vec4 v_color; - varying highp vec2 v_texCoord; - - varying highp float v_depth; - - void main() - { + attribute highp vec4 a_position; + attribute highp vec4 a_color; + varying vec4 v_color; + + varying highp float v_depth; + + void main() + { v_color = a_color; - v_texCoord = a_texCoord; v_depth = a_position.z; gl_Position = a_position * vec4(a_position.w,a_position.w,0,1); - } - `, + } + `, frag: ` - uniform sampler2D u_texture; - - varying highp vec2 v_texCoord; - varying highp vec4 v_color; - - uniform mediump vec2 u_res; - uniform sampler2D u_depthTexture; - - varying highp float v_depth; - - void main() - { - gl_FragColor = texture2D(u_texture, v_texCoord) * v_color; + varying highp vec4 v_color; + + uniform mediump vec2 u_res; + uniform sampler2D u_depthTexture; + + varying highp float v_depth; + + void main() + { + gl_FragColor = v_color; highp vec4 v_depthPart = texture2D(u_depthTexture,gl_FragCoord.xy/u_res); highp float v_depthcalc = (v_depthPart.r+v_depthPart.g+v_depthPart.b)/3.0; - if (v_depth >= v_depthcalc - 0.075){ + if (v_depthcalc < v_depth){ gl_FragColor.a = 0.0; } gl_FragColor.rgb *= gl_FragColor.a; - - } - `, + } + `, + }, + ProgramInf: null, + }, + textured: { + Shaders: { + vert: ` + attribute highp vec4 a_position; + attribute highp vec4 a_color; + attribute highp vec2 a_texCoord; + + varying highp vec4 v_color; + varying highp vec2 v_texCoord; + + varying highp float v_depth; + + void main() + { + v_color = a_color; + v_texCoord = a_texCoord; + v_depth = a_position.z * 3.0; + gl_Position = a_position * vec4(a_position.w,a_position.w,0,1); + } + `, + frag: ` + uniform sampler2D u_texture; + + varying highp vec2 v_texCoord; + varying highp vec4 v_color; + + uniform mediump vec2 u_res; + uniform sampler2D u_depthTexture; + + varying highp float v_depth; + + void main() + { + gl_FragColor = texture2D(u_texture, v_texCoord) * v_color; + highp vec4 v_depthPart = texture2D(u_depthTexture,gl_FragCoord.xy/u_res); + highp float v_depthcalc = (v_depthPart.r+v_depthPart.g+v_depthPart.b); + if (v_depthcalc < v_depth){ + gl_FragColor.a = 0.0; + } + gl_FragColor.rgb *= gl_FragColor.a; + + } + `, }, ProgramInf: null, }, depth: { Shaders: { vert: ` - attribute highp vec4 a_position; - - varying highp float v_depth; - - void main() - { - v_depth = a_position.z*3.0; - gl_Position = a_position * vec4(a_position.w,a_position.w,1,1); - } - `, + attribute highp vec4 a_position; + + varying highp float v_depth; + + void main() + { + v_depth = a_position.z*3.0; + gl_Position = a_position * vec4(a_position.w,a_position.w,a_position.w,1); + } + `, frag: ` - varying highp float v_depth; - - void main() - { - gl_FragColor = vec4(v_depth,0,0,1); - if (v_depth>1.0) { - gl_FragColor.r = 1.0; - gl_FragColor.g = v_depth-1.0; - if (v_depth>2.0) { - gl_FragColor.g = 1.0; - gl_FragColor.b = v_depth-2.0; + varying highp float v_depth; + + void main() + { + gl_FragColor = vec4(v_depth,0,0,1); + if (v_depth>1.0) { + gl_FragColor.r = 1.0; + gl_FragColor.g = v_depth-1.0; + if (v_depth>2.0) { + gl_FragColor.g = 1.0; + gl_FragColor.b = v_depth-2.0; + } } - } - } - `, + } + `, }, ProgramInf: null, }, @@ -606,7 +608,7 @@ gl.drawArrays(gl.TRIANGLES, 0, 3); //? Hacky fix but it works. - //triFunctions.drawDepthTri(targetID, x1, y1, x2, y2, x3, y3); + triFunctions.drawDepthTri(targetID, x1, y1, x2, y2, x3, y3); gl.useProgram(penPlusShaders.pen.program); },