From 88efa9cf69ab9231184e80b73a68da9918457a46 Mon Sep 17 00:00:00 2001 From: Eddie Breeg Date: Thu, 12 Jan 2023 17:16:11 -0500 Subject: [PATCH] added support for 8 different render passes --- defaultShaders.h | 18 +++++++++++------- examples/blank.glsl | 11 ++++++++++- examples/disk.glsl | 2 +- examples/julia.glsl | 2 +- examples/mandelbrot.glsl | 3 ++- examples/noise.glsl | 2 +- examples/voronoi.glsl | 13 ++++++------- main.cpp | 13 +++++++++---- 8 files changed, 41 insertions(+), 23 deletions(-) diff --git a/defaultShaders.h b/defaultShaders.h index fdb9694..e48ca65 100644 --- a/defaultShaders.h +++ b/defaultShaders.h @@ -1,9 +1,14 @@ #pragma once #define FRAG_SHADER_HEADER "#version 450 core\n"\ -"layout(location=0) out vec4 fragColor; \n"\ -"layout(location=1) out vec3 fragNormal; \n"\ -"layout(location=2) out vec4 fragCombined; \n"\ +"layout(location=0) out vec4 frag0; \n"\ +"layout(location=1) out vec4 frag1; \n"\ +"layout(location=2) out vec4 frag2; \n"\ +"layout(location=3) out vec4 frag3; \n"\ +"layout(location=4) out vec4 frag4; \n"\ +"layout(location=5) out vec4 frag5; \n"\ +"layout(location=6) out vec4 frag6; \n"\ +"layout(location=7) out vec4 frag7; \n"\ "in vec4 pos;\n"\ "in vec2 uv;\n" \ "uniform float scale;\n"\ @@ -30,12 +35,11 @@ void main() static constexpr const char *defaultFragShader= FRAG_SHADER_HEADER "void main(){ " - "float v = texture(texNoise, scale*uv+offset.xy).x;" - "fragColor = vec4(v); " - "fragNormal=vec3(0, 0, 1); }"; + "frag0 = vec4(0); " + "frag1=vec4(0, 0, 1, 1); }"; static constexpr const char *errorFragShader = - FRAG_SHADER_HEADER "void main(){fragColor = vec4(1, 0, 1, 1);}"; + FRAG_SHADER_HEADER "void main(){frag0 = vec4(1, 0, 1, 1);}"; static constexpr const char *simpleTextureShader = "#version 450 core\n" diff --git a/examples/blank.glsl b/examples/blank.glsl index c89e834..acb8ed0 100644 --- a/examples/blank.glsl +++ b/examples/blank.glsl @@ -1 +1,10 @@ -void main(){ fragColor = vec4(1, 1, 0, 1);} \ No newline at end of file +void main(){ + frag0 = vec4(0, 0, 0, 1); + frag1 = vec4(0, 0, 1, 1); + frag2 = vec4(0, 1, 0, 1); + frag3 = vec4(0, 1, 1, 1); + frag4 = vec4(1, 0, 0, 1); + frag5 = vec4(1, 0, 1, 1); + frag6 = vec4(1, 1, 0, 1); + frag7 = vec4(1, 1, 1, 1); +} \ No newline at end of file diff --git a/examples/disk.glsl b/examples/disk.glsl index df9ac0b..1988d12 100644 --- a/examples/disk.glsl +++ b/examples/disk.glsl @@ -5,5 +5,5 @@ uniform vec4 color = vec4(1, .5, 0, 1); void main() { vec2 p = vec2(pos.x*res.x/res.y, pos.y) * scale + offset.xy; float fac = 1-smoothstep(r, (1+smoothness)*r, length(p)); - fragColor = fac * color; + frag0 = fac * color; } \ No newline at end of file diff --git a/examples/julia.glsl b/examples/julia.glsl index 87a980f..9d67893 100644 --- a/examples/julia.glsl +++ b/examples/julia.glsl @@ -55,5 +55,5 @@ void main(){ } } int index = int(round(float(i)/float(maxIter) * 32)); - fragColor = palette[index]; + frag0 = palette[index]; } \ No newline at end of file diff --git a/examples/mandelbrot.glsl b/examples/mandelbrot.glsl index 78ed5c9..7a57f76 100644 --- a/examples/mandelbrot.glsl +++ b/examples/mandelbrot.glsl @@ -22,11 +22,12 @@ vec4 palette[16] = { void main(){ vec2 C = pos.xy; + C.x *= res.x/res.y; vec2 Z = vec2(0); int i = 0; while(i++ < maxIter && dot(Z, Z) <= 4){ Z = vec2(Z.x * Z.x - Z.y * Z.y, 2*Z.x*Z.y) + C; } int index = int(round(float(i) / float(maxIter) * 16)); - fragColor = palette[index]; + frag0 = palette[index]; } \ No newline at end of file diff --git a/examples/noise.glsl b/examples/noise.glsl index 3b6eb5c..0d45ffe 100644 --- a/examples/noise.glsl +++ b/examples/noise.glsl @@ -14,5 +14,5 @@ vec4 hash4(vec4 x){ void main() { vec4 p = (scale*pos+offset)/scale; - fragColor = vec4(hash4(p).xyz, 1); + frag0 = vec4(hash4(p).xyz, 1); } \ No newline at end of file diff --git a/examples/voronoi.glsl b/examples/voronoi.glsl index e419d22..cd172a2 100644 --- a/examples/voronoi.glsl +++ b/examples/voronoi.glsl @@ -68,18 +68,17 @@ void main() vec3 dy = vec3(0, 2/(res.y), 0); float R = voronoi(P+dx, temp); float B = voronoi(P-dy, temp); - fragNormal = normalize(vec3( + vec3 normal = normalize(vec3( (d-R)/dx.x, (B-d)/dy.y, - -1 - )); + -1)); + frag1 = vec4(.5 * normal + .5, 1); vec3 lightOffset = vec3(cos(speed*time), sin(speed*time), 0); float lightDistance = length(lightSource+lightOffset - P); - float lightValue = dot(normalize(lightSource+lightOffset - P), fragNormal) * lightPower + float lightValue = dot(normalize(lightSource+lightOffset - P), normal) * lightPower / pow(lightDistance, lightAttenuation); - fragCombined = baseColor * lightValue; + frag2 = baseColor * lightValue; - fragNormal = fragNormal /2 + .5; - fragColor = vec4(d); + frag0 = vec4(d); } \ No newline at end of file diff --git a/main.cpp b/main.cpp index e6733a3..98be692 100644 --- a/main.cpp +++ b/main.cpp @@ -24,15 +24,20 @@ class GLExplorer: public GLBase::Application std::string _filePath; std::vector _shaderSettings; GLBase::FrameBuffer _renderFBO; - GLBase::Texture _textures[3]; + GLBase::Texture _textures[8]; GLBase::Texture _noise; int _selectedRenderPass = 0; static constexpr const char *_renderPasses[] = { - "Base Color", - "Normal", - "Combined" + "Pass 0", + "Pass 1", + "Pass 2", + "Pass 3", + "Pass 4", + "Pass 5", + "Pass 6", + "Pass 7", }; bool _vsync = 0;