Author Topic: Tenkoku Fog and Water  (Read 22 times)

rostik1975

  • Newbie
  • *
  • Posts: 1
    • View Profile
Tenkoku Fog and Water
« on: May 11, 2019, 09:54:46 AM »
Hi,
Could you please tell me how I can edit Tenkoku Fog shader or script so the water is displayed behind the fog?
I use Lux Water that supports both Enviro and AzureSky fog, and I got the following answer from their support:
"Tenkoku should ship with a fog function for transparent shaders like particles, glas or billboards.
if so you would have to call that function at the end of the water shader (core file) - just where it calls the other fog functions right now."

So in LuxWater shader I can see
Code: [Select]
// Fog Mode
#include "Includes/LuxWater_Setup.cginc"

Then in cginc file I set
Code: [Select]
//  Azure Fog ---------------------------
// #define FOG_AZUR
// #include "Assets/Azure[Sky] Dynamic Skybox/Shaders/Transparent/AzureFogCore.cginc"
//  Tenkoku Fog ---------------------------
#define FOG_TENKOKU
#include "Assets/ --- *** "

*** - here I need to put the path to Tenkoku cginc Fog function.

Example - AzureSky uses the following function in AzureFogCore.cginc:
Code: [Select]
float4 ApplyAzureFog (float4 fragOutput, float3 worldPos)
{
#ifdef UNITY_PASS_FORWARDADD
float3 fogScatteringColor = 0;
#else
float3 fogScatteringColor = AzureComputeFogScattering(worldPos);
#endif

// Calcule Standard Fog.
float depth = distance(_WorldSpaceCameraPos, worldPos);
float fog = smoothstep(-_Azure_FogBlend, 1.25, depth / _Azure_FogDistance) * _Azure_FogDensity;
float heightFogDistance = smoothstep(-_Azure_HeightFogBlend, 1.25, depth / _Azure_HeightFogDistance);

// Calcule Height Fog.
float3 worldSpaceDirection = mul((float3x3)_Azure_UpMatrix, worldPos.xyz);
float heightFog = saturate((worldSpaceDirection.y - _Azure_HeightFogStart) / (_Azure_HeightFogEnd + _Azure_HeightFogStart));
heightFog = 1.0 - heightFog;
heightFog *= heightFog;
heightFog *= heightFogDistance;
float fogFactor = saturate(fog + heightFog * _Azure_HeightFogDensity);

// Apply Fog.
#if defined(_ALPHAPREMULTIPLY_ON)
fragOutput.a = lerp(fragOutput.a, 1.0, fogFactor);
#endif
fogScatteringColor = lerp(fragOutput.rgb, fogScatteringColor, fogFactor * lerp(fragOutput.a, 1.0, 2.0 - fogFactor));
return float4(fogScatteringColor, fragOutput.a);
}

it is called from LuxWaterCore.cginc:
Code: [Select]
#elif defined(FOG_AZUR)
            if (!backside){
                c = ApplyAzureFog( float4(c.rgb, 1), float4(i.grabUV.xy, surfaceEyeDepth, i.grabUV.w), worldPos);
            }

I can add the condition for Tenkoku Fog too, but I can't see such cginc files in your system.
Could you help me please?
Thank you.

Chingwa

  • Administrator
  • Hero Member
  • *****
  • Posts: 1633
    • View Profile
    • Tanuki Digital
Re: Tenkoku Fog and Water
« Reply #1 on: May 13, 2019, 09:25:08 AM »
Hi Rostik1975,
Thanks for the example code.  Currently Tenkoku does not have fog code access such as you're showing in these examples.  However there is probably a similar solution that can be obtained, let me dig around a bit and I'll get back to you.