logarithmic depth
This commit is contained in:
		
							parent
							
								
									cdc4aea9d5
								
							
						
					
					
						commit
						b312d390da
					
				| @ -1,4 +1,5 @@ | |||||||
| const float INF = 17.0; | const float INF = 100.0; | ||||||
| const float PI = 3.14159; | const float PI = 3.14159; | ||||||
|  | const float E = 2.71828; | ||||||
| const int SAMPLES = 1; | const int SAMPLES = 1; | ||||||
| const int BOUNCES = 4; | const int BOUNCES = 4; | ||||||
|  | |||||||
| @ -61,9 +61,11 @@ void main() | |||||||
|     pixel.xyz /= SAMPLES; |     pixel.xyz /= SAMPLES; | ||||||
| 
 | 
 | ||||||
|     vec4 d = imageLoad(_g0, ivec2(gl_GlobalInvocationID.xy)); |     vec4 d = imageLoad(_g0, ivec2(gl_GlobalInvocationID.xy)); | ||||||
|     float depth = d.x; |     float depth = d.w; | ||||||
|  |     vec3 normal = d.xyz*2.0-1.0; // unpack normal packaged into texture | ||||||
| 
 | 
 | ||||||
|     pixel.xyz = mix(pixel.xyz, vec3(0), depth); |     //pixel.xyz = mix(pixel.xyz, normal, 1.0-depth); | ||||||
|  |     pixel.xyz = mix(pixel.xyz, vec3(1.0), depth); | ||||||
| 
 | 
 | ||||||
|     //pixel.a = 1.0; |     //pixel.a = 1.0; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -33,16 +33,22 @@ void main() | |||||||
|     Ray ray = createCameraRay(uv); |     Ray ray = createCameraRay(uv); | ||||||
|     RayHit hit = trace(ray); |     RayHit hit = trace(ray); | ||||||
| 
 | 
 | ||||||
|     //pixel.xyz = hit.normal; |     // n roughly correlates to steepness of log curve | ||||||
| 
 |     // TODO: what does this mean in mathematical terms?? | ||||||
|     // TODO: non-linear depth |     float n = 3; | ||||||
|     float n = 1; |  | ||||||
|     float f = INF; |     float f = INF; | ||||||
|     float z = hit.distance; |     float z = hit.distance; | ||||||
|      |      | ||||||
|     float depth = (1.0/z-1.0/n)/(1.0/n-1.0/f); |     float depth; | ||||||
|  |     // linear depth | ||||||
|  |     //depth = z/f; | ||||||
| 
 | 
 | ||||||
|     pixel.x = z/f; |     // logarithmic depth | ||||||
|  |     depth = log(z*pow(E,n)/f)/n; | ||||||
|  | 
 | ||||||
|  |     // pack normal into texture | ||||||
|  |     pixel.xyz = hit.normal*0.5+0.5; | ||||||
|  |     pixel.w = depth; | ||||||
| 
 | 
 | ||||||
|     imageStore(g0_output, pixelCoords, pixel); |     imageStore(g0_output, pixelCoords, pixel); | ||||||
| } | } | ||||||
|  | |||||||
| @ -8,7 +8,7 @@ void updateCameraUniforms(GLuint shaderProgram, float aspect) | |||||||
| 
 | 
 | ||||||
|     // wobble up dir
 |     // wobble up dir
 | ||||||
|     vec3 cdir, cright, cup; |     vec3 cdir, cright, cup; | ||||||
|     vec3 up = {0.1*sin(t),1.0,0.2*cos(t)}; |     vec3 up = {0.1*sin(t),1.0,0.05*cos(0.5*t)}; | ||||||
|     glm_vec3_normalize(up); |     glm_vec3_normalize(up); | ||||||
| 
 | 
 | ||||||
|     // camera and target pos
 |     // camera and target pos
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user