Skip to content

Commit

Permalink
Fix for alpha particles
Browse files Browse the repository at this point in the history
  • Loading branch information
CloudWolfYT committed Sep 24, 2023
1 parent 3886ffb commit 177e7a5
Show file tree
Hide file tree
Showing 28 changed files with 550 additions and 373 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,6 @@
}
]
},
{
"name": "toggler/remove",
"intarget": "particles",
"outtarget": "final"
},
{
"name": "blit",
"intarget": "final",
"outtarget": "particles"
},
{
"name": "transparency",
"intarget": "minecraft:main",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#version 150

uniform sampler2D DiffuseSampler;
uniform sampler2D DiffuseDepthSampler;
uniform sampler2D TranslucentSampler;
uniform sampler2D TranslucentDepthSampler;
uniform sampler2D ItemEntitySampler;
uniform sampler2D ItemEntityDepthSampler;
uniform sampler2D ParticlesSampler;
uniform sampler2D ParticlesDepthSampler;
uniform sampler2D WeatherSampler;
uniform sampler2D WeatherDepthSampler;
uniform sampler2D CloudsSampler;
uniform sampler2D CloudsDepthSampler;

in vec2 texCoord;


#define NUM_LAYERS 6

vec4 color_layers[NUM_LAYERS];
float depth_layers[NUM_LAYERS];
int active_layers = 0;

out vec4 fragColor;

void try_insert( vec4 color, float depth ) {
if ( color.a == 0.0 ) {
return;
}

color_layers[active_layers] = color;
depth_layers[active_layers] = depth;

int jj = active_layers++;
int ii = jj - 1;
while ( jj > 0 && depth_layers[jj] > depth_layers[ii] ) {
float depthTemp = depth_layers[ii];
depth_layers[ii] = depth_layers[jj];
depth_layers[jj] = depthTemp;

vec4 colorTemp = color_layers[ii];
color_layers[ii] = color_layers[jj];
color_layers[jj] = colorTemp;

jj = ii--;
}
}

flat in vec2 oneTexel;

void try_insert_particle( vec4 color, float depth ) {
vec4 col = color;
bool isMarker = col.rg * 255. == vec2(254., 253.);
if (isMarker) {
col = texture(
DiffuseSampler,
texCoord + vec2(0.0, oneTexel.y)
);
}

if ( col.a == 0.0 ) {
return;
}

color_layers[active_layers] = col;
depth_layers[active_layers] = depth;

int jj = active_layers++;
int ii = jj - 1;
while ( jj > 0 && depth_layers[jj] > depth_layers[ii] ) {
float depthTemp = depth_layers[ii];
depth_layers[ii] = depth_layers[jj];
depth_layers[jj] = depthTemp;

vec4 colorTemp = color_layers[ii];
color_layers[ii] = color_layers[jj];
color_layers[jj] = colorTemp;

jj = ii--;
}
}

vec3 blend( vec3 dst, vec4 src ) {
return ( dst * ( 1.0 - src.a ) ) + src.rgb;
}

void main() {
color_layers[0] = vec4( texture( DiffuseSampler, texCoord ).rgb, 1.0 );
depth_layers[0] = texture( DiffuseDepthSampler, texCoord ).r;
active_layers = 1;

try_insert( texture( TranslucentSampler, texCoord ), texture( TranslucentDepthSampler, texCoord ).r );
try_insert( texture( ItemEntitySampler, texCoord ), texture( ItemEntityDepthSampler, texCoord ).r );
try_insert_particle( texture( ParticlesSampler, texCoord ), texture( ParticlesDepthSampler, texCoord ).r );
try_insert( texture( WeatherSampler, texCoord ), texture( WeatherDepthSampler, texCoord ).r );
try_insert( texture( CloudsSampler, texCoord ), texture( CloudsDepthSampler, texCoord ).r );

vec3 texelAccum = color_layers[0].rgb;
for ( int ii = 1; ii < active_layers; ++ii ) {
texelAccum = blend( texelAccum, color_layers[ii] );
}

fragColor = vec4( texelAccum.rgb, 1.0 );
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"blend": {
"func": "add",
"srcrgb": "one",
"dstrgb": "zero"
},
"vertex": "screenquad",
"fragment": "transparency",
"attributes": [ "Position" ],
"samplers": [
{ "name": "DiffuseSampler" },
{ "name": "DiffuseDepthSampler" },
{ "name": "TranslucentSampler" },
{ "name": "TranslucentDepthSampler" },
{ "name": "ItemEntitySampler" },
{ "name": "ItemEntityDepthSampler" },
{ "name": "ParticlesSampler" },
{ "name": "ParticlesDepthSampler" },
{ "name": "CloudsSampler" },
{ "name": "CloudsDepthSampler" },
{ "name": "WeatherSampler" },
{ "name": "WeatherDepthSampler" }
],
"uniforms": [
{ "name": "ProjMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] },
{ "name": "OutSize", "type": "float", "count": 2, "values": [ 1.0, 1.0 ] }
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"targets": [
{ "name": "controller", "width": 2, "height": 3 },
{ "name": "controllerSwap", "width": 2, "height": 3 },
{ "name": "manic.tentacles", "width": 256, "height": 256},
"water",
"translucent",
"itemEntity",
Expand Down Expand Up @@ -30,16 +29,6 @@
}
]
},
{
"name": "toggler/remove",
"intarget": "particles",
"outtarget": "final"
},
{
"name": "blit",
"intarget": "final",
"outtarget": "particles"
},
{
"name": "transparency",
"intarget": "minecraft:main",
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 177e7a5

Please sign in to comment.