[A] reflection prob and refraction

This commit is contained in:
2024-07-19 11:17:16 +08:00
parent bf81a0898f
commit 3c7193cedd
13 changed files with 93 additions and 42 deletions

View File

@@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.17885353, g: 0.22394334, b: 0.3057996, a: 1}
m_IndirectSpecularColor: {r: 0.4410972, g: 0.48978937, b: 0.57004404, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
@@ -756,10 +756,15 @@ PrefabInstance:
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2604673031230735868, guid: 47f79802adc54954898ae8c7d6a674e9,
type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3692584872512927477, guid: 47f79802adc54954898ae8c7d6a674e9,
type: 3}
propertyPath: m_IsActive
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4065199434944052237, guid: 47f79802adc54954898ae8c7d6a674e9,
type: 3}
@@ -779,37 +784,42 @@ PrefabInstance:
- target: {fileID: 4075022403846284307, guid: 47f79802adc54954898ae8c7d6a674e9,
type: 3}
propertyPath: m_LocalRotation.w
value: 0.8862036
value: -0.75348014
objectReference: {fileID: 0}
- target: {fileID: 4075022403846284307, guid: 47f79802adc54954898ae8c7d6a674e9,
type: 3}
propertyPath: m_LocalRotation.x
value: 0.46329606
value: -0.41926923
objectReference: {fileID: 0}
- target: {fileID: 4075022403846284307, guid: 47f79802adc54954898ae8c7d6a674e9,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
value: -0.2508574
objectReference: {fileID: 0}
- target: {fileID: 4075022403846284307, guid: 47f79802adc54954898ae8c7d6a674e9,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
value: 0.4399448
objectReference: {fileID: 0}
- target: {fileID: 4075022403846284307, guid: 47f79802adc54954898ae8c7d6a674e9,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 55.2
value: 58.49
objectReference: {fileID: 0}
- target: {fileID: 4075022403846284307, guid: 47f79802adc54954898ae8c7d6a674e9,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4075022403846284307, guid: 47f79802adc54954898ae8c7d6a674e9,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
value: 300
objectReference: {fileID: 0}
- target: {fileID: 5300509538440423651, guid: 47f79802adc54954898ae8c7d6a674e9,
type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6931138432903229757, guid: 47f79802adc54954898ae8c7d6a674e9,
type: 3}

View File

@@ -19,8 +19,8 @@ MonoBehaviour:
m_RendererDataList:
- {fileID: 11400000, guid: c40be3174f62c4acf8c1216858c64956, type: 2}
m_DefaultRendererIndex: 0
m_RequireDepthTexture: 0
m_RequireOpaqueTexture: 0
m_RequireDepthTexture: 1
m_RequireOpaqueTexture: 1
m_OpaqueDownsampling: 1
m_SupportsTerrainHoles: 1
m_SupportsHDR: 1

View File

@@ -11,8 +11,8 @@ ScriptedImporter:
waterMesh:
shape: 0
scale: 100
vertexDistance: 1
UVTiling: 2
vertexDistance: 2
UVTiling: 1
noise: 0
boundsPadding: 4
mesh: {fileID: -8670151273213183110, guid: 154c6496b574b495eaf1e56696d041c5, type: 3}

View File

@@ -90,8 +90,8 @@ Material:
- _ClearCoatSmoothness: 0
- _Cull: 2
- _Cutoff: 0.5
- _DepthHorizontal: 1.34
- _DepthVertical: 10.83
- _DepthHorizontal: 1.47
- _DepthVertical: 5.99
- _DetailAlbedoMapScale: 1
- _DetailNormalMapScale: 1
- _DstBlend: 0
@@ -101,16 +101,20 @@ Material:
- _GlossMapScale: 0
- _Glossiness: 0
- _GlossyReflections: 0
- _HorizonDistance: 21.27
- _HorizonDistance: 20.6
- _Metallic: 0
- _OcclusionStrength: 1
- _Parallax: 0.005
- _QueueOffset: 0
- _ReceiveShadows: 1
- _ReflectionBlur: 0.012
- _ReflectionFresnel: 3.01
- _ReflectionStrength: 0.909
- _RefractionStrength: 0.332
- _Smoothness: 0.5
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _Speed: 1
- _Speed: 3.49
- _SrcBlend: 1
- _SrcBlendAlpha: 1
- _Surface: 0
@@ -119,24 +123,24 @@ Material:
- _TranslucencyReflectionMask: 0.747
- _TranslucencyStrength: 1.03
- _TranslucencyStrengthDirect: 0.07
- _WaveCount: 3
- _WaveDistance: 0.747
- _WaveHeight: 0.46
- _WaveNormalStr: 0.5
- _WaveCount: 2
- _WaveDistance: 0.759
- _WaveHeight: 0.16
- _WaveNormalStr: 0.2
- _WaveSpeed: 1
- _WaveSteepness: 2.24
- _WaveSteepness: 3.17
- _WorkflowMode: 1
- _ZWrite: 1
m_Colors:
- _BaseColor: {r: 0.0133944545, g: 0.20659995, b: 0.4056604, a: 0.84705883}
- _BaseColor: {r: 0.1254902, g: 0.2901961, b: 0.34509805, a: 1}
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _Direction: {r: 1, g: 1, b: 0, a: 0}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _HorizonColor: {r: 0.09376113, g: 0.18046764, b: 0.46226418, a: 0.95686275}
- _ShallowColor: {r: 0.07943218, g: 0.5314412, b: 0.8018868, a: 0.79607844}
- _HorizonColor: {r: 0.09376113, g: 0.10980392, b: 0.32156864, a: 0.95686275}
- _ShallowColor: {r: 0.105882354, g: 0.4117647, b: 0.62352943, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
- _WaveDirection: {r: 1, g: 1, b: 1, a: 2}
- _WaveFadeDistance: {r: 50, g: 81.68, b: 0, a: 0}
- _WaveFadeDistance: {r: 0, g: 200, b: 0, a: 0}
m_BuildTextureStacks: []
--- !u!114 &1635733923474585344
MonoBehaviour:

View File

@@ -29,6 +29,9 @@ struct WaterSurface
float alpha;
float fog;
float edgeFade;
float3 reflections;
float reflectionMask;
};
struct SceneDepth
@@ -44,13 +47,11 @@ struct SceneDepth
#define DEPTH_SCALAR (FAR_CLIP - NEAR_CLIP)
//Return depth based on the used technique (buffer, vertex color, baked texture)
SceneDepth SampleDepth(float4 positionNDC)
SceneDepth SampleDepth(float2 uv)
{
SceneDepth depth = (SceneDepth)0;
positionNDC.xy /= positionNDC.w;
float raw = SampleSceneDepth(positionNDC.xy);
float raw = SampleSceneDepth(uv);
depth.raw = raw;
depth.eye = LinearEyeDepth(raw, _ZBufferParams);
depth.linear01 = Linear01Depth(raw, _ZBufferParams) * DEPTH_SCALAR;

View File

@@ -12,15 +12,16 @@ struct SceneData
void PopulateSceneData(inout SceneData scene, in Varyings input, in WaterSurface water)
{
const float2 screenPos = input.positionNDC.xy / input.positionNDC.w;
scene.positionNDC = input.positionNDC;
scene.screenPos = input.positionNDC.xy / input.positionNDC.w;
scene.screenPos = screenPos;
//Default for disabled depth texture
scene.viewDepth = 1;
scene.verticalDepth = 1;
//Screen depth Projection to world position
SceneDepth depth = SampleDepth(input.positionNDC);
SceneDepth depth = SampleDepth(screenPos);
float3 projWorldPos = depth.eye * (water.viewDelta / input.positionNDC.w) - _WorldSpaceCameraPos;
scene.positionWS = -projWorldPos;
@@ -31,7 +32,8 @@ void PopulateSceneData(inout SceneData scene, in Varyings input, in WaterSurface
//Distance to opaque geometry in normal direction
scene.verticalDepth = length((water.positionWS - scene.positionWS) * water.vertexNormal);
//scene.verticalDepth = DepthDistance(water.positionWS, scene.positionWS, water.waveNormal * normalSign);
scene.color = SampleSceneColor(screenPos + input.normalWS.xz * 0.5 * _RefractionStrength);
}
float GetWaterDensity(SceneData scene, float heightScalar, float viewDepthScalar)
@@ -86,7 +88,9 @@ float4 ForwardPassFragment(Varyings input) : SV_Target
PopulateSceneData(scene, input, water);
//return float4(scene.verticalDepth.xxx, 1);
//return float4(scene.verticalDepth.xxx, 0.7);
//return float4(scene.viewDepth.xxx, 0.7);
//return float4(scene.color, 1);
water.fog = GetWaterDensity(scene, _DepthHorizontal, _DepthVertical);
@@ -104,6 +108,23 @@ float4 ForwardPassFragment(Varyings input) : SV_Target
water.alpha *= water.edgeFade;
/* ========
// Reflection Prob
=========== */
half3 reflectionVector = reflect(-water.viewDir, normalWS);
water.reflections = GlossyEnvironmentReflection(reflectionVector, water.positionWS, _ReflectionBlur, 1 ,scene.screenPos.xy);
//Schlick's BRDF fresnel AIR_RI = 1.000293
float cosTheta = saturate(dot(normalWS, water.viewDir));
water.reflectionMask = pow(max(0.0, 1.000293 - cosTheta), _ReflectionFresnel) * _ReflectionStrength;
water.albedo = lerp(water.albedo, water.reflections.rgb, water.reflectionMask);
/* ========
// Refraction Prob
=========== */
/* ========
// TRANSLUCENCY
@@ -152,9 +173,10 @@ float4 ForwardPassFragment(Varyings input) : SV_Target
inputData.shadowMask = 0;//shadowMask;
float4 finalColor = float4(ApplyLighting(surfaceData, scene.color, mainLight, inputData, water, translucencyData), water.alpha);
float3 finalColor = ApplyLighting(surfaceData, mainLight, inputData, water, translucencyData);
finalColor = lerp(scene.color, finalColor, 0.7);
return finalColor;
// return float4(water.albedo, water.alpha);
return float4(finalColor, water.alpha);
}

View File

@@ -18,6 +18,11 @@ CBUFFER_START(UnityPerMaterial)
half _TranslucencyExp;
half _TranslucencyCurvatureMask;
float _ReflectionBlur;
float _ReflectionFresnel;
float _ReflectionStrength;
float _RefractionStrength;
//Waves

View File

@@ -31,7 +31,7 @@ void ApplyTranslucency(float3 subsurfaceColor, float3 lightDir, float3 lightColo
//Based on UniversalFragmentBlinnPhong (no BRDF)
float3 ApplyLighting(inout SurfaceData surfaceData, inout float3 sceneColor, Light mainLight, InputData inputData, WaterSurface water, TranslucencyData translucencyData)
float3 ApplyLighting(inout SurfaceData surfaceData, Light mainLight, InputData inputData, WaterSurface water, TranslucencyData translucencyData)
{
ApplyTranslucency(translucencyData.subsurfaceColor, mainLight.direction, mainLight.color, water.viewDir, water.vertexNormal, translucencyData.mask, translucencyData.strength, translucencyData.strengthIncident, translucencyData.exponent, translucencyData.curvature, surfaceData.emission.rgb );

View File

@@ -49,6 +49,9 @@ Varyings LitPassVertex(Attributes input)
//WaveInfo waves = GetWaveInfo(uv, TIME_VERTEX * _WaveSpeed, _WaveHeight, lerp(1, 0, vertexColor.b), _WaveFadeDistance.x, _WaveFadeDistance.y);
WaveInfo waves = GetWaveInfo(uv, TIME_VERTEX * _WaveSpeed, _WaveHeight, 1, _WaveFadeDistance.x, _WaveFadeDistance.y);
//waves.normal = normalInput.normalWS;
//waves.position = 0;
//Apply vertex displacements
positionWS += waves.position.xyz;

View File

@@ -20,6 +20,12 @@ Shader "zzwater/ocean"
_TranslucencyCurvatureMask("Translucency Curvature mask", Range(0, 1)) = 0.75
_TranslucencyReflectionMask("Translucency Reflection mask", Range(0, 1)) = 1
_ReflectionStrength("Reflection Strength", Range(0, 1)) = 1
_ReflectionBlur("Probe Blur Factor", Range(0, 1)) = 0
_ReflectionFresnel("Reflection Curvature mask", Range(0.01, 20)) = 5
_RefractionStrength("Refraction Strength", Range(0, 1)) = 0.1
//waves
_WaveSpeed("Speed", Float) = 2

View File

@@ -59,7 +59,7 @@ GraphicsSettings:
m_FogKeepExp: 1
m_FogKeepExp2: 1
m_AlbedoSwatchInfos: []
m_LightsUseLinearIntensity: 1
m_LightsUseLinearIntensity: 0
m_LightsUseColorTemperature: 1
m_DefaultRenderingLayerMask: 1
m_LogWhenShaderIsCompiled: 0

View File

@@ -47,7 +47,7 @@ PlayerSettings:
defaultScreenWidthWeb: 960
defaultScreenHeightWeb: 600
m_StereoRenderingPath: 0
m_ActiveColorSpace: 1
m_ActiveColorSpace: 0
unsupportedMSAAFallback: 0
m_SpriteBatchVertexThreshold: 300
m_MTRendering: 1

View File

@@ -4,7 +4,7 @@
QualitySettings:
m_ObjectHideFlags: 0
serializedVersion: 5
m_CurrentQuality: 0
m_CurrentQuality: 1
m_QualitySettings:
- serializedVersion: 3
name: Performant
@@ -83,7 +83,7 @@ QualitySettings:
realtimeGICPUUsage: 25
lodBias: 1
maximumLODLevel: 0
enableLODCrossFade: 1
enableLODCrossFade: 0
streamingMipmapsActive: 0
streamingMipmapsAddAllCameras: 1
streamingMipmapsMemoryBudget: 512