Skip to content

Commit

Permalink
feat: support roughness
Browse files Browse the repository at this point in the history
  • Loading branch information
Latios96 committed Oct 22, 2024
1 parent 5dd73ec commit cbf8d97
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 2 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
#usda 1.0
(
subLayers = [
@./../_base_scene/material_parameter_progression.usda@
]
)

over "world"
{
over "knob_0"
{
over "mtl"
{
over "MaterialUnderTest"
{
over "MaterialUnderTestPreviewSurface"
{
float inputs:metallic = 1
float inputs:roughness = 0
}
}
}
}

over "knob_1"
{
over "mtl"
{
over "MaterialUnderTest"
{
over "MaterialUnderTestPreviewSurface"
{
float inputs:metallic = 1
float inputs:roughness = 0.1
}
}
}
}
over "knob_2"
{
over "mtl"
{
over "MaterialUnderTest"
{
over "MaterialUnderTestPreviewSurface"
{
float inputs:metallic = 1
float inputs:roughness = 0.2
}
}
}
}
over "knob_3"
{
over "mtl"
{
over "MaterialUnderTest"
{
over "MaterialUnderTestPreviewSurface"
{
float inputs:metallic = 1
float inputs:roughness = 0.3
}
}
}
}
over "knob_4"
{
over "mtl"
{
over "MaterialUnderTest"
{
over "MaterialUnderTestPreviewSurface"
{
float inputs:metallic = 1
float inputs:roughness = 0.4
}
}
}
}
over "knob_5"
{
over "mtl"
{
over "MaterialUnderTest"
{
over "MaterialUnderTestPreviewSurface"
{
float inputs:metallic = 1
float inputs:roughness = 0.5
}
}
}
}
over "knob_6"
{
over "mtl"
{
over "MaterialUnderTest"
{
over "MaterialUnderTestPreviewSurface"
{
float inputs:metallic = 1
float inputs:roughness = 0.6
}
}
}
}
over "knob_7"
{
over "mtl"
{
over "MaterialUnderTest"
{
over "MaterialUnderTestPreviewSurface"
{
float inputs:metallic = 1
float inputs:roughness = 0.7
}
}
}
}
over "knob_8"
{
over "mtl"
{
over "MaterialUnderTest"
{
over "MaterialUnderTestPreviewSurface"
{
float inputs:metallic = 1
float inputs:roughness = 0.8
}
}
}
}
over "knob_9"
{
over "mtl"
{
over "MaterialUnderTest"
{
over "MaterialUnderTestPreviewSurface"
{
float inputs:metallic = 1
float inputs:roughness = 0.9
}
}
}
}
over "knob_10"
{
over "mtl"
{
over "MaterialUnderTest"
{
over "MaterialUnderTestPreviewSurface"
{
float inputs:metallic = 1
float inputs:roughness = 1
}
}
}
}
}

3 changes: 3 additions & 0 deletions src/crayg/integrationTests/cato.json
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@
},
{
"name": "SimpleMetalMaterial"
},
{
"name": "RoughnessProgression"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,28 @@ float F_schlick(float ior, const Vector3f &view, const Vector3f &halfVector) {
return F_0 + (1.f - F_0) * oneMinus * oneMinus * oneMinus * oneMinus * oneMinus;
}

Vector3f roughReflect(const SurfaceInteraction &surfaceInteraction, float roughness) {
const Vector3f perfectReflection = surfaceInteraction.ray.direction.reflect(surfaceInteraction.normal);

if (roughness == 0) {
return perfectReflection;
}

const Vector3f randomDirOnHemisphere = Sampling::uniformSampleHemisphere();
auto orthonormalBasis = surfaceInteraction.getOrthonormalBasis();
const Vector3f roughReflection = orthonormalBasis.toLocalCoordinates(randomDirOnHemisphere);
return MathUtils::lerp(roughness * roughness, perfectReflection, roughReflection);
}

void UsdPreviewSurface::getLobes(const SurfaceInteraction &surfaceInteraction, Lobes &lobes) {
const Color evaluatedDiffuse = diffuseColor.evaluate(surfaceInteraction);
const float evaluatedMetallic = metallic.evaluate(surfaceInteraction);

if (evaluatedMetallic > 0.f) {
lobes.metallic.weight = Color::createGrey(evaluatedMetallic) * evaluatedDiffuse;
lobes.metallic.sampleDirection = surfaceInteraction.spawnReflectionRayFromSurface();
const float evaluatedRoughness = roughness.evaluate(surfaceInteraction);
lobes.metallic.sampleDirection =
surfaceInteraction.spawnRayFromSurface(roughReflect(surfaceInteraction, evaluatedRoughness));
}

if (evaluatedMetallic >= 1.f) {
Expand All @@ -61,7 +76,9 @@ void UsdPreviewSurface::getLobes(const SurfaceInteraction &surfaceInteraction, L

float reflectance = 0;
if (!lobes.specular.weight.isBlack()) {
lobes.specular.sampleDirection = surfaceInteraction.spawnReflectionRayFromSurface();
const float evaluatedRoughness = roughness.evaluate(surfaceInteraction);
lobes.specular.sampleDirection =
surfaceInteraction.spawnRayFromSurface(roughReflect(surfaceInteraction, evaluatedRoughness));
const float evaluatedIor = ior.evaluate(surfaceInteraction);
reflectance = F_schlick(evaluatedIor, surfaceInteraction.ray.direction, halfVector);
}
Expand Down

0 comments on commit cbf8d97

Please sign in to comment.