Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
float3 SampleSpecularBRDF(BSDFData bsdfData, float2 sample, float3 viewWS)
float3 SampleSpecularBRDF(BSDFData bsdfData, float2 theSample, float3 viewWS)
{
float roughness = PerceptualRoughnessToRoughness(bsdfData.perceptualRoughness);
float3x3 localToWorld = GetLocalFrame(bsdfData.normalWS);

float NdotL, NdotH, VdotH;
float3 sampleDir;
SampleGGXDir(sample, viewWS, localToWorld, roughness, sampleDir, NdotL, NdotH, VdotH);
SampleGGXDir(theSample, viewWS, localToWorld, roughness, sampleDir, NdotL, NdotH, VdotH);
return sampleDir;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
float3 SampleSpecularBRDF(BSDFData bsdfData, float2 sample, float3 viewWS)
float3 SampleSpecularBRDF(BSDFData bsdfData, float2 theSample, float3 viewWS)
{
float roughness = PerceptualRoughnessToRoughness(bsdfData.perceptualRoughness);
float3x3 localToWorld = GetLocalFrame(bsdfData.normalWS);
float NdotL, NdotH, VdotH;
float3 sampleDir;
SampleGGXDir(sample, viewWS, localToWorld, roughness, sampleDir, NdotL, NdotH, VdotH);
SampleGGXDir(theSample, viewWS, localToWorld, roughness, sampleDir, NdotL, NdotH, VdotH);
return sampleDir;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
float3 SampleSpecularBRDF(BSDFData bsdfData, float2 sample, float3 viewWS)
float3 SampleSpecularBRDF(BSDFData bsdfData, float2 theSample, float3 viewWS)
{
float roughness = PerceptualRoughnessToRoughness(bsdfData.perceptualRoughness);
float3x3 localToWorld;
Expand All @@ -12,7 +12,7 @@ float3 SampleSpecularBRDF(BSDFData bsdfData, float2 sample, float3 viewWS)
}
float NdotL, NdotH, VdotH;
float3 sampleDir;
SampleGGXDir(sample, viewWS, localToWorld, roughness, sampleDir, NdotL, NdotH, VdotH);
SampleGGXDir(theSample, viewWS, localToWorld, roughness, sampleDir, NdotL, NdotH, VdotH);
return sampleDir;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
float3 SampleSpecularBRDF(BSDFData bsdfData, float2 sample, float3 viewWS)
float3 SampleSpecularBRDF(BSDFData bsdfData, float2 theSample, float3 viewWS)
{
float roughness = PerceptualRoughnessToRoughness(bsdfData.perceptualRoughness);
float3x3 localToWorld = GetLocalFrame(bsdfData.normalWS);

float NdotL, NdotH, VdotH;
float3 sampleDir;
SampleGGXDir(sample, viewWS, localToWorld, roughness, sampleDir, NdotL, NdotH, VdotH);
SampleGGXDir(theSample, viewWS, localToWorld, roughness, sampleDir, NdotL, NdotH, VdotH);
return sampleDir;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void ProcessBSDFData(PathIntersection pathIntersection, BuiltinData builtinData,
#endif
}

bool CreateMaterialData(PathIntersection pathIntersection, BuiltinData builtinData, BSDFData bsdfData, inout float3 shadingPosition, inout float sample, out MaterialData mtlData)
bool CreateMaterialData(PathIntersection pathIntersection, BuiltinData builtinData, BSDFData bsdfData, inout float3 shadingPosition, inout float theSample, out MaterialData mtlData)
{
// Alter values in the material's bsdfData struct, to better suit path tracing
mtlData.bsdfData = bsdfData;
Expand Down Expand Up @@ -95,7 +95,7 @@ bool CreateMaterialData(PathIntersection pathIntersection, BuiltinData builtinDa
#ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING
float subsurfaceWeight = mtlData.bsdfWeight[0] * mtlData.bsdfData.subsurfaceMask * (1.0 - pathIntersection.maxRoughness);

mtlData.isSubsurface = sample < subsurfaceWeight;
mtlData.isSubsurface = theSample < subsurfaceWeight;
if (mtlData.isSubsurface)
{
// We do a full, ray-traced subsurface scattering computation here:
Expand All @@ -121,11 +121,11 @@ bool CreateMaterialData(PathIntersection pathIntersection, BuiltinData builtinDa
mtlData.bsdfWeight[0] = max(mtlData.bsdfWeight[0] - subsurfaceWeight, BSDF_WEIGHT_EPSILON);
mtlData.bsdfWeight /= mtlData.subsurfaceWeightFactor;

sample -= subsurfaceWeight;
theSample -= subsurfaceWeight;
}

// Rescale the sample we used for the SSS selection test
sample /= mtlData.subsurfaceWeightFactor;
theSample /= mtlData.subsurfaceWeightFactor;
#endif

return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
float3 SampleSpecularBRDF(BSDFData bsdfData, float2 sample, float3 viewWS)
float3 SampleSpecularBRDF(BSDFData bsdfData, float2 theSample, float3 viewWS)
{
float roughness = PerceptualRoughnessToRoughness(bsdfData.perceptualRoughness);
float3x3 localToWorld;
Expand All @@ -12,7 +12,7 @@ float3 SampleSpecularBRDF(BSDFData bsdfData, float2 sample, float3 viewWS)
}
float NdotL, NdotH, VdotH;
float3 sampleDir;
SampleGGXDir(sample, viewWS, localToWorld, roughness, sampleDir, NdotL, NdotH, VdotH);
SampleGGXDir(theSample, viewWS, localToWorld, roughness, sampleDir, NdotL, NdotH, VdotH);
return sampleDir;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
float3 SampleSpecularBRDF(BSDFData bsdfData, float2 sample, float3 viewWS)
float3 SampleSpecularBRDF(BSDFData bsdfData, float2 theSample, float3 viewWS)
{
float roughness = bsdfData.roughnessAT;
float3x3 localToWorld;
Expand All @@ -12,7 +12,7 @@ float3 SampleSpecularBRDF(BSDFData bsdfData, float2 sample, float3 viewWS)
}
float NdotL, NdotH, VdotH;
float3 sampleDir;
SampleGGXDir(sample, viewWS, localToWorld, roughness, sampleDir, NdotL, NdotH, VdotH);
SampleGGXDir(theSample, viewWS, localToWorld, roughness, sampleDir, NdotL, NdotH, VdotH);
return sampleDir;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,23 +224,23 @@ float GetDistantLightWeight(LightList list)
return list.distantWeight / list.distantCount;
}

bool PickLocalLights(LightList list, inout float sample)
bool PickLocalLights(LightList list, inout float theSample)
{
if (sample < list.localWeight)
if (theSample < list.localWeight)
{
// We pick local lighting
sample /= list.localWeight;
theSample /= list.localWeight;
return true;
}

// Otherwise, distant lighting
sample = (sample - list.localWeight) / list.distantWeight;
theSample = (theSample - list.localWeight) / list.distantWeight;
return false;
}

bool PickDistantLights(LightList list, inout float sample)
bool PickDistantLights(LightList list, inout float theSample)
{
return !PickLocalLights(list, sample);
return !PickLocalLights(list, theSample);
}

float3 GetPunctualEmission(LightData lightData, float3 outgoingDir, float dist)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ float ComputeHeightFogMultiplier(float height)
return ComputeHeightFogMultiplier(height, _HeightFogBaseHeight, _HeightFogExponents);
}

bool SampleVolumeScatteringPosition(inout float sample, inout float t, inout float pdf, out bool sampleLocalLights)
bool SampleVolumeScatteringPosition(inout float theSample, inout float t, inout float pdf, out bool sampleLocalLights)
{
sampleLocalLights = false;

Expand All @@ -28,23 +28,23 @@ bool SampleVolumeScatteringPosition(inout float sample, inout float t, inout flo
if (localWeight < 0.0)
return false;

sampleLocalLights = sample < localWeight;
sampleLocalLights = theSample < localWeight;
if (sampleLocalLights)
{
tMax = min(tMax, tFog);
if (tMin >= tMax)
return false;

sample /= localWeight;
theSample /= localWeight;
pdfVol *= localWeight;
}
else
{
tMin = 0.0;
tMax = tFog;

sample -= localWeight;
sample /= 1.0 - localWeight;
theSample -= localWeight;
theSample /= 1.0 - localWeight;
pdfVol *= 1.0 - localWeight;
}
#else
Expand All @@ -57,11 +57,11 @@ bool SampleVolumeScatteringPosition(inout float sample, inout float t, inout flo
const float transmittanceTMax = max(exp(-tMax * sigmaT), 0.01);
const float transmittanceThreshold = t < FLT_MAX ? 1.0 - min(0.5, transmittanceTMax) : 1.0;

if (sample >= transmittanceThreshold)
if (theSample >= transmittanceThreshold)
{
// Re-scale the sample
sample -= transmittanceThreshold;
sample /= 1.0 - transmittanceThreshold;
theSample -= transmittanceThreshold;
theSample /= 1.0 - transmittanceThreshold;

// Adjust the pdf
pdf *= 1.0 - transmittanceThreshold;
Expand All @@ -70,7 +70,7 @@ bool SampleVolumeScatteringPosition(inout float sample, inout float t, inout flo
}

// Re-scale the sample
sample /= transmittanceThreshold;
theSample /= transmittanceThreshold;

// Adjust the pdf
pdf *= pdfVol * transmittanceThreshold;
Expand All @@ -79,15 +79,15 @@ bool SampleVolumeScatteringPosition(inout float sample, inout float t, inout flo
{
// Linear sampling
float deltaT = tMax - tMin;
t = tMin + sample * deltaT;
t = tMin + theSample * deltaT;

// Adjust the pdf
pdf /= deltaT;
}
else
{
// Exponential sampling
float transmittance = transmittanceTMax + sample * (1.0 - transmittanceTMax);
float transmittance = transmittanceTMax + theSample * (1.0 - transmittanceTMax);
t = -log(transmittance) / sigmaT;

// Adjust the pdf
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ void RaytracingIndirectDiffuseFullRes(uint3 dispatchThreadId : SV_DispatchThread
DecodeFromNormalBuffer(currentCoord, normalData);

// Generate the new sample (following values of the sequence)
float2 sample;
sample.x = GetBNDSequenceSample(currentCoord, _RaytracingFrameIndex, 0);
sample.y = GetBNDSequenceSample(currentCoord, _RaytracingFrameIndex, 1);
float2 theSample;
theSample.x = GetBNDSequenceSample(currentCoord, _RaytracingFrameIndex, 0);
theSample.y = GetBNDSequenceSample(currentCoord, _RaytracingFrameIndex, 1);

// Importance sample with a cosine lobe
float3 sampleDir = SampleHemisphereCosine(sample.x, sample.y, normalData.normalWS);
float3 sampleDir = SampleHemisphereCosine(theSample.x, theSample.y, normalData.normalWS);

// PDF is the cosine
float samplePDF = dot(sampleDir, normalData.normalWS);
Expand Down Expand Up @@ -208,8 +208,8 @@ void INDIRECT_DIFFUSE_INTEGRATION_UPSCALE(uint3 dispatchThreadId : SV_DispatchTh
if(sampleDepth == UNITY_RAW_FAR_CLIP_VALUE) continue;

// Compute the target pixel that it will impact
float sample = _BlueNoiseTexture[int3(relativeHRShift, noiseIndex)].x;
int index = clamp(floor(sample * 4.0f), 0, 3);
float theSample = _BlueNoiseTexture[int3(relativeHRShift, noiseIndex)].x;
int index = clamp(floor(theSample * 4.0f), 0, 3);

if (index != localIndex) continue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ void RayGenIntegration()
int globalSampleIndex = _RaytracingFrameIndex * _RaytracingNumSamples + sampleIndex;

// Generate the new sample (follwing values of the sequence)
float2 sample;
sample.x = GetBNDSequenceSample(currentCoord, globalSampleIndex, 0);
sample.y = GetBNDSequenceSample(currentCoord, globalSampleIndex, 1);
float2 theSample;
theSample.x = GetBNDSequenceSample(currentCoord, globalSampleIndex, 0);
theSample.y = GetBNDSequenceSample(currentCoord, globalSampleIndex, 1);

// Importance sample with a cosine lobe
float3 sampleDir = SampleHemisphereCosine(sample.x, sample.y, normalData.normalWS);
float3 sampleDir = SampleHemisphereCosine(theSample.x, theSample.y, normalData.normalWS);

// Create the ray descriptor for this pixel
RayDesc rayDescriptor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ GGXSample GenerateGGXSampleDirection(uint2 currentCoord, float3 normalWS, float3

// Generate the new sample (follwing values of the sequence)
int initialFrameIndex = frameIndex;
float2 sample;
sample.x = GetBNDSequenceSample(currentCoord, initialFrameIndex, 0);
sample.y = GetBNDSequenceSample(currentCoord, initialFrameIndex, 1);
float2 theSample;
theSample.x = GetBNDSequenceSample(currentCoord, initialFrameIndex, 0);
theSample.y = GetBNDSequenceSample(currentCoord, initialFrameIndex, 1);

// Importance sample the direction
float3 sampleDir = float3(0.0, 0.0, 0.0);
float NdotL, NdotH, VdotH;
SampleGGXDir(sample, viewWS, localToWorld, roughness, sampleDir, NdotL, NdotH, VdotH);
SampleGGXDir(theSample, viewWS, localToWorld, roughness, sampleDir, NdotL, NdotH, VdotH);

// If this direction is under the surface, let's generate a new one that won't be.
// We allow ourselves 8 as the total of number of tries.
Expand All @@ -70,9 +70,9 @@ GGXSample GenerateGGXSampleDirection(uint2 currentCoord, float3 normalWS, float3
if (dot(sampleDir, normalWS) >= 0.00f)
break;

sample.x = GetBNDSequenceSample(currentCoord, initialFrameIndex + i, 0);
sample.y = GetBNDSequenceSample(currentCoord, initialFrameIndex + i, 1);
SampleGGXDir(sample, viewWS, localToWorld, roughness, sampleDir, NdotL, NdotH, VdotH);
theSample.x = GetBNDSequenceSample(currentCoord, initialFrameIndex + i, 0);
theSample.y = GetBNDSequenceSample(currentCoord, initialFrameIndex + i, 1);
SampleGGXDir(theSample, viewWS, localToWorld, roughness, sampleDir, NdotL, NdotH, VdotH);
}

// Build the sample and return it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ void RayGenIntegration()
int globalSampleIndex = _RaytracingFrameIndex * realSampleCount + sampleIndex;

// Generate the new sample (follwing values of the sequence)
float2 sample;
sample.x = GetBNDSequenceSample(currentCoord, globalSampleIndex, 0);
sample.y = GetBNDSequenceSample(currentCoord, globalSampleIndex, 1);
float2 theSample;
theSample.x = GetBNDSequenceSample(currentCoord, globalSampleIndex, 0);
theSample.y = GetBNDSequenceSample(currentCoord, globalSampleIndex, 1);

// Importance sample the direction using GGX
float3 sampleDir = float3(0.0, 0.0, 0.0);
float NdotL, NdotH, VdotH;
SampleGGXDir(sample, viewWS, localToWorld, roughness, sampleDir, NdotL, NdotH, VdotH);
SampleGGXDir(theSample, viewWS, localToWorld, roughness, sampleDir, NdotL, NdotH, VdotH);

// If the sample is under the surface
if (dot(sampleDir, normalData.normalWS) <= 0.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ bool GenerateMISSample(inout MISSamplingInput misInput, SphQuad squad, float3 vi
return validity;
}

void GenerateLightSample(float3 positionWS, float2 sample, SphQuad squad, float3 viewVector, out LightSamplingOutput lightSamplingOutput)
void GenerateLightSample(float3 positionWS, float2 theSample, SphQuad squad, float3 viewVector, out LightSamplingOutput lightSamplingOutput)
{
lightSamplingOutput.pos = SphQuadSample(squad, sample.x, sample.y);
lightSamplingOutput.pos = SphQuadSample(squad, theSample.x, theSample.y);
lightSamplingOutput.dir = normalize(lightSamplingOutput.pos - positionWS);
lightSamplingOutput.lightPDF = 1.0f / squad.S;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ void ClosestHitMain(inout RayIntersection rayIntersection : SV_RayPayload, Attri
if (rayIntersection.remainingDepth < _RaytracingMaxRecursion)
{
// Generate the new sample (follwing values of the sequence)
float2 sample = float2(0.0, 0.0);
sample.x = GetBNDSequenceSample(rayIntersection.pixelCoord, rayIntersection.sampleIndex, rayIntersection.remainingDepth * 2);
sample.y = GetBNDSequenceSample(rayIntersection.pixelCoord, rayIntersection.sampleIndex, rayIntersection.remainingDepth * 2 + 1);
float2 theSample = float2(0.0, 0.0);
theSample.x = GetBNDSequenceSample(rayIntersection.pixelCoord, rayIntersection.sampleIndex, rayIntersection.remainingDepth * 2);
theSample.y = GetBNDSequenceSample(rayIntersection.pixelCoord, rayIntersection.sampleIndex, rayIntersection.remainingDepth * 2 + 1);

float3 sampleDir;
if (_RayTracingDiffuseLightingOnly)
{
sampleDir = SampleHemisphereCosine(sample.x, sample.y, bsdfData.normalWS);
sampleDir = SampleHemisphereCosine(theSample.x, theSample.y, bsdfData.normalWS);
}
else
{
sampleDir = SampleSpecularBRDF(bsdfData, sample, viewWS);
sampleDir = SampleSpecularBRDF(bsdfData, theSample, viewWS);
}

// Create the ray descriptor for this pixel
Expand Down