Skip to content

Commit

Permalink
Merge pull request #1186 from invor/Compositing
Browse files Browse the repository at this point in the history
Compositing
  • Loading branch information
invor authored Oct 12, 2023
2 parents ceb591b + e76b12c commit 84746b1
Show file tree
Hide file tree
Showing 44 changed files with 877 additions and 230 deletions.
23 changes: 23 additions & 0 deletions .ci/check-shaders-ignore.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,26 @@ plugins/protein_cuda/shaders/*
plugins/protein_gl/shaders/*
plugins/pwdemos_gl/shaders/*
plugins/test_gl/shaders/test_gl/srtest/*
plugins/compositing_gl/shaders/compositing_gl/depth_darkening.comp.glsl
plugins/compositing_gl/shaders/compositing_gl/edge_outline.comp.glsl
plugins/compositing_gl/shaders/compositing_gl/gauss_blur.comp.glsl
plugins/compositing_gl/shaders/compositing_gl/depth_darkening.comp.glsl
plugins/compositing_gl/shaders/compositing_gl/lambert.comp.glsl
plugins/compositing_gl/shaders/compositing_gl/naive_ssao.comp.glsl
plugins/compositing_gl/shaders/compositing_gl/depth_darkening.comp.glsl
plugins/compositing_gl/shaders/compositing_gl/normalFromDepth.comp.glsl
plugins/compositing_gl/shaders/compositing_gl/phong.comp.glsl
plugins/compositing_gl/shaders/compositing_gl/depth_darkening.comp.glsl
plugins/compositing_gl/shaders/compositing_gl/screenSpaceEdges.comp.glsl
plugins/compositing_gl/shaders/compositing_gl/simple_blur.comp.glsl
plugins/compositing_gl/shaders/compositing_gl/textureAdd.comp.glsl
plugins/compositing_gl/shaders/compositing_gl/textureAlphaCompositing.comp.glsl
plugins/compositing_gl/shaders/compositing_gl/textureDepthCompositing.comp.glsl
plugins/compositing_gl/shaders/compositing_gl/textureMultiply.comp.glsl
plugins/compositing_gl/shaders/compositing_gl/toon.comp.glsl
plugins/compositing_gl/shaders/compositing_gl/AntiAliasing/fxaa.comp.glsl
plugins/compositing_gl/shaders/compositing_gl/AntiAliasing/smaa_neighborhood_blending.comp.glsl
plugins/compositing_gl/shaders/compositing_gl/assao/apply.comp.glsl
plugins/compositing_gl/shaders/compositing_gl/assao/uniforms/apply_uniforms.glsl
plugins/compositing_gl/shaders/compositing_gl/assao/non_smart_apply.comp.glsl
plugins/compositing_gl/shaders/compositing_gl/assao/non_smart_half_apply.comp.glsl
27 changes: 27 additions & 0 deletions plugins/compositing_gl/include/compositing_gl/CompositingCalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,32 @@ class CallTexture2D : public core::GenericVersionedCall<std::shared_ptr<glowl::T
}
};

class CallTextureFormatData {
public:
int internalFormat;
int format;
int type;
inline CallTextureFormatData(int internalFormatP, int formatP, int typeP)
: internalFormat(internalFormatP)
, format(formatP)
, type(typeP) {}
~CallTextureFormatData() = default;
};

class CallTextureFormat
: public core::GenericVersionedCall<std::shared_ptr<CallTextureFormatData>, core::EmptyMetaData> {
public:
inline CallTextureFormat() : GenericVersionedCall<std::shared_ptr<CallTextureFormatData>, core::EmptyMetaData>() {}
~CallTextureFormat() override = default;

static const char* ClassName() {
return "CallTextureFormat";
}
static const char* Description() {
return "Transports texture formats for use in compositing output textures";
}
};

class CallCamera : public core::GenericVersionedCall<core::view::Camera, core::EmptyMetaData> {
public:
inline CallCamera() : GenericVersionedCall<core::view::Camera, core::EmptyMetaData>() {}
Expand Down Expand Up @@ -62,5 +88,6 @@ class CallFramebufferGL
typedef megamol::core::factories::CallAutoDescription<CallTexture2D> CallTexture2DDescription;
typedef megamol::core::factories::CallAutoDescription<CallCamera> CallCameraDescription;
typedef megamol::core::factories::CallAutoDescription<CallFramebufferGL> CallFramebufferGLDescription;
typedef megamol::core::factories::CallAutoDescription<CallTextureFormat> CallTextureFormatDescription;

} // namespace megamol::compositing_gl
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@

uniform sampler2D src_tx2D;

layout(rgba16) writeonly uniform image2D tgt_tx2D;
layout(OUTFORMAT) writeonly uniform image2D tgt_tx2D;



layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;

// see http://horde3d.org/wiki/index.php5?title=Shading_Technique_-_FXAA
void main()
{
void main() {
uvec3 gID = gl_GlobalInvocationID.xyz;
ivec2 pixel_coords = ivec2(gID.xy);
ivec2 tgt_resolution = imageSize (tgt_tx2D);
ivec2 tgt_resolution = imageSize(tgt_tx2D);

if (pixel_coords.x >= tgt_resolution.x || pixel_coords.y >= tgt_resolution.y) {
return;
Expand All @@ -26,50 +27,53 @@ void main()
vec2 pixel_coords_norm = (vec2(pixel_coords) + vec2(0.5)) / vec2(tgt_resolution);

float FXAA_SPAN_MAX = 8.0;
float FXAA_REDUCE_MUL = 1.0/8.0;
float FXAA_REDUCE_MIN = 1.0/128.0;
vec4 rgbNW = texelFetch(src_tx2D, pixel_coords + ivec2(-1,-1),0);
vec4 rgbNE = texelFetch(src_tx2D, pixel_coords + ivec2(1,-1) ,0);
vec4 rgbSW = texelFetch(src_tx2D, pixel_coords + ivec2(-1,1) ,0);
vec4 rgbSE = texelFetch(src_tx2D, pixel_coords + ivec2(1,1) ,0);
vec4 rgbM = texelFetch(src_tx2D, pixel_coords, 0);

vec3 luma=vec3(0.299, 0.587, 0.114);
float FXAA_REDUCE_MUL = 1.0 / 8.0;
float FXAA_REDUCE_MIN = 1.0 / 128.0;
vec4 rgbNW = texelFetch(src_tx2D, pixel_coords + ivec2(-1, -1), 0);
vec4 rgbNE = texelFetch(src_tx2D, pixel_coords + ivec2(1, -1), 0);
vec4 rgbSW = texelFetch(src_tx2D, pixel_coords + ivec2(-1, 1), 0);
vec4 rgbSE = texelFetch(src_tx2D, pixel_coords + ivec2(1, 1), 0);
vec4 rgbM = texelFetch(src_tx2D, pixel_coords, 0);

vec3 luma = vec3(0.299, 0.587, 0.114);
float lumaNW = dot(rgbNW.rgb, luma);
float lumaNE = dot(rgbNE.rgb, luma);
float lumaSW = dot(rgbSW.rgb, luma);
float lumaSE = dot(rgbSE.rgb, luma);
float lumaM = dot(rgbM.rgb, luma);
float lumaM = dot(rgbM.rgb, luma);

float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));
float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));

vec2 dir;
dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));
dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));
dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));

float dirReduce = max(
(lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL),
FXAA_REDUCE_MIN);
float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);

float rcpDirMin = 1.0/(min(abs(dir.x), abs(dir.y)) + dirReduce);
float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);

dir = min(vec2( FXAA_SPAN_MAX, FXAA_SPAN_MAX),
max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),
dir * rcpDirMin)) / vec2(tgt_resolution);
dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX), max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX), dir * rcpDirMin)) /
vec2(tgt_resolution);

vec4 rgbaA = (1.0/2.0) * (
texture(src_tx2D, pixel_coords_norm.xy + dir * (1.0/3.0 - 0.5)) +
texture(src_tx2D, pixel_coords_norm.xy + dir * (2.0/3.0 - 0.5)));
vec4 rgbaB = rgbaA * (1.0/2.0) + (1.0/4.0) * (
texture(src_tx2D, pixel_coords_norm.xy + dir * (0.0/3.0 - 0.5)) +
texture(src_tx2D, pixel_coords_norm.xy + dir * (3.0/3.0 - 0.5)));
vec4 rgbaA = (1.0 / 2.0) * (texture(src_tx2D, pixel_coords_norm.xy + dir * (1.0 / 3.0 - 0.5)) +
texture(src_tx2D, pixel_coords_norm.xy + dir * (2.0 / 3.0 - 0.5)));
vec4 rgbaB =
rgbaA * (1.0 / 2.0) + (1.0 / 4.0) * (texture(src_tx2D, pixel_coords_norm.xy + dir * (0.0 / 3.0 - 0.5)) +
texture(src_tx2D, pixel_coords_norm.xy + dir * (3.0 / 3.0 - 0.5)));
float lumaB = dot(rgbaB.rgb, luma);

if((lumaB < lumaMin) || (lumaB > lumaMax)){
imageStore(tgt_tx2D, pixel_coords , vec4(rgbaA) );
#ifdef OUTBYTEMODE
if ((lumaB < lumaMin) || (lumaB > lumaMax)) {
imageStore(tgt_tx2D, pixel_coords, uvec4(255 * rgbaA));
} else {
imageStore(tgt_tx2D, pixel_coords, uvec4(255 * rgbaB));
}
else{
imageStore(tgt_tx2D, pixel_coords , vec4(rgbaB) );
#else
if ((lumaB < lumaMin) || (lumaB > lumaMax)) {
imageStore(tgt_tx2D, pixel_coords, vec4(rgbaA));
} else {
imageStore(tgt_tx2D, pixel_coords, vec4(rgbaB));
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ uniform int SMAA_REPROJECTION;
uniform sampler2D g_colorTex;
uniform sampler2D g_blendingWeightsTex;
uniform sampler2D g_velocityTex;
layout(rgba16f, binding = 0) uniform image2D g_output;
layout(OUTFORMAT) writeonly uniform image2D g_output;



/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ void main()
float d = textureLod(g_FinalSSAOLinearClamp, vec3( inUV, 3 ), 0.0 ).x;
float avg = (a+d) * 0.5;

imageStore(g_FinalOutput, ivec2(inPos.xy), vec4(avg.xxx, 1.f));
imageStore(g_FinalOutput, ivec2(inPos.xy), vec4(avg.x));
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
uniform sampler2DArray g_FinalSSAO;
uniform sampler2DArray g_FinalSSAOLinearClamp;

layout(rgba16f, binding = 0) uniform writeonly image2D g_FinalOutput;
layout(OUTFORMAT, binding = 0) uniform writeonly image2D g_FinalOutput;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ uniform sampler2D color_tex;
uniform sampler2D depth_tex;
uniform sampler2D blurred_depth_tex;

layout(rgba16) writeonly uniform image2D target_tex;
layout(OUTFORMAT) writeonly uniform image2D target_tex;



layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void main(void) {
}
}
} else {
frag_out = texture(input_tx2D,uv_coord).rgba;
frag_out = vec4(texture(input_tx2D,uv_coord).rgba);
}

gl_FragDepth = texture(depth_tx2D, uv_coord).r;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ uniform sampler2D normal_tx2D;
uniform sampler2D depth_tx2D;
uniform sampler2D noise_tx2D;

layout(rgba16) writeonly uniform image2D tgt_tx2D;
layout(OUTFORMAT) writeonly uniform image2D tgt_tx2D;


uniform mat4 view_mx;
uniform mat4 proj_mx;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

uniform sampler2D source_tex;

layout(rgba16) writeonly uniform image2D target_tex;
layout(OUTFORMAT) writeonly uniform image2D target_tex;

layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ uniform sampler2D albedo_tx2D;
uniform sampler2D normal_tx2D;
uniform sampler2D depth_tx2D;

layout(rgba16) writeonly uniform image2D tgt_tx2D;
layout(OUTFORMAT) writeonly uniform image2D tgt_tx2D;

uniform int point_light_cnt;
uniform int distant_light_cnt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ uniform sampler2D normal_tx2D;
uniform sampler2D depth_tx2D;
uniform sampler2D noise_tx2D;

layout(rgba16) writeonly uniform image2D tgt_tx2D;
layout(OUTFORMAT) writeonly uniform image2D tgt_tx2D;

uniform mat4 view_mx;
uniform mat4 proj_mx;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

uniform sampler2D src_tx2D;

layout(RGBA16) writeonly uniform image2D tgt_tx2D;
layout(OUTFORMAT) writeonly uniform image2D tgt_tx2D;

uniform mat4 inv_view_mx;
uniform mat4 inv_proj_mx;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ uniform sampler2D albedo_tx2D;
uniform sampler2D normal_tx2D;
uniform sampler2D depth_tx2D;

layout(rgba16) writeonly uniform image2D tgt_tx2D;
layout(OUTFORMAT) writeonly uniform image2D tgt_tx2D;

uniform int point_light_cnt;
uniform int distant_light_cnt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ uniform sampler2D normal_tx2D;
uniform sampler2D depth_tx2D;
uniform sampler2D noise_tx2D;

layout(rgba16) writeonly uniform image2D tgt_tx2D;
layout(OUTFORMAT) writeonly uniform image2D tgt_tx2D;

uniform mat4 view_mx;
uniform mat4 proj_mx;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

uniform sampler2D src_tx2D;

layout(rgba16) writeonly uniform image2D tgt_tx2D;
layout(OUTFORMAT) writeonly uniform image2D tgt_tx2D;

layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ uniform sampler2D src1_tx2D; // secondary source texture, is read from using nor
uniform float weight0; // weight for texture 0
uniform float weight1; // weight for texture 1

layout(rgba16) writeonly uniform image2D tgt_tx2D;
layout(OUTFORMAT) writeonly uniform image2D tgt_tx2D;

layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ uniform sampler2D src1_tx2D; // secondary source texture, is read from using nor
uniform float src0_opacity;
uniform float src1_opacity;

layout(rgba16) writeonly uniform image2D tgt_tx2D;
layout(OUTFORMAT) writeonly uniform image2D tgt_tx2D;

layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ uniform sampler2D src1_tx2D; // secondary source texture, is read from using nor
uniform sampler2D depth0_tx2D;
uniform sampler2D depth1_tx2D;

layout(rgba16, binding = 0) writeonly uniform image2D tgt_tx2D;
layout(OUTFORMAT, binding = 0) writeonly uniform image2D tgt_tx2D;
layout(r32f, binding = 1) writeonly uniform image2D tgt_depth_tx2D;

layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
uniform sampler2D src0_tx2D; // primary source texture, target texture resolution will match this one
uniform sampler2D src1_tx2D; // secondary source texture, is read from using normalized texture coords derived from primary

layout(rgba16) writeonly uniform image2D tgt_tx2D;
layout(OUTFORMAT) writeonly uniform image2D tgt_tx2D;

layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ uniform sampler2D albedo_tx2D;
uniform sampler2D normal_tx2D;
uniform sampler2D depth_tx2D;

layout(rgba16) writeonly uniform image2D tgt_tx2D;
layout(OUTFORMAT) writeonly uniform image2D tgt_tx2D;

uniform int point_light_cnt;
uniform int distant_light_cnt;
Expand Down
Loading

0 comments on commit 84746b1

Please sign in to comment.