Skip to content

Commit 14b9c7c

Browse files
Initial VDF support in hardware shading (#2809)
This changelist adds initial support for Volume Distribution Functions (VDFs) in hardware shader generation, giving the VDF type its own struct, and approximating volumetric light absorption for the transmissive term. The following specific changes are included: - Add a dedicated VDF struct to GLSL, MSL, and Slang, replacing the previous use of the BSDF struct as an alias for the VDF type. - Add a simple approximation of volumetric absorption to `mx_anisotropic_vdf`, computing throughput using Beer's law in the transmissive lighting term. - Fix `mx_layer_vdf` to multiply the surface response and throughput by the volume throughput, replacing the previous placeholder math.
1 parent 1e5ff1d commit 14b9c7c

5 files changed

Lines changed: 25 additions & 14 deletions

File tree

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#include "lib/mx_closure_type.glsl"
22

3-
void mx_anisotropic_vdf(ClosureData closureData, vec3 absorption, vec3 scattering, float anisotropy, inout BSDF bsdf)
3+
void mx_anisotropic_vdf(ClosureData closureData, vec3 absorption, vec3 scattering, float anisotropy, inout VDF vdf)
44
{
5-
// TODO: Add some approximation for volumetric light absorption.
5+
// TODO: Add support for scattering and anisotropy.
6+
if (closureData.closureType == CLOSURE_TYPE_TRANSMISSION)
7+
{
8+
vdf.response = vec3(0.0);
9+
vdf.throughput = exp(-absorption);
10+
}
611
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "lib/mx_closure_type.glsl"
22

3-
void mx_layer_vdf(ClosureData closureData, BSDF top, BSDF base, out BSDF result)
3+
void mx_layer_vdf(ClosureData closureData, BSDF top, VDF base, out BSDF result)
44
{
5-
result.response = top.response + base.response;
6-
result.throughput = top.throughput + base.throughput;
5+
result.response = top.response * base.throughput;
6+
result.throughput = top.throughput * base.throughput;
77
}

source/MaterialXGenGlsl/GlslSyntax.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,11 @@ GlslSyntax::GlslSyntax(TypeSystemPtr typeSystem) :
299299
Type::VDF,
300300
std::make_shared<AggregateTypeSyntax>(
301301
this,
302-
"BSDF",
303-
"BSDF(vec3(0.0),vec3(1.0))",
304-
EMPTY_STRING));
302+
"VDF",
303+
"VDF(vec3(0.0),vec3(1.0))",
304+
EMPTY_STRING,
305+
EMPTY_STRING,
306+
"struct VDF { vec3 response; vec3 throughput; };"));
305307

306308
registerTypeSyntax(
307309
Type::SURFACESHADER,

source/MaterialXGenMsl/MslSyntax.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,11 @@ MslSyntax::MslSyntax(TypeSystemPtr typeSystem) : Syntax(typeSystem)
280280
Type::VDF,
281281
std::make_shared<AggregateTypeSyntax>(
282282
this,
283-
"BSDF",
284-
"BSDF{float3(0.0),float3(1.0)}",
285-
EMPTY_STRING));
283+
"VDF",
284+
"VDF{float3(0.0),float3(1.0)}",
285+
EMPTY_STRING,
286+
EMPTY_STRING,
287+
"struct VDF { float3 response; float3 throughput; };"));
286288

287289
registerTypeSyntax(
288290
Type::SURFACESHADER,

source/MaterialXGenSlang/SlangSyntax.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,11 @@ SlangSyntax::SlangSyntax(TypeSystemPtr typeSystem) :
296296
Type::VDF,
297297
std::make_shared<SlangAggregateTypeSyntax>(
298298
this,
299-
"BSDF",
300-
"BSDF(float3(0.0),float3(1.0))",
301-
EMPTY_STRING));
299+
"VDF",
300+
"VDF(float3(0.0),float3(1.0))",
301+
EMPTY_STRING,
302+
EMPTY_STRING,
303+
"struct VDF { float3 response; float3 throughput; };"));
302304

303305
registerTypeSyntax(
304306
Type::SURFACESHADER,

0 commit comments

Comments
 (0)