浏览代码

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

# Conflicts:
#	Assets/scenes/Testing/InfiniteWater.unity
/feature-infinite-sea
Andrem 4 年前
当前提交
30408e83
共有 5 个文件被更改,包括 614 次插入211 次删除
  1. 126
      Assets/scenes/Testing/InfiniteWater.unity
  2. 566
      Packages/com.verasl.water-system/Meshes/SeaVertDisp.fbx.meta
  3. 74
      Packages/com.verasl.water-system/Scripts/Rendering/WaterSystemFeature.cs
  4. 49
      Packages/com.verasl.water-system/Shaders/InfiniteWater.shader
  5. 10
      Packages/com.verasl.water-system/Shaders/WaterInput.hlsl

126
Assets/scenes/Testing/InfiniteWater.unity


objectReference: {fileID: 0}
- target: {fileID: 4554327062270080, guid: 2cac2e60f3f6f2447ad9b550450f60ed, type: 3}
propertyPath: m_RootOrder
value: 2
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4554327062270080, guid: 2cac2e60f3f6f2447ad9b550450f60ed, type: 3}
propertyPath: m_LocalPosition.x

- target: {fileID: 114943683913522278, guid: 2cac2e60f3f6f2447ad9b550450f60ed,
type: 3}
propertyPath: m_Enabled
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 114943683913522278, guid: 2cac2e60f3f6f2447ad9b550450f60ed,
type: 3}

m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 611616626}
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
--- !u!84 &752176023
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!1 &867751506
GameObject:
m_ObjectHideFlags: 0

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1326083684}
m_LocalRotation: {x: -0.013000863, y: -0.9098737, z: 0.028593907, w: -0.41369456}
m_LocalRotation: {x: -0.1071249, y: -0.8793044, z: 0.23560895, w: -0.3997955}
m_LocalEulerAnglesHint: {x: 3.6, y: -228.9, z: 0}
m_LocalEulerAnglesHint: {x: 30, y: -228.9, z: 0}
--- !u!84 &1392271128
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 &1617765646
PrefabInstance:
m_ObjectHideFlags: 0

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1704475455}
m_LocalRotation: {x: 0.2719544, y: -0.2764688, z: -0.49521503, w: 0.77741104}
m_LocalPosition: {x: 9.56, y: 13.44, z: -15.93}
m_LocalRotation: {x: 0.31865332, y: -0.22102997, z: -0.631237, w: 0.67167383}
m_LocalPosition: {x: 1.7, y: 27.83, z: 0}
m_LocalEulerAnglesHint: {x: 8.57, y: -45.000004, z: -68.55}
m_LocalEulerAnglesHint: {x: 8.57, y: -45.000004, z: -90}
--- !u!114 &1704475460
MonoBehaviour:
m_ObjectHideFlags: 0

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

objectReference: {fileID: 0}
- target: {fileID: 100000, guid: 0694fda6617df4cd6a3d240f5eeb580b, type: 3}
propertyPath: m_IsActive
value: 1
value: 0
value: 3
value: 2
objectReference: {fileID: 0}
- target: {fileID: 400000, guid: 0694fda6617df4cd6a3d240f5eeb580b, type: 3}
propertyPath: m_LocalScale.x

566
Packages/com.verasl.water-system/Meshes/SeaVertDisp.fbx.meta


fileFormatVersion: 2
guid: 074aa8ca109924e18baf19f3e26665b6
ModelImporter:
serializedVersion: 23
fileIDToRecycleName:
100000: //RootNode
100002: SeaVertDisp_center
100004: SeaVertDisp_far1
100006: SeaVertDisp_far2
100008: SeaVertDisp_far3
100010: SeaVertDisp_far4
100012: SeaVertDisp_mid1
100014: SeaVertDisp_mid2
100016: SeaVertDisp_mid3
100018: SeaVertDisp_mid4
100020: SeaVertDisp_near1
100022: SeaVertDisp_near2
100024: SeaVertDisp_near3
100026: SeaVertDisp_near4
100028: SeaVertDisp_outter1
100030: SeaVertDisp_outter2
100032: SeaVertDisp_outter3
100034: SeaVertDisp_outter4
100036: SeaDistant_01
100038: SeaDistant_02
100040: SeaDistant_03
100042: SeaDistant_04
100044: SeaDistant_01 (2)
100046: SeaDistant_02 (2)
100048: SeaDistant_03 (2)
100050: SeaDistant_04 (2)
400000: //RootNode
400002: SeaVertDisp_center
400004: SeaVertDisp_far1
400006: SeaVertDisp_far2
400008: SeaVertDisp_far3
400010: SeaVertDisp_far4
400012: SeaVertDisp_mid1
400014: SeaVertDisp_mid2
400016: SeaVertDisp_mid3
400018: SeaVertDisp_mid4
400020: SeaVertDisp_near1
400022: SeaVertDisp_near2
400024: SeaVertDisp_near3
400026: SeaVertDisp_near4
400028: SeaVertDisp_outter1
400030: SeaVertDisp_outter2
400032: SeaVertDisp_outter3
400034: SeaVertDisp_outter4
400036: SeaDistant_01
400038: SeaDistant_02
400040: SeaDistant_03
400042: SeaDistant_04
400044: SeaDistant_01 (2)
400046: SeaDistant_02 (2)
400048: SeaDistant_03 (2)
400050: SeaDistant_04 (2)
2100000: Default
2300000: //RootNode
2300002: SeaVertDisp_center
2300004: SeaVertDisp_far1
2300006: SeaVertDisp_far2
2300008: SeaVertDisp_far3
2300010: SeaVertDisp_far4
2300012: SeaVertDisp_mid1
2300014: SeaVertDisp_mid2
2300016: SeaVertDisp_mid3
2300018: SeaVertDisp_mid4
2300020: SeaVertDisp_near1
2300022: SeaVertDisp_near2
2300024: SeaVertDisp_near3
2300026: SeaVertDisp_near4
2300028: SeaVertDisp_outter1
2300030: SeaVertDisp_outter2
2300032: SeaVertDisp_outter3
2300034: SeaVertDisp_outter4
2300036: SeaDistant_01
2300038: SeaDistant_02
2300040: SeaDistant_03
2300042: SeaDistant_04
2300044: SeaDistant_01 (2)
2300046: SeaDistant_02 (2)
2300048: SeaDistant_03 (2)
2300050: SeaDistant_04 (2)
3300000: //RootNode
3300002: SeaVertDisp_center
3300004: SeaVertDisp_far1
3300006: SeaVertDisp_far2
3300008: SeaVertDisp_far3
3300010: SeaVertDisp_far4
3300012: SeaVertDisp_mid1
3300014: SeaVertDisp_mid2
3300016: SeaVertDisp_mid3
3300018: SeaVertDisp_mid4
3300020: SeaVertDisp_near1
3300022: SeaVertDisp_near2
3300024: SeaVertDisp_near3
3300026: SeaVertDisp_near4
3300028: SeaVertDisp_outter1
3300030: SeaVertDisp_outter2
3300032: SeaVertDisp_outter3
3300034: SeaVertDisp_outter4
3300036: SeaDistant_01
3300038: SeaDistant_02
3300040: SeaDistant_03
3300042: SeaDistant_04
3300044: SeaDistant_01 (2)
3300046: SeaDistant_02 (2)
3300048: SeaDistant_03 (2)
3300050: SeaDistant_04 (2)
4300000: SeaVertDisp
4300002: SeaVertDisp_outter4
4300004: SeaVertDisp_mid4
4300006: SeaVertDisp_mid3
4300008: SeaVertDisp_outter3
4300010: SeaVertDisp_outter1
4300012: SeaVertDisp_mid2
4300014: SeaVertDisp_mid1
4300016: SeaVertDisp_outter2
4300018: SeaVertDisp_far4
4300020: SeaVertDisp_far3
4300022: SeaVertDisp_far2
4300024: SeaVertDisp_far1
4300026: SeaVertDisp_center
4300028: SeaVertDisp_near4
4300030: SeaVertDisp_near3
4300032: SeaVertDisp_near2
4300034: SeaVertDisp_near1
4300036: SeaDistant_01
4300038: SeaDistant_02
4300040: SeaDistant_03
4300042: SeaDistant_04
4300044: SeaDistant_04 (2)
4300046: SeaDistant_03 (2)
4300048: SeaDistant_02 (2)
4300050: SeaDistant_01 (2)
7400000: Take 001
9500000: //RootNode
2186277476908879412: ImportLogs
serializedVersion: 20101
internalIDToNameTable:
- first:
1: 100000
second: //RootNode
- first:
1: 100002
second: SeaVertDisp_center
- first:
1: 100004
second: SeaVertDisp_far1
- first:
1: 100006
second: SeaVertDisp_far2
- first:
1: 100008
second: SeaVertDisp_far3
- first:
1: 100010
second: SeaVertDisp_far4
- first:
1: 100012
second: SeaVertDisp_mid1
- first:
1: 100014
second: SeaVertDisp_mid2
- first:
1: 100016
second: SeaVertDisp_mid3
- first:
1: 100018
second: SeaVertDisp_mid4
- first:
1: 100020
second: SeaVertDisp_near1
- first:
1: 100022
second: SeaVertDisp_near2
- first:
1: 100024
second: SeaVertDisp_near3
- first:
1: 100026
second: SeaVertDisp_near4
- first:
1: 100028
second: SeaVertDisp_outter1
- first:
1: 100030
second: SeaVertDisp_outter2
- first:
1: 100032
second: SeaVertDisp_outter3
- first:
1: 100034
second: SeaVertDisp_outter4
- first:
1: 100036
second: SeaDistant_01
- first:
1: 100038
second: SeaDistant_02
- first:
1: 100040
second: SeaDistant_03
- first:
1: 100042
second: SeaDistant_04
- first:
1: 100044
second: SeaDistant_01 (2)
- first:
1: 100046
second: SeaDistant_02 (2)
- first:
1: 100048
second: SeaDistant_03 (2)
- first:
1: 100050
second: SeaDistant_04 (2)
- first:
4: 400000
second: //RootNode
- first:
4: 400002
second: SeaVertDisp_center
- first:
4: 400004
second: SeaVertDisp_far1
- first:
4: 400006
second: SeaVertDisp_far2
- first:
4: 400008
second: SeaVertDisp_far3
- first:
4: 400010
second: SeaVertDisp_far4
- first:
4: 400012
second: SeaVertDisp_mid1
- first:
4: 400014
second: SeaVertDisp_mid2
- first:
4: 400016
second: SeaVertDisp_mid3
- first:
4: 400018
second: SeaVertDisp_mid4
- first:
4: 400020
second: SeaVertDisp_near1
- first:
4: 400022
second: SeaVertDisp_near2
- first:
4: 400024
second: SeaVertDisp_near3
- first:
4: 400026
second: SeaVertDisp_near4
- first:
4: 400028
second: SeaVertDisp_outter1
- first:
4: 400030
second: SeaVertDisp_outter2
- first:
4: 400032
second: SeaVertDisp_outter3
- first:
4: 400034
second: SeaVertDisp_outter4
- first:
4: 400036
second: SeaDistant_01
- first:
4: 400038
second: SeaDistant_02
- first:
4: 400040
second: SeaDistant_03
- first:
4: 400042
second: SeaDistant_04
- first:
4: 400044
second: SeaDistant_01 (2)
- first:
4: 400046
second: SeaDistant_02 (2)
- first:
4: 400048
second: SeaDistant_03 (2)
- first:
4: 400050
second: SeaDistant_04 (2)
- first:
21: 2100000
second: Default
- first:
23: 2300000
second: //RootNode
- first:
23: 2300002
second: SeaVertDisp_center
- first:
23: 2300004
second: SeaVertDisp_far1
- first:
23: 2300006
second: SeaVertDisp_far2
- first:
23: 2300008
second: SeaVertDisp_far3
- first:
23: 2300010
second: SeaVertDisp_far4
- first:
23: 2300012
second: SeaVertDisp_mid1
- first:
23: 2300014
second: SeaVertDisp_mid2
- first:
23: 2300016
second: SeaVertDisp_mid3
- first:
23: 2300018
second: SeaVertDisp_mid4
- first:
23: 2300020
second: SeaVertDisp_near1
- first:
23: 2300022
second: SeaVertDisp_near2
- first:
23: 2300024
second: SeaVertDisp_near3
- first:
23: 2300026
second: SeaVertDisp_near4
- first:
23: 2300028
second: SeaVertDisp_outter1
- first:
23: 2300030
second: SeaVertDisp_outter2
- first:
23: 2300032
second: SeaVertDisp_outter3
- first:
23: 2300034
second: SeaVertDisp_outter4
- first:
23: 2300036
second: SeaDistant_01
- first:
23: 2300038
second: SeaDistant_02
- first:
23: 2300040
second: SeaDistant_03
- first:
23: 2300042
second: SeaDistant_04
- first:
23: 2300044
second: SeaDistant_01 (2)
- first:
23: 2300046
second: SeaDistant_02 (2)
- first:
23: 2300048
second: SeaDistant_03 (2)
- first:
23: 2300050
second: SeaDistant_04 (2)
- first:
33: 3300000
second: //RootNode
- first:
33: 3300002
second: SeaVertDisp_center
- first:
33: 3300004
second: SeaVertDisp_far1
- first:
33: 3300006
second: SeaVertDisp_far2
- first:
33: 3300008
second: SeaVertDisp_far3
- first:
33: 3300010
second: SeaVertDisp_far4
- first:
33: 3300012
second: SeaVertDisp_mid1
- first:
33: 3300014
second: SeaVertDisp_mid2
- first:
33: 3300016
second: SeaVertDisp_mid3
- first:
33: 3300018
second: SeaVertDisp_mid4
- first:
33: 3300020
second: SeaVertDisp_near1
- first:
33: 3300022
second: SeaVertDisp_near2
- first:
33: 3300024
second: SeaVertDisp_near3
- first:
33: 3300026
second: SeaVertDisp_near4
- first:
33: 3300028
second: SeaVertDisp_outter1
- first:
33: 3300030
second: SeaVertDisp_outter2
- first:
33: 3300032
second: SeaVertDisp_outter3
- first:
33: 3300034
second: SeaVertDisp_outter4
- first:
33: 3300036
second: SeaDistant_01
- first:
33: 3300038
second: SeaDistant_02
- first:
33: 3300040
second: SeaDistant_03
- first:
33: 3300042
second: SeaDistant_04
- first:
33: 3300044
second: SeaDistant_01 (2)
- first:
33: 3300046
second: SeaDistant_02 (2)
- first:
33: 3300048
second: SeaDistant_03 (2)
- first:
33: 3300050
second: SeaDistant_04 (2)
- first:
43: 4300000
second: SeaVertDisp
- first:
43: 4300002
second: SeaVertDisp_outter4
- first:
43: 4300004
second: SeaVertDisp_mid4
- first:
43: 4300006
second: SeaVertDisp_mid3
- first:
43: 4300008
second: SeaVertDisp_outter3
- first:
43: 4300010
second: SeaVertDisp_outter1
- first:
43: 4300012
second: SeaVertDisp_mid2
- first:
43: 4300014
second: SeaVertDisp_mid1
- first:
43: 4300016
second: SeaVertDisp_outter2
- first:
43: 4300018
second: SeaVertDisp_far4
- first:
43: 4300020
second: SeaVertDisp_far3
- first:
43: 4300022
second: SeaVertDisp_far2
- first:
43: 4300024
second: SeaVertDisp_far1
- first:
43: 4300026
second: SeaVertDisp_center
- first:
43: 4300028
second: SeaVertDisp_near4
- first:
43: 4300030
second: SeaVertDisp_near3
- first:
43: 4300032
second: SeaVertDisp_near2
- first:
43: 4300034
second: SeaVertDisp_near1
- first:
43: 4300036
second: SeaDistant_01
- first:
43: 4300038
second: SeaDistant_02
- first:
43: 4300040
second: SeaDistant_03
- first:
43: 4300042
second: SeaDistant_04
- first:
43: 4300044
second: SeaDistant_04 (2)
- first:
43: 4300046
second: SeaDistant_03 (2)
- first:
43: 4300048
second: SeaDistant_02 (2)
- first:
43: 4300050
second: SeaDistant_01 (2)
- first:
74: 7400000
second: Take 001
- first:
95: 9500000
second: //RootNode
- first:
41386430: 2186277476908879412
second: ImportLogs
externalObjects:
- first:
type: UnityEngine:Material

materials:
importMaterials: 1
materialImportMode: 1
materialName: 0
materialSearch: 1
materialLocation: 1

meshCompression: 0
addColliders: 0
useSRGBMaterialColor: 1
sortHierarchyByName: 1
fileIdsGeneration: 1
optimizeMeshForGPU: 0
bakeAxisConversion: 0
skinWeightsMode: 0
maxBonesPerVertex: 4
minBoneWeight: 0.001
meshOptimizationFlags: 1
secondaryUVMarginMethod: 0
secondaryUVMinLightmapResolution: 40
secondaryUVMinObjectScale: 1
previousCalculatedGlobalScale: 0.01
hasPreviousCalculatedGlobalScale: 1
normalImportMode: 1
normalImportMode: 2
blendShapeNormalImportMode: 1
blendShapeNormalImportMode: 2
referencedClips: []
copyAvatar: 0
serializedVersion: 2
serializedVersion: 3
human: []
skeleton: []
armTwist: 0.5

armStretch: 0.05
legStretch: 0.05
feetSpacing: 0
globalScale: 1
autoGenerateAvatarMappingIfUnspecified: 1
avatarSetup: 0
additionalBone: 0
userData:
assetBundleName:

74
Packages/com.verasl.water-system/Scripts/Rendering/WaterSystemFeature.cs


CommandBufferPool.Release(cmd);
}
public override void OnCameraCleanup(CommandBuffer cmd)
public override void OnCameraCleanup(CommandBuffer cmd)
{
// since the texture is used within the single cameras use we need to cleanup the RT afterwards
cmd.ReleaseTemporaryRT(m_WaterFX.id);

#endregion
#region InfiniteWater Pass
class InfiniteWaterPass : ScriptableRenderPass
{
private Mesh infiniteMesh;
private Material infiniteMaterial;
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
if(infiniteMesh == null)
infiniteMesh = GenerateCausticsMesh(2f);
if (infiniteMaterial == null)
infiniteMaterial = CoreUtils.CreateEngineMaterial("BoatAttack/InfiniteWater");
if(!infiniteMaterial || !infiniteMesh) return;
Camera cam = renderingData.cameraData.camera;
if(cam.cameraType != CameraType.Game && cam.cameraType != CameraType.SceneView) return;
CommandBuffer cmd = CommandBufferPool.Get();
using (new ProfilingScope(cmd, new ProfilingSampler("Infinite Water")))
{
var probe = RenderSettings.ambientProbe;
// Create the matrix to position the caustics mesh.
var position = cam.transform.position;
position.y = 0; // TODO should read a global 'water height' variable.
var matrix = Matrix4x4.TRS(position, Quaternion.identity, Vector3.one);
// Setup the CommandBuffer and draw the mesh with the caustic material and matrix
MaterialPropertyBlock matBloc = new MaterialPropertyBlock();
matBloc.CopySHCoefficientArraysFrom(new []{probe});
cmd.DrawMesh(infiniteMesh, matrix, infiniteMaterial, 0, 0);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
}
}
#endregion
#region Caustics Pass
class WaterCausticsPass : ScriptableRenderPass

{
var cam = renderingData.cameraData.camera;
// Stop the pass rendering in the preview or material missing
if (cam.cameraType == CameraType.Preview || !WaterCausticMaterial)
return;
if (!WaterCausticMaterial) return;
if(cam.cameraType != CameraType.Game && cam.cameraType != CameraType.SceneView) return;
CommandBuffer cmd = CommandBufferPool.Get();
using (new ProfilingScope(cmd, m_WaterCaustics_Profile))

: Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(-45f, 45f, 0f), Vector3.one);
WaterCausticMaterial.SetMatrix("_MainLightDir", sunMatrix);
// Create mesh if needed
if (!m_mesh)
m_mesh = GenerateCausticsMesh(1000f);

#endregion
InfiniteWaterPass m_InfiniteWaterPass;
WaterFxPass m_WaterFxPass;
WaterCausticsPass m_CausticsPass;

public override void Create()
{
// InfiniteWater Pass
m_InfiniteWaterPass = new InfiniteWaterPass{renderPassEvent = RenderPassEvent.BeforeRenderingTransparents};
// WaterFX Pass
m_WaterFxPass = new WaterFxPass {renderPassEvent = RenderPassEvent.BeforeRenderingOpaques};

}
_causticMaterial = CoreUtils.CreateEngineMaterial(causticShader);
_causticMaterial.SetFloat("_BlendDistance", settings.causticBlendDistance);
if (causticTexture == null)
{
Debug.Log("Caustics Texture missing, attempting to load.");

}
_causticMaterial.SetTexture(CausticTexture, causticTexture);
switch (settings.debug)
{
case WaterSystemSettings.DebugMode.Caustics:

public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
renderer.EnqueuePass(m_InfiniteWaterPass);
renderer.EnqueuePass(m_WaterFxPass);
renderer.EnqueuePass(m_CausticsPass);
}

/// </summary>
/// <param name="size">The length of the quad.</param>
/// <returns></returns>
private static Mesh GenerateCausticsMesh(float size)
public static Mesh GenerateCausticsMesh(float size, bool flat = true)
{
var m = new Mesh();
size *= 0.5f;

new Vector3(-size, 0f, -size),
new Vector3(size, 0f, -size),
new Vector3(-size, 0f, size),
new Vector3(size, 0f, size)
new Vector3(-size, flat ? 0f : -size, flat ? -size : 0f),
new Vector3(size, flat ? 0f : -size, flat ? -size : 0f),
new Vector3(-size, flat ? 0f : size, flat ? size : 0f),
new Vector3(size, flat ? 0f : size, flat ? size : 0f)
};
m.vertices = verts;

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


{
Tags { "RenderType"="Transparent" "Queue"="Transparent-101" "RenderPipeline" = "UniversalPipeline" }
ZWrite off
Cull off
Pass
{

#pragma vertex InfiniteWaterVertex
#pragma fragment InfiniteWaterFragment
//float4x4 _InvViewProjection;
float3 UnprojectPoint(float3 p)
{
float4x4 mat = mul(unity_MatrixV, glstate_matrix_projection);
float4 unprojectedPoint = mul(mat, float4(p, 1));
return unprojectedPoint.xyz / unprojectedPoint.w;
}
Varyings InfiniteWaterVertex(Attributes input)
{
Varyings output = (Varyings)0;

float3 cameraOffset = GetCameraPositionWS();
//input.positionOS.y *= abs(cameraOffset.y) + 1;
cameraOffset.y -= 25.0;
VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz + cameraOffset);
//input.positionOS.xz = input.positionOS.y < 0 ? half2(0, 0) : input.positionOS.xz;
input.positionOS.xz *= 1000;
//input.positionOS = 1000;
//cameraOffset.y *= 0.0;
VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
//float3 pos = output.positionCS;
//pos.z = _ProjectionParams.y;
//output.positionWS = UnprojectPoint(pos); // near position
//pos.z = _ProjectionParams.z;
//output.preWaveSP = UnprojectPoint(pos); // far postion
output.positionWS = vertexInput.positionWS;
output.screenPosition = ComputeScreenPos(vertexInput.positionCS);
float3 viewPos = vertexInput.positionVS;

return output;
}
void InfiniteWaterFragment(Varyings i, out half4 outColor:SV_Target, out float outDepth : SV_Depth) //: SV_Target
half4 InfiniteWaterFragment(Varyings i) : SV_Target
//float t = -i.positionWS.y / (i.preWaveSP.y - i.positionWS.y);
//if(t > 0)
// discard;
half4 screenUV = 0.0;
screenUV.xy = i.screenPosition.xy / i.screenPosition.w; // screen UVs
screenUV.zw = screenUV.xy; // screen UVs

InfinitePlane plane = WorldPlane(i.screenPosition, i.viewDirectionWS);
i.positionWS = plane.positionWS;
half3 viewDirectionWS = normalize(GetCameraPositionWS() - plane.positionWS);
half3 viewDirectionWS = normalize(GetCameraPositionWS() - i.positionWS);
i.positionWS = plane.positionWS;
i.viewDirectionWS = normalize(GetCameraPositionWS() - plane.positionWS).xyzz;
i.viewDirectionWS = normalize(GetCameraPositionWS() - i.positionWS).xyzz;
i.uv = DetailUVs(plane.positionWS * (1 / _Size), 1);
i.uv = DetailUVs(i.positionWS * (1 / _Size), 1);
WaterInputData inputData;
InitializeInputData(i, inputData, screenUV.xy);

color.a = 1;
color.rgb = WaterShading(inputData, surfaceData, additionalData, screenUV.xy);
outColor = color;
outDepth = 1-plane.depth;
//outColor = half4(frac(i.positionWS), 1); //color;
//outDepth = 1;// 1-plane.depth;
//return half4(frac(plane.positionWS * 0.1), 1);
return color;
}
}

10
Packages/com.verasl.water-system/Shaders/WaterInput.hlsl


UNITY_VERTEX_OUTPUT_STEREO
};
struct VaryingsInfinite // infinite water Varyings
{
float3 nearPosition : TEXCOORD0; // near position of the vertices
float3 farPosition : TEXCOORD1; // far position of the vertices
float3 positionWS : TEXCOORD2; // world position of the vertices
float4 viewDirectionWS : TEXCOORD3; // view direction
half4 screenPosition : TEXCOORD4; // screen position after the waves
float4 positionCS : SV_POSITION;
};
struct WaterSurfaceData
{
half3 absorption;

正在加载...
取消
保存