generate mesh from points using geometry shader

pull/5/head
EmaMaker 2023-07-19 12:42:45 +02:00
parent e7fc35ec47
commit 54c7fa172f
3 changed files with 106 additions and 21 deletions

View File

@ -2,29 +2,29 @@
out vec4 FragColor;
in vec3 vNormal;
in vec3 vTexCoord;
in vec3 TexCoord;
in vec3 Normal;
in vec3 FragPos;
vec3 lightColor = vec3(1.0);
vec3 lightDir = -normalize(vec3(0.0, 100.0, 0.0) - vec3(32.0));
float ambientStrength = 0.4;
float diffuseStrength = 0.45;
float specularStrength = 0.05;
float ambientStrength = 0.1;
float diffuseStrength = 0.8;
float specularStrength = 0.1;
uniform vec3 viewPos;
uniform float u_time;
uniform sampler2DArray textureArray;
void main(){
vec3 vColor = vec3(texture(textureArray, vTexCoord));
// Load the texture
// anti-gamma-correction of the texture. Without this it would be gamma corrected twice!
vec3 vColor = texture(textureArray, TexCoord).rgb;
// offset the normal a tiny bit, so that the color of faces opposing lightDir is not completely
// flat
vec3 normal = normalize(vNormal);
vec3 normal = normalize(Normal);
// Blinn-Phong lighting
/* Start of Blinn-Phong lighting */
// Ambient
vec3 ambient = lightColor*vColor;

80
shaders/shader-texture.gs Normal file
View File

@ -0,0 +1,80 @@
#version 330 core
layout (points) in;
layout (triangle_strip, max_vertices = 4) out;
in VS_OUT{
vec3 Extents;
vec3 Normal;
float BlockType;
} gs_in[];
out vec3 TexCoord;
out vec3 Normal;
out vec3 FragPos;
uniform mat4 view;
uniform mat4 projection;
void main(){
Normal = gs_in[0].Normal;
TexCoord = vec3(0.0, 0.0, gs_in[0].BlockType);
gl_Position = gl_in[0].gl_Position;
FragPos = vec3(gl_Position);
gl_Position = projection * view * gl_Position;
EmitVertex();
if(gs_in[0].Extents.x == 0){
TexCoord = vec3(0.0, gs_in[0].Extents.z, gs_in[0].BlockType);
gl_Position = gl_in[0].gl_Position + vec4(0.0, 0.0, gs_in[0].Extents.z, 0.0);
FragPos = vec3(gl_Position);
gl_Position = projection * view * gl_Position;
EmitVertex();
TexCoord = vec3(gs_in[0].Extents.y, 0.0, gs_in[0].BlockType);
gl_Position = gl_in[0].gl_Position + vec4(0.0, gs_in[0].Extents.y, 0.0, 0.0);
FragPos = vec3(gl_Position);
gl_Position = projection * view * gl_Position;
EmitVertex();
TexCoord = vec3(gs_in[0].Extents.y, gs_in[0].Extents.z, gs_in[0].BlockType);
}
else if(gs_in[0].Extents.y == 0){
TexCoord = vec3(0.0, gs_in[0].Extents.z, gs_in[0].BlockType);
gl_Position = gl_in[0].gl_Position + vec4(0.0, 0.0, gs_in[0].Extents.z, 0.0);
FragPos = vec3(gl_Position);
gl_Position = projection * view * gl_Position;
EmitVertex();
TexCoord = vec3(gs_in[0].Extents.x, 0.0, gs_in[0].BlockType);
gl_Position = gl_in[0].gl_Position + vec4(gs_in[0].Extents.x, 0.0, 0.0, 0.0);
FragPos = vec3(gl_Position);
gl_Position = projection * view * gl_Position;
EmitVertex();
TexCoord = vec3(gs_in[0].Extents.x, gs_in[0].Extents.z, gs_in[0].BlockType);
}
else{
TexCoord = vec3(gs_in[0].Extents.x, 0.0, gs_in[0].BlockType);
gl_Position = gl_in[0].gl_Position + vec4(gs_in[0].Extents.x, 0.0, 0.0, 0.0);
FragPos = vec3(gl_Position);
gl_Position = projection * view * gl_Position;
EmitVertex();
TexCoord = vec3(0.0, gs_in[0].Extents.y, gs_in[0].BlockType);
gl_Position = gl_in[0].gl_Position + vec4(0.0, gs_in[0].Extents.y, 0.0, 0.0);
FragPos = vec3(gl_Position);
gl_Position = projection * view * gl_Position;
EmitVertex();
TexCoord = vec3(gs_in[0].Extents.x, gs_in[0].Extents.y, gs_in[0].BlockType);
}
gl_Position = gl_in[0].gl_Position + vec4(gs_in[0].Extents, 0.0);
FragPos = vec3(gl_Position);
gl_Position = projection * view * gl_Position;
EmitVertex();
EndPrimitive();
}

View File

@ -1,22 +1,27 @@
#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aNormal;
layout (location = 2) in vec3 aTexCoord;
layout (location = 1) in vec3 aExtents;
layout (location = 2) in vec2 aInfo;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
out vec3 vNormal;
out vec3 vTexCoord;
out vec3 FragPos;
out VS_OUT {
vec3 Extents;
vec3 Normal;
float BlockType;
} vs_out;
void main()
{
vTexCoord = aTexCoord;
vNormal = mat3(transpose(inverse(model))) * aNormal;
//vNormal = mat3(transpose(inverse(model))) * aNormal;
vs_out.Extents = aExtents;
vs_out.BlockType = aInfo.y;
FragPos = vec3(model*vec4(aPos, 1.0));
gl_Position = projection * view * model * vec4(aPos, 1.0);
if(aExtents.x == 0) vs_out.Normal = vec3(1.0 - 2*aInfo.x, 0.0, 0.0);
else if(aExtents.y == 0) vs_out.Normal = vec3(0.0, 1.0 - 2*aInfo.x, 0.0);
else vs_out.Normal = vec3(0.0, 0.0, 1.0 - 2*aInfo.x);
vs_out.Normal = mat3(transpose(inverse(model))) * vs_out.Normal;
gl_Position = model * vec4(aPos, 1.0);
}