TUFX icon indicating copy to clipboard operation
TUFX copied to clipboard

Add basic ocean replacement

Open shadowmage45 opened this issue 4 years ago • 0 comments

Because KSPs ocean causes issues with HDR (likely their 'infinite vertex' solution, resulting in degenerate triangles, which are finally causing NANs in the bloom filtering).

  • [x] Develop screen-space shading effect with calculations to determine water base height.
  • [ ] Develop height and normal distortion methods
    • Can utilize a displacement map and a height-map as inputs
  • [ ] Calculate light refraction
  • [ ] Calculate visual reflection (fresnel)
  • [ ] Somehow include the water data and reflected light in the atmosphere calculations... (second pass?)
    • So.. the water reflection needs access to the atmosphere rendered data (e.g. the environment map)
    • And... the atmosphere needs access to the water data to know what value to use for the background color
  • [ ] It seems possible that the existing scattering shader might be utilized for the volumetric lighting calculation portion of the effect. Either integrated, or as a variation of it. Integrated might play best, though that leaves in question where to perform the surface calculations (refraction, etc)
    • Could possibly be integrated into the existing pipeline as an additional 'layer', where the bottom radius of the atmosphere is set to the max ocean depth. This data would then occupy the (abstractly) lower portion of the textures and would be used for lighting calcs whenever the ray traversed through the ocean.
    • Would need even better depth sampling

https://www.gamedev.net/articles/programming/graphics/rendering-water-as-a-post-process-effect-r2642/

https://www.gamasutra.com/view/feature/3036/deep_water_animation_and_rendering.php?print=1


  • Distort surface normals and depth through procedural means
  • This will generate a new offset world surface position; store the inverse offset from the undisturbed surface position.
  • Write world-position to output buffer (surfacePosBuffer)
  • Determine world-position hit of the ray cast through the surface (raymarch depth buffer?), write this into a new buffer (refractionHitPosBuffer) or more easily reconstructed later if it were encoded as a (refractionWorldSpaceOffsetBuffer) denoting the difference in refracted hit position vs. the sampled screenspace UV position.
    • What to do about world-hit pixels that are out of current view?
    • For kerbin/etc, can use the PQS heightmap data to get accurate raytrace info?
  • The complete ray can then be reconstructed as surfacePos -> refractionHitPos or (surfacePos -> surfacePos + refractionOffset)

Calculation of tangent-frame for a position on a sphere:

  • Assume equirectangular spherical UV mapping.
  • Determine UV coordinate for the current position
  • Offset UV.x by predetermined percentage of sphere (1/360?), sample world-position at that UV
  • Offset UV.y by ?, sample world-position at that UV
  • Use the set of three positions as three vertices of a triangle
  • From there it is standard tangent/bitangent calculation bits from geometry shaders...

shadowmage45 avatar Mar 13 '20 14:03 shadowmage45