colortex buffers not accessible between composite passes

Both fragment shaders are attached. This outputs black to the screen, despite the last line of the second pass just loading the texture from the first pass.
1 Reply
Akarys
AkarysOP2mo ago
composite.fsh:
#version 330 compatibility

uniform sampler2D colortex1; // normals

uniform float viewWidth;
uniform float viewHeight;

in vec2 texcoord;

/* DRAWBUFFERS:2 */
layout(location = 2) out vec4 edge;

void make_kernel(inout vec4 n[9], sampler2D tex, vec2 coord)
{
float w = 1.0 / viewWidth;
float h = 1.0 / viewHeight;

n[0] = texture2D(tex, coord + vec2( -w, -h));
n[1] = texture2D(tex, coord + vec2(0.0, -h));
n[2] = texture2D(tex, coord + vec2( w, -h));
n[3] = texture2D(tex, coord + vec2( -w, 0.0));
n[4] = texture2D(tex, coord);
n[5] = texture2D(tex, coord + vec2( w, 0.0));
n[6] = texture2D(tex, coord + vec2( -w, h));
n[7] = texture2D(tex, coord + vec2(0.0, h));
n[8] = texture2D(tex, coord + vec2( w, h));
}

void main() {
vec4 n[9];
make_kernel(n, colortex1, texcoord);

vec3 sobel_x = n[2].rgb + 2.0 * n[5].rgb + n[8].rgb - n[0].rgb - 2.0 * n[3].rgb - n[6].rgb;
vec3 sobel_y = n[0].rgb + 2.0 * n[1].rgb + n[2].rgb - n[6].rgb - 2.0 * n[7].rgb - n[8].rgb;
vec3 sobel = sqrt(sobel_x * sobel_x + sobel_y * sobel_y);

float max = max(max(abs(sobel.x), abs(sobel.y)), abs(sobel.z));

edge = vec4(max, max, max, 1.0);
}
#version 330 compatibility

uniform sampler2D colortex1; // normals

uniform float viewWidth;
uniform float viewHeight;

in vec2 texcoord;

/* DRAWBUFFERS:2 */
layout(location = 2) out vec4 edge;

void make_kernel(inout vec4 n[9], sampler2D tex, vec2 coord)
{
float w = 1.0 / viewWidth;
float h = 1.0 / viewHeight;

n[0] = texture2D(tex, coord + vec2( -w, -h));
n[1] = texture2D(tex, coord + vec2(0.0, -h));
n[2] = texture2D(tex, coord + vec2( w, -h));
n[3] = texture2D(tex, coord + vec2( -w, 0.0));
n[4] = texture2D(tex, coord);
n[5] = texture2D(tex, coord + vec2( w, 0.0));
n[6] = texture2D(tex, coord + vec2( -w, h));
n[7] = texture2D(tex, coord + vec2(0.0, h));
n[8] = texture2D(tex, coord + vec2( w, h));
}

void main() {
vec4 n[9];
make_kernel(n, colortex1, texcoord);

vec3 sobel_x = n[2].rgb + 2.0 * n[5].rgb + n[8].rgb - n[0].rgb - 2.0 * n[3].rgb - n[6].rgb;
vec3 sobel_y = n[0].rgb + 2.0 * n[1].rgb + n[2].rgb - n[6].rgb - 2.0 * n[7].rgb - n[8].rgb;
vec3 sobel = sqrt(sobel_x * sobel_x + sobel_y * sobel_y);

float max = max(max(abs(sobel.x), abs(sobel.y)), abs(sobel.z));

edge = vec4(max, max, max, 1.0);
}
composite1.fsh:
#version 330 compatibility

uniform sampler2D colortex2; // edge

uniform float viewWidth;
uniform float viewHeight;

in vec2 texcoord;

/* DRAWBUFFERS:03 */
layout(location = 3) out vec4 bloom;
layout(location = 0) out vec4 color;

void main() {
int blurSize = 2;

vec4 bloomColor = vec4(0.0);

for (int x = -blurSize; x <= blurSize; x++) {
for (int y = -blurSize; y <= blurSize; y++) {
bloomColor += texture2D(colortex2, texcoord + vec2(x, y) / vec2(viewWidth, viewHeight));
}
}

bloomColor /= (2 * blurSize + 1) * (2 * blurSize + 1);
bloomColor.a = 1.0;

bloom = bloomColor;
// color = bloom;
color = texture2D(colortex2, texcoord);
}
#version 330 compatibility

uniform sampler2D colortex2; // edge

uniform float viewWidth;
uniform float viewHeight;

in vec2 texcoord;

/* DRAWBUFFERS:03 */
layout(location = 3) out vec4 bloom;
layout(location = 0) out vec4 color;

void main() {
int blurSize = 2;

vec4 bloomColor = vec4(0.0);

for (int x = -blurSize; x <= blurSize; x++) {
for (int y = -blurSize; y <= blurSize; y++) {
bloomColor += texture2D(colortex2, texcoord + vec2(x, y) / vec2(viewWidth, viewHeight));
}
}

bloomColor /= (2 * blurSize + 1) * (2 * blurSize + 1);
bloomColor.a = 1.0;

bloom = bloomColor;
// color = bloom;
color = texture2D(colortex2, texcoord);
}
I got it, the directive was a little misleading
Want results from more Discord servers?
Add your server