Skip to content

Commit

Permalink
Update RayTracingCommon.js
Browse files Browse the repository at this point in the history
  • Loading branch information
erichlof authored Mar 28, 2024
1 parent f25e932 commit 0764ff5
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions js/RayTracingCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,30 +86,30 @@ float tentFilter(float x) // input: x: a random float(0.0 to 1.0), output: a fil
return (x < 0.5) ? sqrt(x * 2.0) - 1.0 : 1.0 - sqrt(2.0 - (x * 2.0));
}
vec3 doAmbientLighting(vec3 rayColorMask, float ambientIntensity, Material surfaceMaterial)
vec3 doAmbientLighting(vec3 rayColorMask, float ambientIntensity, vec3 materialColor)
{
vec3 ambientColor = rayColorMask * surfaceMaterial.color;
vec3 ambientColor = rayColorMask * materialColor;
return ambientColor * ambientIntensity;
}
vec3 doDiffuseDirectLighting(vec3 rayColorMask, vec3 surfaceNormal, vec3 directionToLight, vec3 lightColor, Material surfaceMaterial, out float diffuseIntensity)
vec3 doDiffuseDirectLighting(vec3 rayColorMask, vec3 surfaceNormal, vec3 directionToLight, vec3 lightColor, vec3 materialColor, out float diffuseIntensity)
{
vec3 diffuseColor = rayColorMask * surfaceMaterial.color * lightColor;
vec3 diffuseColor = rayColorMask * materialColor * lightColor;
// next, do typical Lambertian diffuse lighting (NdotL)
diffuseIntensity = max(0.0, dot(surfaceNormal, directionToLight));
return diffuseColor * diffuseIntensity;
}
vec3 doBlinnPhongSpecularLighting(vec3 rayColorMask, vec3 surfaceNormal, vec3 halfwayVector, vec3 lightColor, Material surfaceMaterial, float diffuseIntensity)
vec3 doBlinnPhongSpecularLighting(vec3 rayColorMask, vec3 surfaceNormal, vec3 halfwayVector, vec3 lightColor, float materialRoughness, float diffuseIntensity)
{
// for dielectric materials (non-conductors), specular color is unaffected by surface color
// for metal materials (conductors) however, specular color gets tinted by the metal surface color
// therefore, in the metal case, 'rayColorMask' will get pre-tinted before it is passed into this function
vec3 specularColor = rayColorMask; // will either be white for dielectrics (usually vec3(1,1,1)), or tinted by metal color for metallics
specularColor *= clamp(lightColor, 0.0, 4.0);
float shininess = 1.0 - surfaceMaterial.roughness;
float shininessExponent = max(2000.0 * shininess * shininess * shininess, 1.0);
float specularIntensity = pow(max(0.0, dot(surfaceNormal, halfwayVector)), round(shininessExponent)); // this is a powered cosine with shininess as the exponent
float shininess = 1.0 - materialRoughness;
float shininessExponent = max(2000.0 * shininess * shininess * shininess, 5.0);
float specularIntensity = pow(max(0.0, dot(surfaceNormal, halfwayVector)), shininessExponent); // this is a powered cosine with shininess as the exponent
// makes specular highlights fade away as surface shininess and diffuseInstensity decrease
return specularColor * (specularIntensity * shininess * diffuseIntensity);
}
Expand Down

0 comments on commit 0764ff5

Please sign in to comment.