mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-16 16:12:35 +00:00
Work In Progress
This commit is contained in:
@@ -1,19 +1,15 @@
|
||||
# version 330 core
|
||||
|
||||
@include "light_struct"
|
||||
|
||||
layout(location = 0) out vec3 fragPosition;
|
||||
layout (location = 0) out vec4 fragPosition;
|
||||
layout (location = 1) out vec4 fragColor;
|
||||
layout (location = 2) out vec3 fragNormal;
|
||||
layout (location = 3) out vec3 fragUV;
|
||||
layout (location = 2) out vec4 fragNormal;
|
||||
layout (location = 3) out vec4 fragUV;
|
||||
|
||||
in vec3 outPosition;
|
||||
in vec3 outColor;
|
||||
in vec3 outNormal;
|
||||
in vec3 outUV;
|
||||
in float outTextureID;
|
||||
in Light outLights[MAX_LIGHTS];
|
||||
flat in int outTotalLights;
|
||||
in vec3 outFragPos;
|
||||
in vec3 outCameraPos;
|
||||
flat in int outHasTexture;
|
||||
@@ -21,88 +17,17 @@ flat in int outDisableLighting;
|
||||
|
||||
uniform sampler2D diffuse_texture;
|
||||
|
||||
// optimizing compilers are annoying at this stage of my understanding of GLSL
|
||||
vec4 lokiVar;
|
||||
|
||||
// https://learnopengl.com/Lighting/Multiple-lights
|
||||
vec3 calculatePointLight(Light light) {
|
||||
vec3 viewDir = normalize(outCameraPos - outFragPos);
|
||||
vec3 lightDir = normalize(light.position - outFragPos);
|
||||
float diff = max(dot(vec3(outNormal), lightDir), 0.0);
|
||||
vec3 reflectDir = reflect(-lightDir, vec3(outNormal));
|
||||
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 16.0);
|
||||
|
||||
float distance = length(light.position - outFragPos);
|
||||
float attenuation = 1.0 / (1.0 + 0.09 * distance +
|
||||
0.032 * (distance * distance));
|
||||
|
||||
vec3 ambient = light.ambient * outColor;
|
||||
vec3 diffuse = light.diffuse * outColor;
|
||||
vec3 specular = light.specular * spec * vec3(1.0, 1.0, 1.0);
|
||||
|
||||
ambient *= attenuation;
|
||||
diffuse *= attenuation;
|
||||
specular *= attenuation;
|
||||
|
||||
return (ambient + diffuse + specular);
|
||||
}
|
||||
|
||||
// https://learnopengl.com/Lighting/Basic-Lighting
|
||||
vec3 calculateBasicLight(Light light) {
|
||||
vec3 lightDir = normalize(light.position - outFragPos);
|
||||
|
||||
float ambientStrength = 0.25;
|
||||
vec3 ambient = ambientStrength * light.ambient;
|
||||
|
||||
float diff = max(dot(normalize(vec3(outNormal)), lightDir), 0.0);
|
||||
vec3 diffuse = diff * light.diffuse;
|
||||
|
||||
float specularStrength = 0.5;
|
||||
vec3 viewDir = normalize(outCameraPos - outFragPos);
|
||||
vec3 reflectDir = reflect(-lightDir, outNormal);
|
||||
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);
|
||||
vec3 specular = specularStrength * spec * light.specular;
|
||||
|
||||
return vec3(ambient + diffuse + specular);
|
||||
}
|
||||
|
||||
vec3 calculateLighting() {
|
||||
vec3 result = vec3(0.0, 0.0, 0.0);
|
||||
|
||||
for (int i = 0; i < min(outTotalLights, MAX_LIGHTS); i++) {
|
||||
if (int(outLights[i].type) == 0) {
|
||||
result += calculateBasicLight(outLights[i]);
|
||||
} else if (int(outLights[i].type) == 1) {
|
||||
result += calculateBasicLight(outLights[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void main() {
|
||||
lokiVar = vec4(outColor, 1.0) + vec4(outNormal, 1.0) + vec4(outUV, 1.0) + vec4(outTextureID, 1.0, 1.0, 1.0);
|
||||
lokiVar = normalize(lokiVar);
|
||||
|
||||
vec3 result;
|
||||
|
||||
if (outHasTexture == 0) {
|
||||
if (outDisableLighting == 1.0) {
|
||||
result = outColor + 0.25;
|
||||
} else {
|
||||
result = calculateLighting() * outColor;
|
||||
}
|
||||
|
||||
result = outColor;
|
||||
} else {
|
||||
if (outDisableLighting == 1.0) {
|
||||
result = texture(diffuse_texture, outUV.xy).xyz + 0.25;
|
||||
} else {
|
||||
result = calculateLighting() * texture(diffuse_texture, outUV.xy).xyz;
|
||||
}
|
||||
result = texture(diffuse_texture, outUV.xy).xyz;
|
||||
}
|
||||
|
||||
fragPosition = outPosition;
|
||||
fragPosition = vec4(outPosition, 1.0);
|
||||
fragColor = vec4(result, 1.0);
|
||||
fragNormal = outNormal;
|
||||
fragUV = outUV;
|
||||
fragNormal = vec4(outNormal, 1.0);
|
||||
fragUV = vec4(outUV, 1.0);
|
||||
}
|
||||
|
||||
17
shaders/fragment/lighting.glsl
Normal file
17
shaders/fragment/lighting.glsl
Normal file
@@ -0,0 +1,17 @@
|
||||
# version 330 core
|
||||
|
||||
layout (location = 4) out vec4 sceneColor;
|
||||
|
||||
flat in int outLightType;
|
||||
in vec3 outLightPosition;
|
||||
in vec3 outLightAmbient;
|
||||
in vec3 outLightDiffuse;
|
||||
in vec3 outLightSpecular;
|
||||
|
||||
in vec2 outTexCoords;
|
||||
|
||||
@include "light_struct"
|
||||
|
||||
void main() {
|
||||
sceneColor = vec4(1.0, 0.5, 0.25, 1.0);
|
||||
}
|
||||
@@ -39,8 +39,6 @@ void main() {
|
||||
outUV = inUV;
|
||||
outTextureID = inTextureID;
|
||||
outHasTexture = hasTexture;
|
||||
outLights = lights;
|
||||
outTotalLights = totalLights;
|
||||
outCameraPos = cameraPos;
|
||||
outDisableLighting = disableLighting;
|
||||
|
||||
|
||||
28
shaders/vertex/lighting.glsl
Normal file
28
shaders/vertex/lighting.glsl
Normal file
@@ -0,0 +1,28 @@
|
||||
#version 330 core
|
||||
layout (location = 0) in vec3 inPosition;
|
||||
layout (location = 1) in vec2 inTexCoords;
|
||||
|
||||
in int inLightType;
|
||||
in vec3 inLightPosition;
|
||||
in vec3 inLightAmbient;
|
||||
in vec3 inLightDiffuse;
|
||||
in vec3 inLightSpecular;
|
||||
|
||||
flat out int outLightType;
|
||||
out vec3 outLightPosition;
|
||||
out vec3 outLightAmbient;
|
||||
out vec3 outLightDiffuse;
|
||||
out vec3 outLightSpecular;
|
||||
|
||||
out vec2 outTexCoords;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(inPosition.x, inPosition.y, inPosition.z, 1.0);
|
||||
|
||||
outLightType = inLightType;
|
||||
outLightPosition = inLightPosition;
|
||||
outLightAmbient = inLightAmbient;
|
||||
outLightDiffuse = inLightDiffuse;
|
||||
outLightSpecular = inLightSpecular;
|
||||
outTexCoords = inTexCoords;
|
||||
}
|
||||
@@ -5,6 +5,6 @@ layout (location = 1) in vec2 inTexCoords;
|
||||
out vec2 outTexCoords;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(inPosition.x, inPosition.y, inPosition.z, 1.0);
|
||||
gl_Position = vec4(inPosition.x, inPosition.y, inPosition.z, 1.0);
|
||||
outTexCoords = inTexCoords;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user