Skip to content

Commit

Permalink
fix specular + add support for roughness
Browse files Browse the repository at this point in the history
  • Loading branch information
omicronrex committed Aug 27, 2024
1 parent 18c36ee commit ff9530b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.zig-cache/
zig-out/
test/
*.glb
*.gex
*.bat
Expand Down
12 changes: 7 additions & 5 deletions pixel.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,21 @@ float3 uEyePos;
return (saturate(dot(-normal, diffvec/len)) * atten) * color;
}

float4 doLighting(float4 color, float3 wpos, float3 normal, float4 ambient, float metal, float3 eyevector, float4 environment) {
float4 diffuse = ambient + (environment - ambient) * metal;
float4 doLighting(float4 color, float3 wpos, float3 normal, float4 ambient, float metal, float rough, float3 eyevector, float4 environment) {
float4 diffuse = ambient;
float4 specular = float4(0,0,0,0);

for (int i = 0; i < 8; i++) {
float3 dir = -normalize(uLightDirection[i].xyz);

diffuse += saturate(dot(normal,dir)) * uLightColor[i] * (1.0-metal);
specular += pow(max(dot(reflect(-dir,normal),eyevector), 0.0), 40.0) * uLightColor[i];
diffuse += saturate(dot(normal,dir)) * uLightColor[i];
specular += (1.0-0.9*rough) * pow(max(dot(reflect(dir,normal),eyevector), 0.0), 200.0/(1.0+rough*100.0)) * uLightColor[i];

//accumcol += doPointLight(wpos, normal, uLightPosRange[i], uLightColor[i]);
}

diffuse = lerp(diffuse,diffuse*lerp(environment,ambient,rough),metal);

return saturate(diffuse) * color + saturate(specular) * color.a;
}
//end game maker lighting
Expand Down Expand Up @@ -108,7 +110,7 @@ PS_OUTPUT main(PS_INPUT input) {

if (uOcclusionMap_enabled<0.5) occlusion=float4(1.0,1.0,1.0,1.0);

if (uLightingEnabled>0.5) color = doLighting(color, input.worldpos, finormal, uAmbientColor * occlusion, metal, eyevector, environment);
if (uLightingEnabled>0.5) color = doLighting(color, input.worldpos, finormal, uAmbientColor * occlusion, metal, rough, eyevector, environment);

if (uEmissiveMap_enabled>0.5) color = saturate(color+emissive);

Expand Down

0 comments on commit ff9530b

Please sign in to comment.