Have the first geom shader working that will explode the box.
This commit is contained in:
parent
c4c808f3c5
commit
22c2b78fca
13 changed files with 153 additions and 20 deletions
17
26-geometry-shaders/shaders/26-frag.glsl
Normal file
17
26-geometry-shaders/shaders/26-frag.glsl
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
in vec3 Normal;
|
||||
in vec3 FragPos;
|
||||
in vec2 TexCoords;
|
||||
|
||||
uniform vec3 cameraPos;
|
||||
uniform samplerCube skybox;
|
||||
|
||||
void main()
|
||||
{
|
||||
float ratio = 1.0/1.52;
|
||||
vec3 I = normalize(FragPos - cameraPos);
|
||||
vec3 R = refract(I, normalize(Normal), ratio);
|
||||
FragColor = vec4(texture(skybox, R).rgb, 1.0);
|
||||
}
|
||||
11
26-geometry-shaders/shaders/26-framebuffers.frag.glsl
Normal file
11
26-geometry-shaders/shaders/26-framebuffers.frag.glsl
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
in vec2 TexCoords;
|
||||
|
||||
uniform sampler2D texture1;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = texture(texture1, TexCoords);
|
||||
}
|
||||
23
26-geometry-shaders/shaders/26-framebuffers.vert.glsl
Normal file
23
26-geometry-shaders/shaders/26-framebuffers.vert.glsl
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#version 330 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aNormal;
|
||||
layout (location = 2) in vec2 aTexCoords;
|
||||
|
||||
out vec3 FragPos;
|
||||
out vec3 Normal;
|
||||
|
||||
out VS_OUT {
|
||||
vec2 texCoords;
|
||||
} vs_out;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = projection * view * model * vec4(aPos, 1.0);
|
||||
FragPos = vec3(model * vec4(aPos, 1.0));
|
||||
Normal = mat3(transpose(inverse(model))) * aNormal;
|
||||
vs_out.texCoords = aTexCoords;
|
||||
}
|
||||
40
26-geometry-shaders/shaders/26-geometry.glsl
Normal file
40
26-geometry-shaders/shaders/26-geometry.glsl
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#version 330 core
|
||||
layout (triangles) in;
|
||||
layout (triangle_strip, max_vertices = 3) out;
|
||||
|
||||
in VS_OUT {
|
||||
vec2 texCoords;
|
||||
} gs_in[];
|
||||
|
||||
out vec2 TexCoords;
|
||||
|
||||
uniform float time;
|
||||
|
||||
vec4 explode(vec4 position, vec3 normal)
|
||||
{
|
||||
float magnitude = 2.0;
|
||||
vec3 direction = normal * ((sin(time) + 1.0) / 2.0) * magnitude;
|
||||
return position + vec4(direction, 0.0);
|
||||
}
|
||||
|
||||
vec3 GetNormal()
|
||||
{
|
||||
vec3 a = vec3(gl_in[0].gl_Position) - vec3(gl_in[1].gl_Position);
|
||||
vec3 b = vec3(gl_in[2].gl_Position) - vec3(gl_in[1].gl_Position);
|
||||
return normalize(cross(a, b));
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec3 normal = GetNormal();
|
||||
|
||||
gl_Position = explode(gl_in[0].gl_Position, normal);
|
||||
TexCoords = gs_in[0].texCoords;
|
||||
EmitVertex();
|
||||
gl_Position = explode(gl_in[1].gl_Position, normal);
|
||||
TexCoords = gs_in[1].texCoords;
|
||||
EmitVertex();
|
||||
gl_Position = explode(gl_in[2].gl_Position, normal);
|
||||
TexCoords = gs_in[2].texCoords;
|
||||
EmitVertex();
|
||||
EndPrimitive();
|
||||
}
|
||||
21
26-geometry-shaders/shaders/26-vert.glsl
Normal file
21
26-geometry-shaders/shaders/26-vert.glsl
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#version 330 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aNormal;
|
||||
layout (location = 2) in vec2 aTexCoords;
|
||||
|
||||
out vec3 FragPos;
|
||||
out vec3 Normal;
|
||||
out vec2 TexCoords;
|
||||
out vec3 Position;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
void main()
|
||||
{
|
||||
Normal = mat3(transpose(inverse(model))) * aNormal;
|
||||
FragPos = vec3(model * vec4(aPos, 1.0));
|
||||
gl_Position = projection * view * vec4(FragPos, 1.0);
|
||||
TexCoords = aTexCoords;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue