浏览代码

Merge branch 'feature/infinite-sea' of github.com:Unity-Technologies/BoatAttack into feature/infinite-sea

# Conflicts:
#	Packages/com.verasl.water-system/Shaders/InfiniteWater.shader
/feature-infinite-sea
André McGrail 4 年前
当前提交
9563496c
共有 4 个文件被更改,包括 182 次插入26 次删除
  1. 144
      Assets/scenes/Testing/InfiniteWater.unity
  2. 2
      Packages/com.verasl.water-system/Shaders/InfiniteWater.shader
  3. 42
      Packages/com.verasl.water-system/Shaders/WaterCommon.hlsl
  4. 20
      Packages/com.verasl.water-system/Shaders/WaterLighting.hlsl

144
Assets/scenes/Testing/InfiniteWater.unity


m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 322090437}
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1001 &337970705
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 8993800107570090065, guid: 405c4bc591de844a3a100e1538790229,
type: 3}
propertyPath: m_Materials.Array.size
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8994039904032558531, guid: 405c4bc591de844a3a100e1538790229,
type: 3}
propertyPath: m_Materials.Array.size
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8994085050065515947, guid: 405c4bc591de844a3a100e1538790229,
type: 3}
propertyPath: m_Materials.Array.size
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8994587504260833689, guid: 405c4bc591de844a3a100e1538790229,
type: 3}
propertyPath: m_Materials.Array.size
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8994604808859007103, guid: 405c4bc591de844a3a100e1538790229,
type: 3}
propertyPath: m_Materials.Array.size
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8995542815361017601, guid: 405c4bc591de844a3a100e1538790229,
type: 3}
propertyPath: m_Materials.Array.size
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8995611058222461145, guid: 405c4bc591de844a3a100e1538790229,
type: 3}
propertyPath: m_Materials.Array.size
value: 1
objectReference: {fileID: 0}
- target: {fileID: 9080735299852188497, guid: 405c4bc591de844a3a100e1538790229,
type: 3}
propertyPath: m_RootOrder
value: 1
objectReference: {fileID: 0}
- target: {fileID: 9080735299852188497, guid: 405c4bc591de844a3a100e1538790229,
type: 3}
propertyPath: m_LocalPosition.x
value: -3.69
objectReference: {fileID: 0}
- target: {fileID: 9080735299852188497, guid: 405c4bc591de844a3a100e1538790229,
type: 3}
propertyPath: m_LocalPosition.y
value: 0.09
objectReference: {fileID: 0}
- target: {fileID: 9080735299852188497, guid: 405c4bc591de844a3a100e1538790229,
type: 3}
propertyPath: m_LocalPosition.z
value: 24.27
objectReference: {fileID: 0}
- target: {fileID: 9080735299852188497, guid: 405c4bc591de844a3a100e1538790229,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 9080735299852188497, guid: 405c4bc591de844a3a100e1538790229,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9080735299852188497, guid: 405c4bc591de844a3a100e1538790229,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9080735299852188497, guid: 405c4bc591de844a3a100e1538790229,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9080735299852188497, guid: 405c4bc591de844a3a100e1538790229,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9080735299852188497, guid: 405c4bc591de844a3a100e1538790229,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9080735299852188497, guid: 405c4bc591de844a3a100e1538790229,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9083998436884223129, guid: 405c4bc591de844a3a100e1538790229,
type: 3}
propertyPath: m_Name
value: _Interceptor
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 405c4bc591de844a3a100e1538790229, type: 3}
--- !u!1 &341762015
GameObject:
m_ObjectHideFlags: 0

- {fileID: 341762016}
- {fileID: 322090438}
m_Father: {fileID: 0}
m_RootOrder: 3
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &611616626
GameObject:

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!28 &952346665
Texture2D:

m_RequiresDepthTexture: 0
m_RequiresColorTexture: 0
m_Version: 2
--- !u!84 &1705656474
RenderTexture:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: WaterDepthMap
m_ImageContentsHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000
m_ForcedFallbackFormat: 4
m_DownscaleFallback: 0
m_IsAlphaChannelOptional: 0
serializedVersion: 3
m_Width: 1024
m_Height: 1024
m_AntiAliasing: 1
m_MipCount: -1
m_DepthFormat: 2
m_ColorFormat: 142
m_MipMap: 0
m_GenerateMips: 1
m_SRGB: 0
m_UseDynamicScale: 0
m_BindMS: 0
m_EnableCompatibleFormat: 1
m_TextureSettings:
serializedVersion: 2
m_FilterMode: 1
m_Aniso: 1
m_MipBias: 0
m_WrapU: 1
m_WrapV: 1
m_WrapW: 1
m_Dimension: 2
m_VolumeDepth: 1
--- !u!1001 &2012797122
PrefabInstance:
m_ObjectHideFlags: 0

2
Packages/com.verasl.water-system/Shaders/InfiniteWater.shader


}
}
FallBack "Hidden/InternalErrorShader"
}
}

42
Packages/com.verasl.water-system/Shaders/WaterCommon.hlsl


{
// Lighting
Light mainLight = GetMainLight(TransformWorldToShadowCoord(input.positionWS));
half shadow = SoftShadows(screenUV, input.positionWS);
half shadow = SoftShadows(screenUV, input.positionWS, input.viewDirectionWS, input.depth);
half3 GI = SampleSH(input.normalWS);
// SSS

return MixFog(output, input.fogCoord);
}
float WaterNearFade(float3 positionWS)
{
float3 camPos = GetCameraPositionWS();
camPos.y = 0;
return 1 - saturate((distance(positionWS, camPos) - 50) * 0.1);
}
///////////////////////////////////////////////////////////////////////////////
// Vertex and Fragment functions //
///////////////////////////////////////////////////////////////////////////////

InitializeSurfaceData(inputData, surfaceData);
half4 current;
current.a = 1;
current.a = WaterNearFade(IN.positionWS);
//return color;
return current;
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////

// Detail waves
DetailNormals(IN.normalWS, IN.uv, waterFX, depth.x);
// Distortion
half2 distortion = DistortionUVs(depth.x, IN.normalWS);
distortion = screenUV.xy + distortion;// * clamp(depth.x, 0, 5);
float d = depth.x;
depth.xz = AdjustedDepth(distortion, IN.additionalData);
distortion = depth.x < 0 ? screenUV.xy : distortion;
depth.x = depth.x < 0 ? d : depth.x;
// Fresnel
half fresnelTerm = CalculateFresnelTerm(IN.normalWS, IN.viewDirectionWS.xyz);
//return fresnelTerm.xxxx;
half shadow = SoftShadows(screenUV.xy, IN.positionWS);
half shadow = SoftShadows(screenUV, IN.positionWS, IN.viewDirectionWS.xyz, depth.x);
half3 GI = SampleSH(IN.normalWS);
// SSS

// Foam lighting
half3 foam = foamMask.xxx * (mainLight.shadowAttenuation * mainLight.color + GI);
// Distortion
half2 distortion = DistortionUVs(depth.x, IN.normalWS);
distortion = screenUV.xy + distortion;// * clamp(depth.x, 0, 5);
float d = depth.x;
depth.xz = AdjustedDepth(distortion, IN.additionalData); // only x y
distortion = depth.x < 0 ? screenUV.xy : distortion;
depth.x = depth.x < 0 ? d : depth.x;
// Fresnel
half fresnelTerm = CalculateFresnelTerm(IN.normalWS, IN.viewDirectionWS.xyz);
half3 spec = DirectBDRF(brdfData, IN.normalWS, mainLight.direction, IN.viewDirectionWS.xyz) * shadow * mainLight.color;
half3 spec = DirectBDRF(brdfData, IN.normalWS, mainLight.direction, IN.viewDirectionWS) * shadow * mainLight.color;
#ifdef _ADDITIONAL_LIGHTS
uint pixelLightCount = GetAdditionalLightsCount();
for (uint lightIndex = 0u; lightIndex < pixelLightCount; ++lightIndex)

#endif
}
#endif // WATER_COMMON_INCLUDED
#endif // WATER_COMMON_INCLUDED

20
Packages/com.verasl.water-system/Shaders/WaterLighting.hlsl


#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
#define SHADOW_ITERATIONS 4
half CalculateFresnelTerm(half3 normalWS, half3 viewDirectionWS)
{
return saturate(pow(1.0 - dot(normalWS, viewDirectionWS), 5));//fresnel TODO - find a better place

}
//Soft Shadows
half SoftShadows(float2 screenUV, float3 positionWS)
half SoftShadows(float2 screenUV, float3 positionWS, half3 viewDir, half depth)
#if _MAIN_LIGHT_SHADOWS
uint loop = 4;
float loopDiv = 1.0 / loop;
for (uint i = 0u; i < loop; ++i)
float loopDiv = 1.0 / SHADOW_ITERATIONS;
half depthFrac = depth * loopDiv;
half3 lightOffset = -viewDir * depthFrac;
for (uint i = 0u; i < SHADOW_ITERATIONS; ++i)
float3 lightJitter = positionWS + jitterTexture.xzy * 2;
half3 j = jitterTexture.xzy * depthFrac * i * 0.1;
float3 lightJitter = (positionWS + j) + (lightOffset * (i + jitterTexture.y));
#else
return 1;
#endif
}
///////////////////////////////////////////////////////////////////////////////

return reflection;
}
#endif // WATER_LIGHTING_INCLUDED
#endif // WATER_LIGHTING_INCLUDED
正在加载...
取消
保存