Skip to content

Commit

Permalink
Z Buffer is production ready
Browse files Browse the repository at this point in the history
  • Loading branch information
David-Orangemoon committed Aug 21, 2023
1 parent 8821d58 commit e8cdbeb
Showing 1 changed file with 100 additions and 98 deletions.
198 changes: 100 additions & 98 deletions extensions/obviousAlexC/penPlus.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
);

gl.enable(gl.DEPTH_TEST);
gl.depthFunc(gl.LEQUAL);

gl.bindFramebuffer(gl.FRAMEBUFFER, lastFB);

Expand Down Expand Up @@ -136,8 +137,6 @@
null
);

console.log(nativeSize)

gl.activeTexture(gl.TEXTURE0);

gl.bindFramebuffer(gl.FRAMEBUFFER, lastFB);
Expand All @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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);
},

Expand Down

0 comments on commit e8cdbeb

Please sign in to comment.