Created
February 21, 2018 14:36
-
-
Save gwaldron/8c2eec040c4f3f71a2cc0b433eb76e9b to your computer and use it in GitHub Desktop.
SilverLining/osgEarth LogarithmicDepthBuffer integration (with fragment depth)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Allow overriding of the final sky fragment color | |
| void overrideSkyFragColor(inout vec4 finalColor) | |
| { | |
| } | |
| // Allows overriding of the fog color, fog blend factor, underlying cloud color, and alpha blending of the cloud. | |
| void overrideStratusLighting(in vec3 fogColor, in float fogFactor, in vec3 cloudColor, in float cloudFade, inout vec4 finalColor) | |
| { | |
| } | |
| // Overrides fragment colors in stratocumulus clouds. The pre-lit color (which incorporates light scattering within the cloud) is | |
| // given as well as the light color. These are multiplied together to provide the default finalColor. | |
| // finalColor = color * lightColor; | |
| void overrideStratocumulus(in vec4 color, in vec4 lightColor, inout vec4 finalColor) | |
| { | |
| } | |
| // Overrides fragment colors of billboards (cloud puffs, sun, moon.) | |
| void overrideBillboardFragment(in vec4 texColor, in vec4 lightColor, inout vec4 finalColor) | |
| { | |
| } | |
| //Overrides the final color of the Cirrus Clouds | |
| // original finalColor is texel * gl_Color | |
| void overrideCirrusColor(in vec4 texel, in vec4 litColor, inout vec4 finalColor) | |
| { | |
| } | |
| // Overrides the particle color used to light rain, snow, and sleet. | |
| void overrideParticleColor(in vec4 textureColor, in vec4 lightColor, inout vec4 particleColor) | |
| { | |
| } | |
| uniform float oe_logDepth_FC; | |
| varying float oe_logDepth_clipz; | |
| void oe_logDepth_frag(in vec4 color) | |
| { | |
| 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; | |
| } | |
| } | |
| // Write the final fragment color. Implement this if you need to write to multiple render targets, for example. | |
| void writeFragmentData(in vec4 finalColor) | |
| { | |
| oe_logDepth_frag(finalColor); | |
| gl_FragColor = finalColor; | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Hook to override computation of fog on clouds | |
| // fogExponent is squared to determine the blending of clouds with the background | |
| // fogBlend is used for blending fogColor with the cloud color. | |
| void overrideBillboardFog(in vec3 eyePosition, inout vec4 fogColor, inout float fogExponent, inout float fogBlend, inout float fogFade) | |
| { | |
| } | |
| // Cloud puffs are drawn additively, so dark = more transparent. This allows you to influence the color used for a given | |
| // puff. This color is multiplied with the puff texture in the fragment shader, and nothing more. | |
| // By default the fogged color is multiplied by the cloudFade, voxelFade, and fogFade, which apply alpha effects on the | |
| // cloud layer as a whole, on the individual puff (ie while clouds are growing in real time,) and from fog (we simulate atmospheric | |
| // scattering by blending the puff into the sky behind it based on distance.) | |
| // modelPos is the position of the puff vertex, before billboarding has been applied, and rotated into a Y-is-up system. So, the altitude | |
| // of this vertex will be in modelPos.y. | |
| void overrideBillboardColor(in vec3 eyePosition, in vec4 modelPos, in vec4 foggedColor, in float cloudFade, in float voxelFade, in float fogFade, inout vec4 finalColor) | |
| { | |
| } | |
| // Override the vertex color of a point on the sky box. The position in world space (relative to the camera) is given, as is | |
| // our sky color before and after applying fog. | |
| void overrideSkyColor(in vec3 vertexPos, in float fogDensity, in vec4 preFogColor, inout vec4 finalColor) | |
| { | |
| } | |
| // Overrides colors of cirrus and cirrocumulus clouds | |
| void overrideCirrusLighting(in vec3 lightColor, in vec3 fogColor, in float fogBlend, in float alpha, inout vec4 finalColor) | |
| { | |
| } | |
| // Override the star colors. | |
| void overrideStars(in vec4 worldPos, in float magnitude, in vec4 starColor, in vec4 fogColor, in float fogDensity, inout vec4 finalColor) | |
| { | |
| } | |
| // override the color calculation for the Stratus clouds. | |
| // finalColor = vec4(color.x, color.y, color.z, color.w * fadeAndDisplacementFactor); | |
| void overrideStratocumulusColor(inout vec4 finalColor) | |
| { | |
| } | |
| 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); | |
| //return position; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment