Announcement

Collapse
No announcement yet.

Post Processing/Global Distance Field effect fine in viewport/simulate but Black during play.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    Post Processing/Global Distance Field effect fine in viewport/simulate but Black during play.

    Hi

    I'm experimenting with using the global distance field to do volumetric light shafts.

    Click image for larger version

Name:	UE4Editor_2016-05-01_23-09-43.jpg
Views:	1
Size:	205.9 KB
ID:	1181435

    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.

    Code:
    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;
    Attached Files
    Visual Effects Artist, Weta Digital, Wellington New Zealand
    BLOG www.danielelliott.co.uk
    @danielelliott3d https://twitter.com/danielelliott3d
    Unreal Engine and VFX Tutorials https://www.youtube.com/user/DokipenTechTutorials
    2015 Showreel: https://vimeo.com/116917817

    #2
    I figured out the issue. It was that the camera position wasn't the same in the game vs editor. The 'clipping plane' or something like that must be different. If I subtract the camera vector from the position before sending it into the custom node then it all comes out fine.

    Click image for larger version

Name:	UE4Editor_2016-05-02_21-23-40.jpg
Views:	1
Size:	48.8 KB
ID:	1105821
    Visual Effects Artist, Weta Digital, Wellington New Zealand
    BLOG www.danielelliott.co.uk
    @danielelliott3d https://twitter.com/danielelliott3d
    Unreal Engine and VFX Tutorials https://www.youtube.com/user/DokipenTechTutorials
    2015 Showreel: https://vimeo.com/116917817

    Comment

    Working...
    X