[M] simplifiy ocean shader
This commit is contained in:
@@ -38,7 +38,7 @@ RenderSettings:
|
||||
m_ReflectionIntensity: 1
|
||||
m_CustomReflection: {fileID: 0}
|
||||
m_Sun: {fileID: 0}
|
||||
m_IndirectSpecularColor: {r: 0.4410972, g: 0.48978937, b: 0.57004404, a: 1}
|
||||
m_IndirectSpecularColor: {r: 0.4412511, g: 0.49000543, b: 0.57021886, a: 1}
|
||||
m_UseRadianceAmbientProbe: 0
|
||||
--- !u!157 &3
|
||||
LightmapSettings:
|
||||
@@ -200,7 +200,7 @@ Transform:
|
||||
m_GameObject: {fileID: 77912383}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 24, y: -2.4, z: 56}
|
||||
m_LocalPosition: {x: 24, y: -2.5, z: 56}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
@@ -761,6 +761,11 @@ PrefabInstance:
|
||||
propertyPath: m_IsActive
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3237648003214109488, guid: 47f79802adc54954898ae8c7d6a674e9,
|
||||
type: 3}
|
||||
propertyPath: m_IsActive
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3692584872512927477, guid: 47f79802adc54954898ae8c7d6a674e9,
|
||||
type: 3}
|
||||
propertyPath: m_IsActive
|
||||
@@ -784,27 +789,27 @@ PrefabInstance:
|
||||
- target: {fileID: 4075022403846284307, guid: 47f79802adc54954898ae8c7d6a674e9,
|
||||
type: 3}
|
||||
propertyPath: m_LocalRotation.w
|
||||
value: -0.75348014
|
||||
value: -0.75529873
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 4075022403846284307, guid: 47f79802adc54954898ae8c7d6a674e9,
|
||||
type: 3}
|
||||
propertyPath: m_LocalRotation.x
|
||||
value: -0.41926923
|
||||
value: -0.41602525
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 4075022403846284307, guid: 47f79802adc54954898ae8c7d6a674e9,
|
||||
type: 3}
|
||||
propertyPath: m_LocalRotation.y
|
||||
value: -0.2508574
|
||||
value: -0.24900545
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 4075022403846284307, guid: 47f79802adc54954898ae8c7d6a674e9,
|
||||
type: 3}
|
||||
propertyPath: m_LocalRotation.z
|
||||
value: 0.4399448
|
||||
value: 0.44095713
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 4075022403846284307, guid: 47f79802adc54954898ae8c7d6a674e9,
|
||||
type: 3}
|
||||
propertyPath: m_LocalEulerAnglesHint.x
|
||||
value: 58.49
|
||||
value: 58
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 4075022403846284307, guid: 47f79802adc54954898ae8c7d6a674e9,
|
||||
type: 3}
|
||||
|
||||
@@ -90,18 +90,18 @@ Material:
|
||||
- _ClearCoatSmoothness: 0
|
||||
- _Cull: 2
|
||||
- _Cutoff: 0.5
|
||||
- _DepthHorizontal: 1.47
|
||||
- _DepthVertical: 5.99
|
||||
- _DepthHorizontal: 2.36
|
||||
- _DepthVertical: 7.44
|
||||
- _DetailAlbedoMapScale: 1
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DstBlend: 0
|
||||
- _DstBlendAlpha: 0
|
||||
- _EdgeFade: 8.34
|
||||
- _EdgeFade: 19.08
|
||||
- _EnvironmentReflections: 1
|
||||
- _GlossMapScale: 0
|
||||
- _Glossiness: 0
|
||||
- _GlossyReflections: 0
|
||||
- _HorizonDistance: 20.6
|
||||
- _HorizonDistance: 26.6
|
||||
- _Metallic: 0
|
||||
- _OcclusionStrength: 1
|
||||
- _Parallax: 0.005
|
||||
@@ -109,25 +109,25 @@ Material:
|
||||
- _ReceiveShadows: 1
|
||||
- _ReflectionBlur: 0.012
|
||||
- _ReflectionFresnel: 3.01
|
||||
- _ReflectionStrength: 0.909
|
||||
- _RefractionStrength: 0.332
|
||||
- _ReflectionStrength: 0.913
|
||||
- _RefractionStrength: 0.415
|
||||
- _Smoothness: 0.5
|
||||
- _SmoothnessTextureChannel: 0
|
||||
- _SpecularHighlights: 1
|
||||
- _Speed: 3.49
|
||||
- _Speed: 1
|
||||
- _SrcBlend: 1
|
||||
- _SrcBlendAlpha: 1
|
||||
- _Surface: 0
|
||||
- _TranslucencyCurvatureMask: 0.584
|
||||
- _TranslucencyExp: 15.3
|
||||
- _TranslucencyReflectionMask: 0.747
|
||||
- _TranslucencyStrength: 1.03
|
||||
- _TranslucencyStrengthDirect: 0.07
|
||||
- _TranslucencyCurvatureMask: 0.708
|
||||
- _TranslucencyExp: 10
|
||||
- _TranslucencyReflectionMask: 0.764
|
||||
- _TranslucencyStrength: 0.7
|
||||
- _TranslucencyStrengthDirect: 0.411
|
||||
- _WaveCount: 2
|
||||
- _WaveDistance: 0.759
|
||||
- _WaveHeight: 0.16
|
||||
- _WaveDistance: 0.66
|
||||
- _WaveHeight: 0.17
|
||||
- _WaveNormalStr: 0.2
|
||||
- _WaveSpeed: 1
|
||||
- _WaveSpeed: 0.88
|
||||
- _WaveSteepness: 3.17
|
||||
- _WorkflowMode: 1
|
||||
- _ZWrite: 1
|
||||
|
||||
@@ -38,9 +38,6 @@ void PopulateSceneData(inout SceneData scene, in Varyings input, in WaterSurface
|
||||
|
||||
float GetWaterDensity(SceneData scene, float heightScalar, float viewDepthScalar)
|
||||
{
|
||||
//Best default value, otherwise water just turns invisible (infinitely shallow)
|
||||
float density = 1.0;
|
||||
|
||||
float viewDepth = scene.viewDepth;
|
||||
float verticalDepth = scene.verticalDepth;
|
||||
|
||||
@@ -64,24 +61,15 @@ float4 ForwardPassFragment(Varyings input) : SV_Target
|
||||
water.alpha = 1.0;
|
||||
water.positionWS = positionWS;
|
||||
water.viewDelta = _WorldSpaceCameraPos - positionWS;
|
||||
water.viewDir = normalize(water.viewDelta);
|
||||
float3 viewDir = normalize(water.viewDelta);
|
||||
water.viewDir = viewDir;
|
||||
water.vertexNormal = normalize(input.normalWS.xyz);
|
||||
|
||||
//Normal
|
||||
water.tangentNormal = float3(0.5, 0.5, 1);
|
||||
water.tangentWorldNormal = normalWS;
|
||||
|
||||
//Tangent-space
|
||||
//water.tangentNormal = SampleNormals(uv, _NormalTiling, _NormalSubTiling, positionWS, TIME, _NormalSpeed, _NormalSubSpeed, water.slope, water.vFace);
|
||||
|
||||
//Based on wave normal, makes it easier to create blend between the smooth wave normals and high-frequency normal maps
|
||||
//water.tangentToWorldMatrix = half3x3(WorldTangent, WorldBiTangent, water.waveNormal);
|
||||
|
||||
//World-space
|
||||
//water.tangentWorldNormal = normalize(TransformTangentToWorld(water.tangentNormal, water.tangentToWorldMatrix));
|
||||
|
||||
half VdotN = 1.0 - saturate(dot(water.viewDir, normalWS));
|
||||
|
||||
half VdotN = 1.0 - saturate(dot(viewDir, normalWS));
|
||||
half4 shadowMask = 1.0;
|
||||
float4 shadowCoords = float4(0, 0, 0, 0);
|
||||
Light mainLight = GetMainLight(shadowCoords, water.positionWS, shadowMask);
|
||||
@@ -112,71 +100,45 @@ float4 ForwardPassFragment(Varyings input) : SV_Target
|
||||
// Reflection Prob
|
||||
=========== */
|
||||
|
||||
half3 reflectionVector = reflect(-water.viewDir, normalWS);
|
||||
half3 reflectionVector = reflect(-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));
|
||||
float cosTheta = saturate(dot(normalWS, viewDir));
|
||||
water.reflectionMask = pow(max(0.0, 1.000293 - cosTheta), _ReflectionFresnel) * _ReflectionStrength;
|
||||
|
||||
water.albedo = lerp(water.albedo, water.reflections.rgb, water.reflectionMask);
|
||||
|
||||
/* ========
|
||||
// Refraction Prob
|
||||
=========== */
|
||||
|
||||
// =================== Make ApplyLight simple =========================
|
||||
|
||||
/* ========
|
||||
// TRANSLUCENCY
|
||||
=========== */
|
||||
TranslucencyData translucencyData = (TranslucencyData)0;
|
||||
float scatteringMask = 1.0;
|
||||
scatteringMask = saturate(water.fog + water.edgeFade);
|
||||
//scatteringMask = saturate((water.fog + water.edgeFade) - (water.reflectionMask * water.vFace)) * water.shadowMask;
|
||||
//scatteringMask -= water.foam;
|
||||
//scatteringMask = saturate(scatteringMask);
|
||||
translucencyData.subsurfaceColor = _ShallowColor.rgb;
|
||||
//translucencyData.lightColor = mainLight.color;
|
||||
//translucencyData.lightDir = mainLight.direction;
|
||||
// =====Translucency Begin========
|
||||
float3 lightDir = mainLight.direction;
|
||||
float3 lightColor = mainLight.color;
|
||||
float3 emission = 0;
|
||||
float3 specular = 0;
|
||||
|
||||
//translucencyData.normal = normalWS;
|
||||
translucencyData.curvature = _TranslucencyCurvatureMask;
|
||||
translucencyData.mask = scatteringMask;
|
||||
translucencyData.strength = _TranslucencyStrength;
|
||||
translucencyData.strengthIncident = _TranslucencyStrengthDirect;
|
||||
//translucencyData.viewDir = water.viewDir;
|
||||
translucencyData.exponent = _TranslucencyExp;
|
||||
float scatteringMask = saturate(water.fog + water.edgeFade);
|
||||
|
||||
half incident = saturate(dot(lightDir, normalWS)) * _TranslucencyStrengthDirect;
|
||||
|
||||
/* ========
|
||||
// UNITY SURFACE & INPUT DATA
|
||||
=========== */
|
||||
SurfaceData surfaceData = (SurfaceData)0;
|
||||
const float lightIntensity = lightColor.r * 0.3 + lightColor.g * 0.59 + lightColor.b * 0.11;
|
||||
|
||||
surfaceData.albedo = water.albedo.rgb;
|
||||
surfaceData.specular = 0;// water.specular.rgb;
|
||||
surfaceData.metallic = 0;
|
||||
surfaceData.smoothness = 0;
|
||||
surfaceData.normalTS = water.tangentNormal;
|
||||
surfaceData.emission = 0; //To be populated with translucency+caustics
|
||||
surfaceData.occlusion = 1.0;
|
||||
surfaceData.alpha = water.alpha;
|
||||
half attenuation = (incident) * scatteringMask * lightIntensity;
|
||||
|
||||
InputData inputData = (InputData)0;
|
||||
inputData.positionWS = positionWS;
|
||||
inputData.viewDirectionWS = water.viewDir;
|
||||
inputData.shadowCoord = shadowCoords;
|
||||
inputData.normalWS = water.tangentWorldNormal;
|
||||
inputData.fogCoord = 0;//InitializeInputDataFog(float4(positionWS, 1.0), input.fogFactorAndVertexLight.x);
|
||||
inputData.vertexLighting = 0;//input.fogFactorAndVertexLight.yzw;
|
||||
inputData.bakedGI = 0;
|
||||
inputData.shadowMask = 0;//shadowMask;
|
||||
emission += lerp(emission, _ShallowColor.rgb, attenuation);
|
||||
|
||||
// =====Translucency End========
|
||||
|
||||
float3 finalColor = ApplyLighting(surfaceData, mainLight, inputData, water, translucencyData);
|
||||
// LightingLambert Light applied here
|
||||
half3 attenuatedLightColor = lightColor * (mainLight.distanceAttenuation * mainLight.shadowAttenuation);
|
||||
half3 diffuseColor = LightingLambert(attenuatedLightColor, lightDir, normalWS);
|
||||
|
||||
finalColor = lerp(scene.color, finalColor, 0.7);
|
||||
float3 finalColor = (water.albedo * diffuseColor) + emission + specular;
|
||||
|
||||
// =================== Make ApplyLight simple =========================
|
||||
|
||||
finalColor = lerp(scene.color, finalColor, water.fog);
|
||||
|
||||
return float4(finalColor, water.alpha);
|
||||
}
|
||||
|
||||
@@ -13,10 +13,7 @@ CBUFFER_START(UnityPerMaterial)
|
||||
float _DepthHorizontal;
|
||||
half _EdgeFade;
|
||||
|
||||
half _TranslucencyStrength;
|
||||
half _TranslucencyStrengthDirect;
|
||||
half _TranslucencyExp;
|
||||
half _TranslucencyCurvatureMask;
|
||||
|
||||
float _ReflectionBlur;
|
||||
float _ReflectionFresnel;
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
|
||||
struct TranslucencyData
|
||||
{
|
||||
float3 subsurfaceColor;
|
||||
float curvature;
|
||||
float mask; //Actually the 'thickness'
|
||||
float strength;
|
||||
float strengthIncident;
|
||||
float exponent;
|
||||
};
|
||||
|
||||
void ApplyTranslucency(float3 subsurfaceColor, float3 lightDir, float3 lightColor, float3 viewDir, float3 normal, float occlusion, float strength, float incidentStrength, float exponent, float offset, inout float3 emission)
|
||||
{
|
||||
//Coefficient describing how much the surface orientation is between the camera and the direction of/to the light
|
||||
half transmittance = saturate(dot(-viewDir, lightDir));
|
||||
//Exponentiate to tighten the falloff
|
||||
transmittance = saturate(pow(transmittance, exponent)) * strength;
|
||||
|
||||
half incident = saturate(dot(lightDir, normal)) * incidentStrength;
|
||||
|
||||
//Mask by normals facing away from the light (backfaces, in light-space)
|
||||
const half curvature = saturate(lerp(1.0, dot(normal, -lightDir), offset));
|
||||
transmittance *= curvature;
|
||||
|
||||
const float lightIntensity = lightColor.r * 0.3 + lightColor.g * 0.59 + lightColor.b * 0.11;
|
||||
|
||||
half attenuation = (transmittance + incident) * occlusion * lightIntensity;
|
||||
|
||||
emission += lerp(emission, subsurfaceColor, attenuation);
|
||||
}
|
||||
|
||||
|
||||
//Based on UniversalFragmentBlinnPhong (no BRDF)
|
||||
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 );
|
||||
|
||||
half3 attenuatedLightColor = mainLight.color * (mainLight.distanceAttenuation * mainLight.shadowAttenuation);
|
||||
half3 diffuseColor = inputData.bakedGI + LightingLambert(attenuatedLightColor, mainLight.direction, water.vertexNormal);
|
||||
|
||||
float3 color = (surfaceData.albedo.rgb * diffuseColor) + surfaceData.emission.rgb + surfaceData.specular;
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cf5941ae7f85e4b30bab818d47e3a79b
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -14,11 +14,7 @@ Shader "zzwater/ocean"
|
||||
_DepthHorizontal("Vertical Height Depth", Range(0.01 , 8)) = 1
|
||||
_EdgeFade("Edge Fade", Float) = 0.1
|
||||
|
||||
_TranslucencyStrength("Translucency Strength", Range(0 , 3)) = 1
|
||||
_TranslucencyStrengthDirect("Translucency Strength (Direct)", Range(0 , 0.5)) = 0.05
|
||||
_TranslucencyExp("Translucency Exponent", Range(1 , 32)) = 4
|
||||
_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
|
||||
@@ -74,7 +70,6 @@ Shader "zzwater/ocean"
|
||||
#include "Packages/zzwater/shaders/libs/Input.hlsl"
|
||||
#include "Packages/zzwater/shaders/libs/Waves.hlsl"
|
||||
#include "Packages/zzwater/shaders/libs/Vertex.hlsl"
|
||||
#include "Packages/zzwater/shaders/libs/Light.hlsl"
|
||||
|
||||
#pragma vertex Vertex
|
||||
|
||||
|
||||
Reference in New Issue
Block a user