VolumetricFog 2.0

This commit is contained in:
Bartek
2025-10-13 14:55:32 +02:00
parent c5f574b05c
commit 59d14633a5
59 changed files with 827 additions and 192 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 60d9ec5fcaf76684f856b882ab632a45
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,143 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &-7347096721105448201
MonoBehaviour:
m_ObjectHideFlags: 11
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
m_Name:
m_EditorClassIdentifier:
version: 10
--- !u!21 &2100000
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Fog
m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords:
- _ALPHAPREMULTIPLY_ON
- _ENVIRONMENTREFLECTIONS_OFF
- _SPECULARHIGHLIGHTS_OFF
- _SPECULAR_SETUP
- _SURFACE_TYPE_TRANSPARENT
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: 3000
stringTagMap:
RenderType: Transparent
disabledShaderPasses:
- MOTIONVECTORS
- DepthOnly
- SHADOWCASTER
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BaseMap:
m_Texture: {fileID: 2800000, guid: d10e6a092c503ab4199ecec3ae5c953e, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SpecGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_Lightmaps:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_LightmapsInd:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_ShadowMasks:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _AddPrecomputedVelocity: 0
- _AlphaClip: 0
- _AlphaToMask: 0
- _Blend: 0
- _BlendModePreserveSpecular: 1
- _BumpScale: 1
- _ClearCoatMask: 0
- _ClearCoatSmoothness: 0
- _Cull: 2
- _Cutoff: 0
- _DetailAlbedoMapScale: 1
- _DetailNormalMapScale: 1
- _DstBlend: 10
- _DstBlendAlpha: 10
- _EnvironmentReflections: 0
- _GlossMapScale: 0
- _Glossiness: 0
- _GlossyReflections: 0
- _Metallic: 0
- _OcclusionStrength: 1
- _Parallax: 0.005
- _QueueOffset: 0
- _ReceiveShadows: 1
- _Smoothness: 0.023
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 0
- _SrcBlend: 1
- _SrcBlendAlpha: 1
- _Surface: 1
- _WorkflowMode: 0
- _ZWrite: 0
m_Colors:
- _BaseColor: {r: 0, g: 0.4716981, b: 0.22123891, a: 0.10980392}
- _Color: {r: 0, g: 0.4716981, b: 0.22123888, a: 0.10980392}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecColor: {r: 0.0335326, g: 0.084905684, b: 0, a: 1}
m_BuildTextureStacks: []
m_AllowLocking: 1

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 029ee9db1aff91f4ebf470f0b5ed0b03
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3595323a20e4e9149af6b2682ddbbd16
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11700000
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: de9d333e7ece24e488908a9b606d2575
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11700000
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b9aa881a4e8a39846be9a61466800446
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11700000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,65 @@
using UnityEngine;
[ExecuteAlways]
public class FogNoiseGenerator : MonoBehaviour
{
public Material targetMaterial;
public string propertyName = "_FogNoise";
public int size = 64;
public float scale = 0.05f;
public int seed = 1337;
void Start() { if (Application.isPlaying) Generate(); }
[ContextMenu("Generate Noise")]
public void Generate()
{
if (targetMaterial == null) { Debug.LogWarning("No target material set"); return; }
var tex = CreatePerlin3D(size, scale, seed);
tex.wrapMode = TextureWrapMode.Repeat;
tex.filterMode = FilterMode.Trilinear;
tex.Apply();
targetMaterial.SetTexture(propertyName, tex);
Debug.Log("Generated Texture3D and assigned to material");
}
static Texture3D CreatePerlin3D(int size, float scale, int seed)
{
var tex = new Texture3D(size, size, size, TextureFormat.RGBA32, false);
var cols = new Color[size * size * size];
var rng = new System.Random(seed);
float ox = (float)rng.NextDouble() * 10000f, oy = (float)rng.NextDouble() * 10000f, oz = (float)rng.NextDouble() * 10000f;
int idx = 0;
for (int z = 0; z < size; z++)
{
float wz = (z + oz) * scale;
for (int y = 0; y < size; y++)
{
float wy = (y + oy) * scale;
for (int x = 0; x < size; x++)
{
float wx = (x + ox) * scale;
float n = FractalPerlin(wx, wy, wz, 3);
cols[idx++] = new Color(n, n, n, n);
}
}
}
tex.SetPixels(cols);
return tex;
}
static float FractalPerlin(float x, float y, float z, int octaves)
{
float amp = 1f, freq = 1f, sum = 0f, max = 0f;
for (int i = 0; i < octaves; i++)
{
sum += amp * Mathf.PerlinNoise(x * freq, y * freq);
sum += amp * Mathf.PerlinNoise(y * freq, z * freq);
sum += amp * Mathf.PerlinNoise(z * freq, x * freq);
max += 3f * amp;
amp *= 0.5f;
freq *= 2f;
}
return Mathf.Clamp01(sum / max);
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 491a2f6e8cbd1ff49a2eb93772881d0e

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 MiB

View File

@@ -0,0 +1,117 @@
fileFormatVersion: 2
guid: 122f172c549967c4cbc3ca3e80298b5f
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 13
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 0
platformSettings:
- serializedVersion: 4
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
customData:
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spriteCustomMetadata:
entries: []
nameFileIdTable: {}
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,158 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: SwampFogPlane
m_Shader: {fileID: 211, guid: 0000000000000000f000000000000000, type: 0}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords:
- _ALPHABLEND_ON
- _FADING_ON
m_InvalidKeywords: []
m_LightmapFlags: 0
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: 3000
stringTagMap:
RenderType: Transparent
disabledShaderPasses:
- MOTIONVECTORS
- GRABPASS
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BaseMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SpecGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_Lightmaps:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_LightmapsInd:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_ShadowMasks:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _AddPrecomputedVelocity: 0
- _AlphaClip: 0
- _AlphaToMask: 0
- _Blend: 0
- _BlendModePreserveSpecular: 1
- _BlendOp: 0
- _BumpScale: 1
- _CameraFadingEnabled: 0
- _CameraFarFadeDistance: 2
- _CameraNearFadeDistance: 1
- _ClearCoatMask: 0
- _ClearCoatSmoothness: 0
- _ColorMode: 0
- _Cull: 2
- _Cutoff: 0.5
- _DetailAlbedoMapScale: 1
- _DetailNormalMapScale: 1
- _DistortionBlend: 0.5
- _DistortionEnabled: 0
- _DistortionStrength: 1
- _DistortionStrengthScaled: 0
- _DstBlend: 10
- _DstBlendAlpha: 0
- _EmissionEnabled: 0
- _EnvironmentReflections: 1
- _FlipbookMode: 0
- _GlossMapScale: 0
- _Glossiness: 0
- _GlossyReflections: 0
- _LightingEnabled: 0
- _Metallic: 0
- _Mode: 2
- _OcclusionStrength: 1
- _Parallax: 0.005
- _QueueOffset: 0
- _ReceiveShadows: 1
- _Smoothness: 0.5
- _SmoothnessTextureChannel: 0
- _SoftParticlesEnabled: 1
- _SoftParticlesFarFadeDistance: 45
- _SoftParticlesNearFadeDistance: 0
- _SpecularHighlights: 1
- _SrcBlend: 5
- _SrcBlendAlpha: 1
- _Surface: 0
- _WorkflowMode: 1
- _ZWrite: 0
m_Colors:
- _BaseColor: {r: 0.2688089, g: 0.6415094, b: 0, a: 1}
- _CameraFadeParams: {r: 0, g: Infinity, b: 0, a: 0}
- _Color: {r: 0.32944074, g: 0.7830189, b: 0, a: 0.4392157}
- _ColorAddSubDiff: {r: 0, g: 0, b: 0, a: 0}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SoftParticleFadeParams: {r: 0, g: 0.022222223, b: 0, a: 0}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
m_BuildTextureStacks: []
m_AllowLocking: 1
--- !u!114 &729621175673853768
MonoBehaviour:
m_ObjectHideFlags: 11
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
m_Name:
m_EditorClassIdentifier:
version: 9

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3c5671a395844724b88a76bfef1cbe31
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,167 @@
Shader "Custom/VolumetricFog_ExtendedFX"
{
Properties
{
_ColorLow("Fog Color Low", Color) = (0.6, 0.6, 0.7, 1)
_ColorHigh("Fog Color High", Color) = (0.8, 0.8, 0.9, 1)
_AmbientFogColor("Ambient Fog Color", Color) = (0.3, 0.3, 0.35, 1)
_MaxDistance("Max Distance", Float) = 100
_StepSize("Step Size", Range(0.1, 20)) = 1
_MaxSteps("Max Steps", Range(8, 256)) = 64
_DensityMultiplier("Density Multiplier", Range(0, 10)) = 1
_DensityThreshold("Density Threshold", Range(0, 1)) = 0.1
_HeightFalloff("Height Falloff", Range(0, 2)) = 0.2
_NoiseOffset("Noise Offset", Float) = 0
_NoiseTiling("Noise Tiling", Float) = 1
_FogNoise("Fog Noise", 3D) = "white" {}
_NoiseScrollSpeed("Noise Scroll Speed (XYZ)", Vector) = (0.02, 0, 0.015, 0)
_NoisePulseSpeed("Noise Pulse Speed", Float) = 0.2
_NoisePulseAmount("Noise Pulse Amount", Float) = 0.1
[HDR]_LightContribution("Light Contribution", Color) = (1, 1, 1, 1)
_LightScattering("Light Scattering (g)", Range(-1, 1)) = 0.2
_DepthFade("Depth Fade Strength", Range(0,1)) = 0.3
// ✅ Soft clip dla near fade
_NearStart("Near Fade Start", Float) = 1.0
_NearEnd("Near Fade End", Float) = 3.0
_DayColor("Day Fog Tint", Color) = (0.7,0.75,0.8,1)
_NightColor("Night Fog Tint", Color) = (0.3,0.35,0.4,1)
_DayFactor("Day/Night Blend", Range(0,1)) = 0.5
_GodRayStrength("God Ray Strength", Range(0,1)) = 0.2
_DitherStrength("Dither Strength", Range(0,1)) = 0.3
_ColorSteps("Color Steps", Range(2,32)) = 8
}
SubShader
{
Tags { "RenderType"="Opaque" "RenderPipeline"="UniversalPipeline" }
Pass
{
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment frag
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
#pragma multi_compile _ _ADDITIONAL_LIGHTS
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
float4 _ColorLow, _ColorHigh, _AmbientFogColor;
float _MaxDistance, _StepSize; int _MaxSteps;
float _DensityMultiplier, _DensityThreshold, _HeightFalloff;
float _NoiseOffset, _NoiseTiling; TEXTURE3D(_FogNoise);
float3 _NoiseScrollSpeed; float _NoisePulseSpeed, _NoisePulseAmount;
float4 _LightContribution; float _LightScattering;
float _DepthFade;
float _NearStart, _NearEnd;
float4 _DayColor, _NightColor; float _DayFactor, _GodRayStrength;
float _DitherStrength; float _ColorSteps;
float henyey_greenstein(float cosTheta, float g)
{
float g2 = g * g;
return (1.0 - g2) / (4.0 * PI * pow(1.0 + g2 - 2.0 * g * cosTheta, 1.5));
}
float get_density(float3 worldPos)
{
float pulse = 1.0 + sin(_Time.y * _NoisePulseSpeed) * _NoisePulseAmount;
float3 noiseCoords = worldPos * 0.01 * _NoiseTiling * pulse;
noiseCoords += _NoiseScrollSpeed * _Time.y;
float4 noise = _FogNoise.SampleLevel(sampler_TrilinearRepeat, noiseCoords, 0);
float density = noise.r;
density = saturate(density - _DensityThreshold) * _DensityMultiplier;
density *= exp(-max(0, worldPos.y) * _HeightFalloff);
return density;
}
half4 frag(Varyings IN) : SV_Target
{
float4 col = SAMPLE_TEXTURE2D(_BlitTexture, sampler_LinearClamp, IN.texcoord);
float depth = SampleSceneDepth(IN.texcoord);
float3 worldPos = ComputeWorldSpacePosition(IN.texcoord, depth, UNITY_MATRIX_I_VP);
float3 entryPoint = _WorldSpaceCameraPos;
float3 viewDir = worldPos - _WorldSpaceCameraPos;
float viewLength = length(viewDir);
float3 rayDir = normalize(viewDir);
float2 pixelCoords = IN.texcoord * _BlitTexture_TexelSize.zw;
float distLimit = min(viewLength, _MaxDistance);
float distTravelled = InterleavedGradientNoise(pixelCoords, (int)(_Time.y / max(HALF_EPS, unity_DeltaTime.x))) * _NoiseOffset;
float transmittance = 1.0;
float3 fogAccum = 0;
[loop]
for (int i = 0; i < _MaxSteps && distTravelled < distLimit; i++)
{
float3 rayPos = entryPoint + rayDir * distTravelled;
float density = get_density(rayPos);
if (density > 0)
{
Light mainLight = GetMainLight(TransformWorldToShadowCoord(rayPos));
float phase = henyey_greenstein(dot(rayDir, mainLight.direction), _LightScattering);
float3 lightCol = mainLight.color.rgb * _LightContribution.rgb * phase * mainLight.shadowAttenuation;
#if defined(_ADDITIONAL_LIGHTS)
uint lightCount = GetAdditionalLightsCount();
[loop]
for (uint li = 0; li < lightCount; li++)
{
Light addLight = GetAdditionalLight(li, rayPos);
float phaseAdd = henyey_greenstein(dot(rayDir, addLight.direction), _LightScattering);
lightCol += addLight.color.rgb * _LightContribution.rgb * phaseAdd * addLight.distanceAttenuation;
}
#endif
float3 fogColor = lerp(_ColorLow.rgb, _ColorHigh.rgb, saturate(rayPos.y * 0.01));
float3 dayNightTint = lerp(_NightColor.rgb, _DayColor.rgb, _DayFactor);
fogColor = lerp(fogColor, dayNightTint, 0.5);
fogColor = lerp(fogColor, _AmbientFogColor.rgb, 0.25);
fogColor += lightCol * _GodRayStrength;
// ✅ Depth fade
float fade = exp(-distTravelled * _DepthFade);
// ✅ Soft clip near fade
float nearFactor = saturate((distTravelled - _NearStart) / (_NearEnd - _NearStart));
density *= fade * nearFactor;
fogAccum += (fogColor + lightCol) * density * _StepSize;
transmittance *= exp(-density * _StepSize);
if (transmittance < 0.01) break;
}
distTravelled += _StepSize;
}
float3 finalFog = fogAccum * transmittance;
float dither = frac(sin(dot(pixelCoords, float2(12.9898,78.233))) * 43758.5453);
finalFog += (dither - 0.5) * _DitherStrength.xxx;
finalFog = floor(finalFog * _ColorSteps) / _ColorSteps;
return float4(lerp(col.rgb, finalFog, 1.0 - saturate(transmittance)), 1.0);
}
ENDHLSL
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 6934182509f924641a5a75ad544128c9
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,95 @@
Shader "VolumetricFogTutorial.shader"
{
Properties
{
_Color("Color", Color) = (1, 1, 1, 1)
_MaxDistance("Max distance", float) = 100
_StepSize("Step size", Range(0.1, 20)) = 1
_DensityMultiplier("Density multiplier", Range(0, 10)) = 1
_NoiseOffset("Noise offset", float) = 0
_FogNoise("Fog noise", 3D) = "white" {}
_NoiseTiling("Noise tiling", float) = 1
_DensityThreshold("Density threshold", Range(0, 1)) = 0.1
[HDR]_LightContribution("Light contribution", Color) = (1, 1, 1, 1)
_LightScattering("Light scattering", Range(0, 1)) = 0.2
}
SubShader
{
Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" }
Pass
{
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment frag
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
float4 _Color;
float _MaxDistance;
float _DensityMultiplier;
float _StepSize;
float _NoiseOffset;
TEXTURE3D(_FogNoise);
float _DensityThreshold;
float _NoiseTiling;
float4 _LightContribution;
float _LightScattering;
float henyey_greenstein(float angle, float scattering)
{
return (1.0 - angle * angle) / (4.0 * PI * pow(1.0 + scattering * scattering - (2.0 * scattering) * angle, 1.5f));
}
float get_density(float3 worldPos)
{
float4 noise = _FogNoise.SampleLevel(sampler_TrilinearRepeat, worldPos * 0.01 * _NoiseTiling, 0);
float density = dot(noise, noise);
density = saturate(density - _DensityThreshold) * _DensityMultiplier;
return density;
}
half4 frag(Varyings IN) : SV_Target
{
float4 col = SAMPLE_TEXTURE2D(_BlitTexture, sampler_LinearClamp, IN.texcoord);
float depth = SampleSceneDepth(IN.texcoord);
float3 worldPos = ComputeWorldSpacePosition(IN.texcoord, depth, UNITY_MATRIX_I_VP);
float3 entryPoint = _WorldSpaceCameraPos;
float3 viewDir = worldPos - _WorldSpaceCameraPos;
float viewLength = length(viewDir);
float3 rayDir = normalize(viewDir);
float2 pixelCoords = IN.texcoord * _BlitTexture_TexelSize.zw;
float distLimit = min(viewLength, _MaxDistance);
float distTravelled = InterleavedGradientNoise(pixelCoords, (int)(_Time.y / max(HALF_EPS, unity_DeltaTime.x))) * _NoiseOffset;
float transmittance = 1;
float4 fogCol = _Color;
while(distTravelled < distLimit)
{
float3 rayPos = entryPoint + rayDir * distTravelled;
float density = get_density(rayPos);
if (density > 0)
{
Light mainLight = GetMainLight(TransformWorldToShadowCoord(rayPos));
fogCol.rgb += mainLight.color.rgb * _LightContribution.rgb * henyey_greenstein(dot(rayDir, mainLight.direction), _LightScattering) * density * mainLight.shadowAttenuation * _StepSize;
transmittance *= exp(-density * _StepSize);
}
distTravelled += _StepSize;
}
return lerp(col, fogCol, 1.0 - saturate(transmittance));
}
ENDHLSL
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 188ef53a12823a14ca334af8b197bad1
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,186 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Volumetric Light
m_Shader: {fileID: 4800000, guid: 6934182509f924641a5a75ad544128c9, type: 3}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords: []
m_InvalidKeywords:
- _GLOSSYREFLECTIONS_OFF
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses:
- MOTIONVECTORS
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BaseMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _FogMask:
m_Texture: {fileID: 2800000, guid: 122f172c549967c4cbc3ca3e80298b5f, type: 3}
m_Scale: {x: 0, y: 0}
m_Offset: {x: 0, y: 0}
- _FogNoise:
m_Texture: {fileID: 11700000, guid: 3595323a20e4e9149af6b2682ddbbd16, type: 2}
m_Scale: {x: 100, y: 100}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SpecGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_Lightmaps:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_LightmapsInd:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_ShadowMasks:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _AddPrecomputedVelocity: 0
- _AlphaClip: 0
- _AlphaToMask: 0
- _AmbientScattering: 0.1
- _Blend: 0
- _BlendModePreserveSpecular: 1
- _BumpScale: 1
- _ClearCoatMask: 0
- _ClearCoatSmoothness: 0
- _ColorSteps: 6
- _Cull: 2
- _Cutoff: 0.5
- _DayFactor: 0.091
- _DensityMultiplier: 2.2
- _DensityThreshold: 0.18
- _DepthFade: 0.01
- _DetailAlbedoMapScale: 1
- _DetailNormalMapScale: 1
- _DitherStrength: 0.04
- _DstBlend: 0
- _DstBlendAlpha: 0
- _EnvironmentReflections: 1
- _GlossMapScale: 0
- _Glossiness: 0
- _GlossyReflections: 0
- _GodRayStrength: 0.25
- _HG_G: 0.2
- _HeightFalloff: 0.4
- _Intensity: 1
- _LightScattering: 0.35
- _LightScatteringG: 0.2
- _MaskTiling: 0.03
- _MaxDistance: 60
- _MaxSteps: 64
- _Metallic: 0
- _Mode: 0
- _NearEnd: 3
- _NearFade: 0
- _NearStart: 0.05
- _NoiseJitter: 0.02
- _NoiseOffset: 0.6
- _NoisePulseAmount: 0.07
- _NoisePulseSpeed: 0.15
- _NoiseTiling: 0.8
- _OcclusionStrength: 1
- _Parallax: 0.005
- _QueueOffset: 0
- _ReceiveShadows: 1
- _ShadowStrength: 1
- _Smoothness: 0.5
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _SrcBlendAlpha: 1
- _StepScale: 4
- _StepSize: 1
- _Surface: 0
- _UVSec: 0
- _WorkflowMode: 1
- _ZWrite: 1
m_Colors:
- _AmbientFogColor: {r: 0.25, g: 0.28, b: 0.3, a: 1}
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
- _Color: {r: 0.7264151, g: 0.607963, b: 0.22957456, a: 1}
- _ColorHigh: {r: 0.65, g: 0.68, b: 0.7, a: 1}
- _ColorLow: {r: 0.45, g: 0.48, b: 0.5, a: 1}
- _DayColor: {r: 0.6, g: 0.65, b: 0.7, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _FogBaseColor: {r: 0.78, g: 0.82, b: 0.9, a: 1}
- _LightContribution: {r: 18.618134, g: 14.44776, b: 12.382816, a: 1}
- _MainLightColor: {r: 1, g: 1, b: 1, a: 1}
- _MainLightDir: {r: 0, g: -1, b: 0, a: 0}
- _MaskOffset: {r: -0.23, g: -0.32, b: 0, a: 0}
- _NightColor: {r: 0.25, g: 0.28, b: 0.3, a: 1}
- _NoiseScrollSpeed: {r: 0.01, g: 0, b: 0.02, a: 0}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
- _UserMainLightColor: {r: 1, g: 1, b: 1, a: 1}
- _UserMainLightDir: {r: 0, g: -1, b: 0, a: 0}
m_BuildTextureStacks: []
m_AllowLocking: 1
--- !u!114 &6285378627783397592
MonoBehaviour:
m_ObjectHideFlags: 11
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
m_Name:
m_EditorClassIdentifier:
version: 9

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6dad1b85c9bf7884e8a1671ebcd5d1ab
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

After

Width:  |  Height:  |  Size: 199 KiB

View File

@@ -0,0 +1,117 @@
fileFormatVersion: 2
guid: ded807eef54675f4aaf8a4d8418d4d69
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 13
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 0
platformSettings:
- serializedVersion: 4
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
customData:
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spriteCustomMetadata:
entries: []
nameFileIdTable: {}
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,4 +1,4 @@
Shader "Custom/UniversalLiquidSurface_Simplified"
Shader "Custom/UniversalLiquidSurface"
{
Properties
{
@@ -27,7 +27,7 @@ Shader "Custom/UniversalLiquidSurface_Simplified"
_FoamStrength ("Foam Strength", Range(0,2)) = 0.6
_FoamBias ("Foam Bias", Range(-1,1)) = 0.0
// NEW: UV scroll speeds
// UV scroll speeds
_WaterNormal1Speed ("Normal Map 1 Speed (X,Y)", Vector) = (0.05, 0.0, 0, 0)
_WaterNormal2Speed ("Normal Map 2 Speed (X,Y)", Vector) = (0.0, -0.03, 0, 0)
_FoamScrollSpeed ("Foam Scroll Speed (X,Y)", Vector) = (0.02, 0.01, 0, 0)
@@ -44,7 +44,7 @@ Shader "Custom/UniversalLiquidSurface_Simplified"
_LavaCrackGlow ("Lava Crack Glow Strength", Float) = 0.8
_LavaEdgeGlow ("Lava Edge Glow Strength", Float) = 0.5
// Procedural bubbles
// Procedural bubbles - coś nie bangla
_BubbleDensity ("Bubble Density", Float) = 8.0
_BubbleFlow ("Bubble Flow Speed", Float) = 0.5
_BubbleStrength ("Bubble Strength", Float) = 1.5
@@ -104,7 +104,7 @@ Shader "Custom/UniversalLiquidSurface_Simplified"
float4 _NormalMap_ST;
float4 _FoamTex_ST;
// Params
// Parameters
float4 _BaseColor;
float _SurfaceType;
@@ -163,7 +163,7 @@ Shader "Custom/UniversalLiquidSurface_Simplified"
return d2-d1;
}
// Gerstner
// Gerstner, śmieszna nazwa
void GerstnerSimple(float2 dir, float amp, float len, float spd, float2 xz, float t, out float3 disp, out float3 nContrib)
{
float2 D = normalize(dir);