Hi
I’m experimenting with using the global distance field to do volumetric light shafts.
I know its expensive but wanted to give it a go. Turned out its not as bad as I though performance wise but there is one issue. Here’s my function going into a custom node. Looks okay in the viewport but goes black on play.
float3 curpos = CamPos;
float currentDistance = 0;
float currentLightDistance = 0;
float minDistance = minDist;
float3 lightVec = normalize(float3(1,1,0.12));
float3 lightPos;
float distanceToTravel = 0;
float distanceToTravelLight = 0;
float shadowMinDistance;
int i = 0;
float Accum = 0;
float T = 1.0;
while ( i < numSteps){
currentDistance = GetDistanceToNearestSurfaceGlobal(curpos);
distanceToTravel = max(minDistance , currentDistance );
if( (currentDistance < 0) ){
return float(1-T);
}
float unOccluded = 1;
int j = 0;
lightPos = curpos;
shadowMinDistance = minDistance;
while ( j < numSteps/4){
currentLightDistance = GetDistanceToNearestSurfaceGlobal(lightPos);
distanceToTravelLight = max(shadowMinDistance , currentLightDistance );
if ( currentLightDistance < 0){
unOccluded = 0;
j += 5000;
}
lightPos += lightVec * distanceToTravelLight ;
shadowMinDistance += minDistMult;
j++;
}
T *= 1.0 - density*distanceToTravel*unOccluded ;
//Accum += distanceToTravel *density * unOccluded ;
//if (Accum > 1){
// return min(float(1),float(Accum));
//}
curpos -= CamVec * distanceToTravel;
minDistance += minDistMult;
i++;
}
return 1;