small changes to fix the lighting (+ added logo for later.)

This commit is contained in:
Anemunt
2025-12-10 17:59:57 -05:00
parent cdb781262f
commit d35d000dd7
4 changed files with 176 additions and 13 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 451 KiB

View File

@@ -21,7 +21,7 @@ uniform float specularStrength = 0.5;
uniform float shininess = 32.0;
const int MAX_LIGHTS = 10;
uniform int lightCount = 0; // up to MAX_LIGHTS
// type: 0 dir, 1 point, 2 spot
// type: 0 dir, 1 point, 2 spot, 3 area (rect)
uniform int lightTypeArr[MAX_LIGHTS];
uniform vec3 lightDirArr[MAX_LIGHTS];
uniform vec3 lightPosArr[MAX_LIGHTS];
@@ -30,6 +30,7 @@ uniform float lightIntensityArr[MAX_LIGHTS];
uniform float lightRangeArr[MAX_LIGHTS];
uniform float lightInnerCosArr[MAX_LIGHTS];
uniform float lightOuterCosArr[MAX_LIGHTS];
uniform vec2 lightAreaSizeArr[MAX_LIGHTS];
// Single directional light controlled by hierarchy (fallback if none set)
uniform vec3 lightDir = normalize(vec3(0.3, 1.0, 0.5));
@@ -69,12 +70,59 @@ void main()
int count = min(lightCount, MAX_LIGHTS);
for (int i = 0; i < count; ++i) {
int ltype = lightTypeArr[i];
vec3 ldir = (ltype == 0) ? -normalize(lightDirArr[i]) : lightPosArr[i] - FragPos;
float dist = length(ldir);
vec3 lDirN = normalize(ldir);
float intensity = lightIntensityArr[i];
if (intensity <= 0.0) continue;
vec3 lDirN;
float attenuation = 1.0;
if (ltype != 0) {
if (ltype == 0) {
lDirN = -normalize(lightDirArr[i]);
} else if (ltype == 3) { // area light approximate
vec3 n = normalize(lightDirArr[i]);
vec3 up = abs(n.y) > 0.9 ? vec3(1.0, 0.0, 0.0) : vec3(0.0, 1.0, 0.0);
vec3 tangent = normalize(cross(up, n));
vec3 bitangent = cross(n, tangent);
vec3 center = lightPosArr[i];
vec3 rel = FragPos - center;
float distPlane = dot(rel, n);
vec3 onPlane = FragPos - distPlane * n;
vec2 halfSize = lightAreaSizeArr[i] * 0.5;
vec2 local;
local.x = dot(onPlane - center, tangent);
local.y = dot(onPlane - center, bitangent);
vec2 clamped = clamp(local, -halfSize, halfSize);
vec3 closest = center + tangent * clamped.x + bitangent * clamped.y;
vec3 lvec = closest - FragPos;
float dist = length(lvec);
if (dist < 1e-4) continue;
lDirN = normalize(lvec);
float range = lightRangeArr[i];
if (range > 0.0 && dist > range) continue;
if (range > 0.0) {
float falloff = clamp(1.0 - (dist / range), 0.0, 1.0);
attenuation = falloff * falloff;
}
// Lambert against area normal for softer look
float nl = max(dot(norm, lDirN), 0.0);
float facing = max(dot(n, -lDirN), 0.0);
attenuation *= facing;
vec3 diffuse = nl * lightColorArr[i] * intensity;
vec3 halfwayDir = normalize(lDirN + viewDir);
float spec = pow(max(dot(norm, halfwayDir), 0.0), shininess);
vec3 specular = specularStrength * spec * lightColorArr[i] * intensity;
lighting += attenuation * (diffuse + specular) * baseColor;
continue;
} else {
vec3 ldir = lightPosArr[i] - FragPos;
float dist = length(ldir);
lDirN = normalize(ldir);
float range = lightRangeArr[i];
if (range > 0.0 && dist > range) continue;
if (range > 0.0) {
@@ -83,9 +131,6 @@ void main()
}
}
float intensity = lightIntensityArr[i];
if (intensity <= 0.0) continue;
float diff = max(dot(norm, lDirN), 0.0);
vec3 diffuse = diff * lightColorArr[i] * intensity;