Skip to content

Commit

Permalink
added support for 8 different render passes
Browse files Browse the repository at this point in the history
  • Loading branch information
EddieBreeg committed Jan 12, 2023
1 parent cc4eeac commit 88efa9c
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 23 deletions.
18 changes: 11 additions & 7 deletions defaultShaders.h
Original file line number Diff line number Diff line change
@@ -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"\
Expand All @@ -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"
Expand Down
11 changes: 10 additions & 1 deletion examples/blank.glsl
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
void main(){ fragColor = vec4(1, 1, 0, 1);}
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);
}
2 changes: 1 addition & 1 deletion examples/disk.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion examples/julia.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ void main(){
}
}
int index = int(round(float(i)/float(maxIter) * 32));
fragColor = palette[index];
frag0 = palette[index];
}
3 changes: 2 additions & 1 deletion examples/mandelbrot.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
2 changes: 1 addition & 1 deletion examples/noise.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
13 changes: 6 additions & 7 deletions examples/voronoi.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
13 changes: 9 additions & 4 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,20 @@ class GLExplorer: public GLBase::Application
std::string _filePath;
std::vector<UserParam> _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;
Expand Down

0 comments on commit 88efa9c

Please sign in to comment.