Geometry Shader step

master
Nicole Collings 2020-06-05 18:32:49 -07:00
parent e51de627a2
commit 431def2032
2 changed files with 65 additions and 77 deletions

View File

@ -5,12 +5,7 @@
layout (triangles) in;
layout (triangle_strip, max_vertices = 3) out;
struct SHADER_MOD {
float type;
vec3 values;
};
struct VS_OUT {
in VS_OUT {
vec3 pos;
vec3 normal;
@ -19,10 +14,9 @@ struct VS_OUT {
vec3 blend;
vec3 light;
SHADER_MOD mod;
};
in VS_OUT gs_in[3];
float modType;
vec3 modValues;
} gs_in[3];
out vec3 fragPos;
out vec3 normal;
@ -59,65 +53,62 @@ vec4 rotateZ(vec4 vertex, vec4 offset, float radians) {
return vec4(m * vertex.xy, vertex.zw).xyzw + offset;
}
void processVertex(VS_OUT v) {
vec4 pos = vec4(v.pos, 1);
vec4 nml = vec4(v.normal, 1);
// switch (int(v.mod.type)) {
// default: break;
// case 1: { // Rotate X
// vec4 origin = vec4(round(unpackFloat(v.mod.values.x) * 8 + 8) + 0.5, 1);
// pos = rotateX(pos, origin, time * TAU * v.mod.values.y);
// nml = rotateX(nml, vec4(0), time * TAU * v.mod.values.y);
// break;
// }
// case 2: { // Rotate Y
// vec4 origin = vec4(round(unpackFloat(v.mod.values.x) * 8 + 8) + 0.5, 1);
// pos = rotateY(pos, origin, time * TAU * v.mod.values.y);
// nml = rotateY(nml, vec4(0), time * TAU * v.mod.values.y);
// break;
// }
// case 3: { // Rotate Z
// vec4 origin = vec4(round(unpackFloat(v.mod.values.x) * 8 + 8) + 0.5, 1);
// pos = rotateZ(pos, origin, time * TAU * v.mod.values.y);
// nml = rotateZ(nml, vec4(0), time * TAU * v.mod.values.y);
// break;
// }
// case 4: { //Sway Grounded
// vec4 origin = vec4(round(unpackFloat(v.mod.values.x) * 8 + 8), 1);
// vec3 bsp = vec3(pos - origin);
// vec3 worldPos = (model * pos).xyz;
// if (bsp.x*bsp.y*bsp.z != 0 && bsp.x*bsp.y*bsp.z != 1) {
// vec3 sway = (texture(swayTex, worldPos.xz * (worldPos.y / 16.f) / 16.f).xyz - .5f) * vec3(v.mod.values.y, v.mod.values.y / 2, v.mod.values.y);
// pos += vec4(sway, 0);
// }
// break;
// }
// case 5: { //Sway Full Block
// vec3 worldPos = (model * pos).xyz;
// vec3 sway = (texture(swayTex, worldPos.xz * (worldPos.y / 16.f) / 16.f).xyz - .5f) * vec3(v.mod.values.y, v.mod.values.y / 2, v.mod.values.y);
// pos += vec4(sway, 0);
// break;
// }
// }
vec4 worldPos = model * pos;
// worldPos.y -= pow(length(view * worldPos * 0.025) - 0, 2);
// worldPos.y += sin(time + (worldPos.x + worldPos.z) / 10) * clamp(length(view * worldPos * 0.1) - 1, 0, 2.5);
gl_Position = projection * view * worldPos;
fragPos = (view * worldPos).xyz;
normal = nml.xyz;
// Passthrough
blendMaskCoords = v.blendMaskCoords;
texCoords = v.texCoords;
blend = v.blend;
light = v.light;
EmitVertex();
}
void main() {
for (int i = 0; i < 3; i++) processVertex(gs_in[i]);
for (int i = 0; i < 3; i++) {
vec4 pos = vec4(gs_in[i].pos, 1);
vec4 nml = vec4(gs_in[i].normal, 1);
switch (int(gs_in[i].modType)) {
default: break;
case 1: { // Rotate X
vec4 origin = vec4(round(unpackFloat(gs_in[i].modValues.x) * 8 + 8) + 0.5, 1);
pos = rotateX(pos, origin, time * TAU * gs_in[i].modValues.y);
nml = rotateX(nml, vec4(0), time * TAU * gs_in[i].modValues.y);
break;
}
case 2: { // Rotate Y
vec4 origin = vec4(round(unpackFloat(gs_in[i].modValues.x) * 8 + 8) + 0.5, 1);
pos = rotateY(pos, origin, time * TAU * gs_in[i].modValues.y);
nml = rotateY(nml, vec4(0), time * TAU * gs_in[i].modValues.y);
break;
}
case 3: { // Rotate Z
vec4 origin = vec4(round(unpackFloat(gs_in[i].modValues.x) * 8 + 8) + 0.5, 1);
pos = rotateZ(pos, origin, time * TAU * gs_in[i].modValues.y);
nml = rotateZ(nml, vec4(0), time * TAU * gs_in[i].modValues.y);
break;
}
case 4: { //Sway Grounded
vec4 origin = vec4(round(unpackFloat(gs_in[i].modValues.x) * 8 + 8), 1);
vec3 bsp = vec3(pos - origin);
vec3 worldPos = (model * pos).xyz;
if (bsp.x*bsp.y*bsp.z != 0 && bsp.x*bsp.y*bsp.z != 1) {
vec3 sway = (texture(swayTex, worldPos.xz * (worldPos.y / 16.f) / 16.f).xyz - .5f) * vec3(gs_in[i].modValues.y, gs_in[i].modValues.y / 2, gs_in[i].modValues.y);
pos += vec4(sway, 0);
}
break;
}
case 5: { //Sway Full Block
vec3 worldPos = (model * pos).xyz;
vec3 sway = (texture(swayTex, worldPos.xz * (worldPos.y / 16.f) / 16.f).xyz - .5f) * vec3(gs_in[i].modValues.y, gs_in[i].modValues.y / 2, gs_in[i].modValues.y);
pos += vec4(sway, 0);
break;
}
}
vec4 worldPos = model * pos;
worldPos.y -= pow(length(view * worldPos * 0.025) - 0, 2);
gl_Position = projection * view * worldPos;
fragPos = (view * worldPos).xyz;
normal = nml.xyz;
// Passthrough
blendMaskCoords = gs_in[i].blendMaskCoords;
texCoords = gs_in[i].texCoords;
blend = gs_in[i].blend;
light = gs_in[i].light;
EmitVertex();
}
}

View File

@ -14,11 +14,6 @@ layout (location = 5) in vec4 aLight;
layout (location = 6) in float aShaderMod;
layout (location = 7) in vec3 aModValues;
struct SHADER_MOD {
float type;
vec3 values;
};
out VS_OUT {
vec3 pos;
vec3 normal;
@ -28,7 +23,8 @@ out VS_OUT {
vec3 blend;
vec3 light;
SHADER_MOD mod;
float modType;
vec3 modValues;
} vs_out;
vec3 unpackFloat(float src) { return vec3(fract(src) * 2.0f - 1.0f, fract(src * 256.f) * 2.0f - 1.0f, fract(src * 65536.f) * 2.0f - 1.0f); }
@ -48,5 +44,6 @@ void main() {
vs_out.blend = aBlend;
vs_out.light = light;
vs_out.mod = SHADER_MOD(aShaderMod, aModValues);
vs_out.modType = aShaderMod;
vs_out.modValues = aModValues;
}