R2 Shaders
Functions
R2LogDepth.h File Reference

Logarithmic depth functions. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

float R2_logDepthPrepareEyeZ (const float z)
 
float R2_logDepthEncodePartial (const float z, const float depth_coefficient)
 
float R2_logDepthEncodeFull (const float z, const float depth_coefficient)
 
float R2_logDepthDecode (const float z, const float depth_coefficient)
 

Detailed Description

Logarithmic depth functions.

Definition in file R2LogDepth.h.

Function Documentation

§ R2_logDepthDecode()

float R2_logDepthDecode ( const float  z,
const float  depth_coefficient 
)

Decode a depth value that was encoded with the given depth coefficient. Note that in most cases, this will yield a positive eye-space Z value, and must be negated to yield a conventional negative eye-space Z value.

Parameters
zThe depth value
depth_coefficientThe coefficient used during encoding
Returns
The original (positive) eye-space Z value

Definition at line 72 of file R2LogDepth.h.

75 {
76  float half_co = depth_coefficient * 0.5;
77  float exponent = z / half_co;
78  return pow (2.0, exponent) - 1.0;
79 }

§ R2_logDepthEncodeFull()

float R2_logDepthEncodeFull ( const float  z,
const float  depth_coefficient 
)

Fully encode the given eye-space Z value.

Parameters
zAn eye-space Z value
depth_coefficientThe depth coefficient used to encode z
Returns
The fully encoded depth

Definition at line 51 of file R2LogDepth.h.

54 {
55  float half_co = depth_coefficient * 0.5;
56  float clamp_z = max (0.000001, z + 1.0);
57  return log2 (clamp_z) * half_co;
58 }

§ R2_logDepthEncodePartial()

float R2_logDepthEncodePartial ( const float  z,
const float  depth_coefficient 
)

Partially encode the given positive eye-space Z value. This partial encoding can be used when performing part of the encoding in a vertex shader and the rest in a fragment shader (for efficiency reasons) - See R2_logDepthPrepareEyeZ.

Parameters
zAn eye-space Z value
depth_coefficientThe depth coefficient used to encode z
Returns
The encoded depth

Definition at line 33 of file R2LogDepth.h.

36 {
37  float half_co = depth_coefficient * 0.5;
38  float clamp_z = max (0.000001, z);
39  return log2 (clamp_z) * half_co;
40 }

§ R2_logDepthPrepareEyeZ()

float R2_logDepthPrepareEyeZ ( const float  z)

Prepare an eye-space Z value for encoding. See R2_logDepthEncodePartial.

Parameters
zAn eye-space Z value
Returns
The prepared value

Definition at line 15 of file R2LogDepth.h.

17 {
18  return 1.0 + (-z);
19 }