mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-11-03 23:26:40 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			24 lines
		
	
	
	
		
			479 B
		
	
	
	
		
			GLSL
		
	
	
	
	
	
			
		
		
	
	
			24 lines
		
	
	
	
		
			479 B
		
	
	
	
		
			GLSL
		
	
	
	
	
	
#ifndef LIB_VIEW_DEPTH
 | 
						|
#define LIB_VIEW_DEPTH
 | 
						|
 | 
						|
float linearizeDepth(float depth, float near, float far)
 | 
						|
{
 | 
						|
#if @reverseZ
 | 
						|
    depth = 1.0 - depth;
 | 
						|
#endif
 | 
						|
    float z_n = 2.0 * depth - 1.0;
 | 
						|
    depth = 2.0 * near * far / (far + near - z_n * (far - near));
 | 
						|
    return depth;
 | 
						|
}
 | 
						|
 | 
						|
float getLinearDepth(in float z, in float viewZ)
 | 
						|
{
 | 
						|
#if @reverseZ
 | 
						|
    // FIXME: Fixme, figure out how to calculate correct linear depth for reverse z
 | 
						|
    return -viewZ;
 | 
						|
#else
 | 
						|
    return z;
 | 
						|
#endif
 | 
						|
}
 | 
						|
 | 
						|
#endif
 |