Skip to content

Instantly share code, notes, and snippets.

@gwaldron
Created February 23, 2018 17:28
Show Gist options
  • Select an option

  • Save gwaldron/513575afcfb045a03bf1882a90914f23 to your computer and use it in GitHub Desktop.

Select an option

Save gwaldron/513575afcfb045a03bf1882a90914f23 to your computer and use it in GitHub Desktop.
Triton/osgEarth LogarithmicDepthBuffer integration (with fragment depth)
#ifdef OPENGL32
out vec4 fragColor;
#endif
// Light, view, and normal vectors are all in world space.
// This function may be used to modify the ambient, diffuse, and specular light computed by Triton's fragment shaders.
void user_lighting(in vec3 L
, in vec3 vVertex_World_Space, in vec3 vNormal_World_Space
, in vec4 vVertex_Projection_Space
, inout vec3 ambient, inout vec3 diffuse, inout vec3 specular)
{
}
// View in world space. The final waterColor will be alpha-blended with the fogColor by fogBlend.
void user_fog(in vec3 vNorm, inout vec4 waterColor, inout vec4 fogColor, inout float fogBlend)
{
}
// The final computed color is normally just clamped to (0,1), but you may override this behavior here.
void user_tonemap(in vec4 preToneMapColor, inout vec4 postToneMapColor)
{
}
// Override spray particle colors. Note these are drawn with an additive blending
// mode, so darker colors just result in more transparent particles. You're given
// the position in eye and world coordinates, and the texture lookup results for the
// spray particle. "Transparency" represents the overall transparency of the particles.
// "Decay" is used to fade out the particle over time. The final output color should
// be written to additive Color.
// The default implementation is:
// additiveColor = texColor * lightColor * decay * transparency
void user_particle_color(in vec3 vEye, in vec3 vWorld, in vec4 texColor,
in vec4 lightColor, in float transparency, in float decay,
inout vec4 additiveColor)
{
}
// Override the shading of volumetric decals on the water. You are given the texture lookup value,
// alpha value for the decal, and light color for the decal. The incoming default finalColor
// is the textureColor times the lightColor, with the alpha component further multiplied by alpha.
void user_decal_color(in vec4 textureColor, in float alpha, in vec4 lightColor, inout vec4 finalColor)
{
}
//adjust the reflection color prior to it being used by triton.
void user_reflection_adjust(in vec4 envColor, in vec4 planarColor, in float planarReflectionBlend, inout vec4 reflectedColor)
{
}
// Shadows the fragment; 1.0 = no shadow, 0 = black.
float user_cloud_shadow_fragment()
{
return 1.0;
}
// Adjust the water diffuse to include color from breaking waves, propeller wash, and some refraction
void user_diffuse_color( inout vec3 Cdiffuse, in vec3 CiNoLight, in vec4 reflectedColor,
in float reflectivity )
{
}
uniform float oe_logDepth_FC;
varying float oe_logDepth_clipz;
void oe_logDepth_frag()
{
if (gl_ProjectionMatrix[3][3] == 0.0) // perspective
{
gl_FragDepth = log2(oe_logDepth_clipz) * 0.5*oe_logDepth_FC;
}
else
{
// must set gl_FragDepth is all branches even if it doesn't change
gl_FragDepth = gl_FragCoord.z;
}
}
// Output to MRT
void writeFragmentData(in vec4 finalColor, in vec4 Cdiffuse, in vec3 lightColor, in vec3 nNorm )
{
oe_logDepth_frag();
#ifdef OPENGL32
fragColor = finalColor;
#else
gl_FragColor = finalColor;
#endif
}
float user_get_depth( in vec3 worldPos )
{
return 1000.0;
}
/* You may use this hook to set any varying parameters you need for the user-functions.glsl fragment program.
provided are the ocean vertex in world, eye, and projected coordinates. */
void user_intercept(in vec3 worldPosition, in vec3 localPosition, in vec4 eyePosition, in vec4 projectedPosition)
{
}
uniform float oe_logDepth_FC;
varying float oe_logDepth_clipz;
vec4 oe_logDepth_vert(in vec4 clip)
{
if (gl_ProjectionMatrix[3][3] == 0.0) // perspective
{
clip.z = (log2(max(1e-6, 1.0 + clip.w)) * oe_logDepth_FC - 1.0) * clip.w;
oe_logDepth_clipz = 1.0 + clip.w;
}
return clip;
}
// Provides a point to override the final value of gl_Position.
// Useful for implementing logarithmic depth buffers etc.
vec4 overridePosition(in vec4 position)
{
return oe_logDepth_vert(position);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment