浏览代码

Fixed planar reflections

- Planar reflections now work properly across multiple windows
- Fixed leaking of render texture
- Fixed multiple reflection cameras
- Added first pass seaweed
- Fixed tessellation shader
- Simplified water common to share more between tessellation and vertex displacement
- Enabled SRP batcher
- Fixed LODLightmaps to work with 4 LODs
- Cleared Occlusion data, was messing with planar reflections and also didnt cull anything at large distances
-
/main
André McGrail 6 年前
当前提交
175825d8
共有 22 个文件被更改,包括 3089 次插入775 次删除
  1. 5
      Assets/Data/LightweightAsset.asset
  2. 2
      Assets/Objects/boats/Interceptor.mat
  3. 2
      Assets/Objects/props/props/Matr_Props_Hue.mat
  4. 16
      Assets/Scripts/Boat/BoatController.cs
  5. 24
      Assets/Scripts/Effects/LODLightmaps.cs
  6. 4
      Assets/Scripts/Effects/WakeGenerator.cs
  7. 980
      Assets/scenes/Island.unity
  8. 980
      Packages/com.verasl.water-system/Meshes/SeaVertDisp.fbx
  9. 113
      Packages/com.verasl.water-system/Scripts/Rendering/PlanerReflections.cs
  10. 46
      Packages/com.verasl.water-system/Scripts/Rendering/WaterCausticsPass.cs
  11. 1
      Packages/com.verasl.water-system/Sea.mat
  12. 2
      Packages/com.verasl.water-system/Shaders/CommonUtilities.hlsl
  13. 125
      Packages/com.verasl.water-system/Shaders/WaterCommon.hlsl
  14. 7
      Packages/com.verasl.water-system/Shaders/WaterLighting.hlsl
  15. 18
      Packages/com.verasl.water-system/Shaders/WaterTessellated.shader
  16. 38
      Packages/com.verasl.water-system/Shaders/WaterTessellation.hlsl
  17. 95
      Assets/Materials/Seaweed.mat
  18. 8
      Assets/Materials/Seaweed.mat.meta
  19. 1001
      Assets/Textures/seaweedtemp.png
  20. 389
      Assets/Textures/seaweedtemp.png.meta
  21. 8
      Assets/scenes/Island/OcclusionCullingData.asset.meta

5
Assets/Data/LightweightAsset.asset


m_Name: LightweightAsset
m_EditorClassIdentifier:
k_AssetVersion: 4
m_RendererType: 1
m_RendererData: {fileID: 11400000, guid: 618d298269e66c542b306de85db1faea, type: 2}
m_RequireDepthTexture: 0
m_RequireOpaqueTexture: 0
m_OpaqueDownsampling: 1

m_ShadowDepthBias: 0.75
m_ShadowNormalBias: 0.75
m_SoftShadowsSupported: 1
m_UseSRPBatcher: 0
m_UseSRPBatcher: 1
m_SupportsDynamicBatching: 0
m_MixedLightingSupported: 0
m_ShadowType: 1

m_ShadowAtlasResolution: 256
m_ResourcesAsset: {fileID: 11400000, guid: aac5a08c32552a14c89394b703f1978a, type: 2}
m_ShaderVariantLogLevel: 1

2
Assets/Objects/boats/Interceptor.mat


m_LightmapFlags: 4
m_EnableInstancingVariants: 1
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
m_CustomRenderQueue: 2200
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:

2
Assets/Objects/props/props/Matr_Props_Hue.mat


m_LightmapFlags: 4
m_EnableInstancingVariants: 1
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
m_CustomRenderQueue: 2200
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:

16
Assets/Scripts/Boat/BoatController.cs


{
if (boatRenderer)
{
MaterialPropertyBlock mpb = new MaterialPropertyBlock();
mpb.SetColor("_Color1", PrimaryColor);
mpb.SetColor("_Color2", TrimColor);
boatRenderer.SetPropertyBlock(mpb);
if (Application.isEditor)
{
MaterialPropertyBlock mpb = new MaterialPropertyBlock();
mpb.SetColor("_Color1", PrimaryColor);
mpb.SetColor("_Color2", TrimColor);
boatRenderer.SetPropertyBlock(mpb);
}
else
{
boatRenderer.material.SetColor("_Color1", PrimaryColor);
boatRenderer.material.SetColor("_Color2", TrimColor);
}
}
}
}

24
Assets/Scripts/Effects/LODLightmaps.cs


Renderer[] _main; // LOD0 Meshes
Renderer[] _LOD1; // LOD2 Meshes
Renderer[] _LOD2; // LOD3 Meshes
Renderer[] _LOD3; // LOD3 Meshes
void OnEnable()
{

_lodGrp = GetComponent<LODGroup>();
LOD[] lods = _lodGrp.GetLODs();
_main = lods[0].renderers;
_LOD1 = lods[1].renderers;
_LOD2 = lods[2].renderers;
for (var i = 1; i < lods.Length; i++)
{
switch (i)
{
case 1:
_LOD1 = lods[i].renderers;
break;
case 2:
_LOD2 = lods[i].renderers;
break;
case 3:
_LOD3 = lods[i].renderers;
break;
}
}
int[] lmIndex = new int[_main.Length];
Vector4[] lmScaleOffset = new Vector4[_main.Length];

_LOD1[i].lightmapScaleOffset = lmScaleOffset[i];
_LOD2[i].lightmapIndex = lmIndex[i];
_LOD2[i].lightmapScaleOffset = lmScaleOffset[i];
if (_LOD3[i])
{
_LOD3[i].lightmapIndex = lmIndex[i];
_LOD3[i].lightmapScaleOffset = lmScaleOffset[i];
}
}
}
}

4
Assets/Scripts/Effects/WakeGenerator.cs


using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using System.Collections.Generic;
using UnityEngine;
using Quaternion = UnityEngine.Quaternion;
using Vector3 = UnityEngine.Vector3;

980
Assets/scenes/Island.unity
文件差异内容过多而无法显示
查看文件

980
Packages/com.verasl.water-system/Meshes/SeaVertDisp.fbx
文件差异内容过多而无法显示
查看文件

113
Packages/com.verasl.water-system/Scripts/Rendering/PlanerReflections.cs


using System;
using Unity.Mathematics;
using UnityEngine.Rendering;
using WaterSystem;
using Unity.Mathematics;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Serialization;
public class PlanerReflections : MonoBehaviour, IBeforeCameraRender
{
[System.Serializable]

public PlanarReflectionSettings m_settings = new PlanarReflectionSettings();
public GameObject target;
public float camOffset;
[FormerlySerializedAs("camOffset")] public float m_planeOffset;
private Camera m_ReflectionCamera;
private static Camera m_ReflectionCamera;
private int planarReflectionTextureID = Shader.PropertyToID("_PlanarReflectionTexture");
void OnDisable()
private void OnDisable()
{
Cleanup();
}
private void OnDestroy()
{
Cleanup();
}
void Cleanup()
DestroyImmediate(m_ReflectionCamera.gameObject);
SafeDestroy(m_ReflectionCamera.gameObject);
DestroyImmediate(m_ReflectionTexture);
RenderTexture.ReleaseTemporary(m_ReflectionTexture);
}
}
void SafeDestroy(Object obj)
{
if (Application.isEditor)
{
DestroyImmediate(obj);
}
else
{
Destroy(obj);
}
}

return;
// set camera to clear the same way as current camera
dest.clearFlags = src.clearFlags;
dest.backgroundColor = src.backgroundColor;
// update other values to match current camera.
// even if we are supplying custom camera&projection matrices,
// some of values are used elsewhere (e.g. skybox uses far plane)
dest.farClipPlane = src.farClipPlane;
dest.nearClipPlane = src.nearClipPlane;
dest.orthographic = src.orthographic;
dest.fieldOfView = src.fieldOfView;
dest.allowHDR = src.allowHDR;
dest.useOcclusionCulling = false;
dest.aspect = src.aspect;
dest.orthographicSize = src.orthographicSize;
dest.CopyFrom(src);
private void UpdateReflectionCamera(Camera realCamera)
{

Vector3 normal = Vector3.up;
if (target != null)
{
pos = target.transform.position + Vector3.up * camOffset;
pos = target.transform.position + Vector3.up * m_planeOffset;
normal = target.transform.up;
}

m_ReflectionCamera.projectionMatrix = projection;
m_ReflectionCamera.cullingMask = m_settings.m_ReflectLayers; // never render water layer
m_ReflectionCamera.transform.position = newpos;
}
// Calculates reflection matrix around the given plane

private Camera CreateMirrorObjects(Camera currentCamera)
{
LightweightRenderPipelineAsset lwAsset = (LightweightRenderPipelineAsset) GraphicsSettings.renderPipelineAsset;
var resMulti = lwAsset.renderScale * GetScaleValue();
m_TextureSize.x = (int) Mathf.Pow(2, Mathf.RoundToInt(Mathf.Log(currentCamera.pixelWidth * resMulti, 2)));
m_TextureSize.y = (int) Mathf.Pow(2, Mathf.RoundToInt(Mathf.Log(currentCamera.pixelHeight * resMulti, 2)));
// Reflection render texture
if (Int2Compare(m_TextureSize, m_OldReflectionTextureSize) || !m_ReflectionTexture)
{
if (m_ReflectionTexture)
DestroyImmediate(m_ReflectionTexture);
bool useHDR10 = Application.isMobilePlatform &&
SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.RGB111110Float);
RenderTextureFormat hdrFormat = (useHDR10) ? RenderTextureFormat.RGB111110Float : RenderTextureFormat.DefaultHDR;
m_ReflectionTexture = new RenderTexture(m_TextureSize.x, m_TextureSize.y, 0,
currentCamera.allowHDR ? hdrFormat : RenderTextureFormat.Default);
m_ReflectionTexture.useMipMap = m_ReflectionTexture.autoGenerateMips = false;
m_ReflectionTexture.autoGenerateMips = false; // no need for mips(unless wanting cheap roughness)
m_ReflectionTexture.name = "_PlanarReflection" + GetInstanceID();
m_ReflectionTexture.isPowerOfTwo = true;
m_ReflectionTexture.hideFlags = HideFlags.DontSave;
m_ReflectionTexture.depth = 32;
m_OldReflectionTextureSize = m_TextureSize;
}
m_ReflectionTexture.DiscardContents();
typeof(Camera), typeof(Skybox));
typeof(Camera));
LWRPAdditionalCameraData lwrpCamData =
go.AddComponent(typeof(LWRPAdditionalCameraData)) as LWRPAdditionalCameraData;
lwrpCamData.renderShadows = false; // turn off shadows for the reflection camera

reflectionCamera.transform.SetPositionAndRotation(transform.position, transform.rotation);
reflectionCamera.targetTexture = m_ReflectionTexture;
//reflectionCamera.targetTexture = m_ReflectionTexture;
reflectionCamera.allowMSAA = currentCamera.allowMSAA;
reflectionCamera.depth = -10;
reflectionCamera.enabled = false;

Shader.SetGlobalTexture("_PlanarReflectionTexture", m_ReflectionTexture);
private int2 ReflectionResolution(Camera cam, float scale)
{
var x = (int)(cam.pixelWidth * scale * GetScaleValue());
var y = (int)(cam.pixelHeight * scale * GetScaleValue());
return new int2(x, y);
}
public void ExecuteBeforeCameraRender(
LightweightRenderPipeline pipelineInstance,
ScriptableRenderContext context,

UpdateReflectionCamera(camera);
LightweightRenderPipeline.RenderSingleCamera(pipelineInstance, context, m_ReflectionCamera);
var res = ReflectionResolution(camera, LightweightRenderPipeline.asset.renderScale);
if (m_ReflectionTexture == null)
{
m_ReflectionTexture = RenderTexture.GetTemporary(res.x, res.y, 16,
GraphicsFormatUtility.GetGraphicsFormat(RenderTextureFormat.DefaultHDR, true));
}
m_ReflectionCamera.targetTexture = m_ReflectionTexture;
LightweightRenderPipeline.RenderSingleCamera(pipelineInstance, context, m_ReflectionCamera);
Shader.SetGlobalTexture(planarReflectionTextureID, m_ReflectionTexture);
}
}
}

46
Packages/com.verasl.water-system/Scripts/Rendering/WaterCausticsPass.cs


using System.Net;
using UnityEngine;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.LWRP;
using UnityEngine.Experimental.Rendering.LWRP;

public class WaterCausticsPassImpl : ScriptableRenderPass
{
const string k_RenderWaterCausticsTag = "Render Water Caustics";
//private RenderTargetHandle m_WaterCaustics = RenderTargetHandle.CameraTarget;
//RenderTargetHandle m_TemporaryColorTexture;
private Matrix4x4 view;
private Matrix4x4 proj;
private FilteringSettings transparentFilterSettings { get; set; }
public WaterCausticsPassImpl()
{
RegisterShaderPassName("WaterFX");
//m_WaterCaustics.Init("_WaterFXMap");
//m_TemporaryColorTexture.Init("_TemporaryColorTexture");
transparentFilterSettings = new FilteringSettings(RenderQueueRange.transparent);
}
private Matrix4x4 m_view;
private Matrix4x4 m_proj;
Debug.LogErrorFormat("Missing {0}. {1} render pass will not execute. Check for missing reference in the renderer resources.", m_WaterCausticMaterial, GetType().Name);
Debug.LogErrorFormat("Missing caustic material}. {0} render pass will not execute. Check for missing reference in the renderer resources.", GetType().Name);
RenderTextureDescriptor opaqueDesc = ScriptableRenderer.CreateRenderTextureDescriptor(ref renderingData.cameraData);
opaqueDesc.msaaSamples = 1;
//RenderTargetIdentifier src = m_WaterCaustics.Identifier();
//cmd.GetTemporaryRT(m_TemporaryColorTexture.id, opaqueDesc, FilterMode.Point);
//cmd.Blit(src, m_TemporaryColorTexture.Identifier(), blitMaterial, blitShaderPassIndex);
//cmd.Blit(m_TemporaryColorTexture.Identifier(), src);
view = renderingData.cameraData.camera.worldToCameraMatrix;
proj = renderingData.cameraData.camera.projectionMatrix;
m_view = renderingData.cameraData.camera.worldToCameraMatrix;
m_proj = renderingData.cameraData.camera.projectionMatrix;
//cmd.SetViewport(renderingData.cameraData.camera.pixelRect);
cmd.SetViewProjectionMatrices(view, proj);
cmd.SetViewProjectionMatrices(m_view, m_proj);
// public override void FrameCleanup(CommandBuffer cmd)
// {
// cmd.SetViewProjectionMatrices(renderingData.cameraData.camera.worldToCameraMatrix, renderingData.cameraData.camera.projectionMatrix);
// }
}
}

1
Packages/com.verasl.water-system/Sea.mat


- _SpecularHighlights: 1
- _SrcBlend: 1
- _Surface: 0
- _TessellationEdgeLength: 50
- _UVSec: 0
- _ZWrite: 1
m_Colors:

2
Packages/com.verasl.water-system/Shaders/CommonUtilities.hlsl


// Simple noise from thebookofshaders.com
// 2D Random
float random(float2 st){
float2 random(float2 st){
st = float2( dot(st,float2(127.1,311.7)), dot(st,float2(269.5,183.3)) );
return -1.0 + 2.0 * frac(sin(st) * 43758.5453123);
}

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


{
float4 vertex : POSITION; // vertex positions
float2 texcoord : TEXCOORD0; // local UVs
float4 lightmapUV : TEXCOORD1; // lightmap UVs
float4 color : COLOR; // vertex colors
UNITY_VERTEX_INPUT_INSTANCE_ID
};

//float4 lightmapUVOrVertexSH : TEXCOORD1; // holds either lightmapUV or vertex SH. depending on LIGHTMAP_ON - TODO
half2 fogFactorNoise : TEXCOORD4; // x: fogFactor, y: noise
float4 additionalData : TEXCOORD5; // x = distance to surface, y = distance to surface, z = normalized wave height
half2 fogFactorNoise : TEXCOORD4; // x: fogFactor, y: noise
float4 additionalData : TEXCOORD5; // x = distance to surface, y = distance to surface, z = normalized wave height, w = horizontal movement
half4 shadowCoord : TEXCOORD6; // for ssshadows
float4 clipPos : SV_POSITION;

half3 Refraction(half2 distortion, half mip)
{
half3 refrac = SAMPLE_TEXTURE2D_LOD(_CameraOpaqueTexture, sampler_CameraOpaqueTexture_linear_clamp, distortion, mip);
half3 refrac = SAMPLE_TEXTURE2D_LOD(_CameraOpaqueTexture, sampler_CameraOpaqueTexture_linear_clamp, distortion, mip).rgb;
//half2 distortion;
half3 viewNormal = mul(GetWorldToHClipMatrix(), -normalWS).xyz;
half3 viewNormal = mul((float3x3)GetWorldToHClipMatrix(), -normalWS).xyz;
///////////////////////////////////////////////////////////////////////////////
// Vertex and Fragment functions //
///////////////////////////////////////////////////////////////////////////////
half4 AdditionalData(float3 postionWS, WaveStruct wave)
{
half4 data = half4(0.0, 0.0, 0.0, 0.0);
float3 viewPos = TransformWorldToView(postionWS);
data.x = length(viewPos / viewPos.z);// distance to surface
data.y = length(GetCameraPositionWS().xyz - postionWS); // local position in camera space
data.z = wave.position.y / _MaxWaveHeight; // encode the normalized wave height into additional data
data.w = wave.position.x + wave.position.z;
return data;
}
// Vertex: Used for Standard non-tessellated water
WaterVertexOutput WaterVertex(WaterVertexInput v)
WaterVertexOutput WaveVertexOperations(WaterVertexOutput input)
WaterVertexOutput o = (WaterVertexOutput)0;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_TRANSFER_INSTANCE_ID(v, o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
input.normal = float3(0, 1, 0);
input.uv.zw = input.posWS.xz;
input.fogFactorNoise.y = ((noise((input.posWS.xz * 0.5) + _GlobalTime) + noise((input.posWS.xz * 1) + _GlobalTime)) * 0.25 - 0.5) + 1;
o.uv.xy = v.texcoord; // geo uvs
// initializes o.normal
o.normal = float3(0, 1, 0);
o.posWS = TransformObjectToWorld(v.vertex.xyz);
o.uv.zw = o.posWS.xz;
o.fogFactorNoise.y = ((noise((o.posWS.xz * 0.5) + _GlobalTime) + noise((o.posWS.xz * 1) + _GlobalTime)) * 0.25 - 0.5) + 1;
half4 screenUV = ComputeScreenPos(TransformWorldToHClip(o.posWS));
half4 screenUV = ComputeScreenPos(TransformWorldToHClip(input.posWS));
half waterDepth = UNITY_REVERSED_Z + SAMPLE_DEPTH_TEXTURE_LOD(_WaterDepthMap, sampler_WaterDepthMap_linear_clamp, (o.posWS.xz * 0.002) + 0.5, 1).r * _ProjectionParams.x;
half waterDepth = UNITY_REVERSED_Z + SAMPLE_DEPTH_TEXTURE_LOD(_WaterDepthMap, sampler_WaterDepthMap_linear_clamp, (input.posWS.xz * 0.002) + 0.5, 1).r * _ProjectionParams.x;
o.posWS.y += saturate((1 - waterDepth) * 0.6 - 0.5);
input.posWS.y += saturate((1 - waterDepth) * 0.6 - 0.5);
SampleWaves(o.posWS, saturate((waterDepth * 0.25)) + 0.1, wave);
o.normal = normalize(wave.normal.xzy);
o.posWS += wave.position;
SampleWaves(input.posWS, saturate((waterDepth * 0.25)) + 0.1, wave);
input.normal = normalize(wave.normal.xzy);
input.posWS += wave.position;
// Dynamic displacement
input.posWS.y += waterFX.w * 2 - 1;
o.posWS.y += waterFX.w * 2 - 1;
// After waves
input.clipPos = TransformWorldToHClip(input.posWS);
input.shadowCoord = ComputeScreenPos(input.clipPos);
input.viewDir = SafeNormalize(_WorldSpaceCameraPos - input.posWS);
//after waves
o.clipPos = TransformWorldToHClip(o.posWS);
o.shadowCoord = ComputeScreenPos(o.clipPos);
o.viewDir = SafeNormalize(_WorldSpaceCameraPos - o.posWS);
// We either sample GI from lightmap or SH. lightmap UV and vertex SH coefficients
// are packed in lightmapUVOrVertexSH to save interpolator.
// The following funcions initialize
//OUTPUT_LIGHTMAP_UV(v.lightmapUV, unity_LightmapST, o.lightmapUVOrVertexSH);
//OUTPUT_SH(o.normal, o.lightmapUVOrVertexSH);
//o.fogFactorAndVertexLight = VertexLightingAndFog(o.normal, o.posWS, o.clipPos.xyz);
o.fogFactorNoise.x = ComputeFogFactor(o.clipPos.z);
o.preWaveSP = screenUV; // pre-displaced screenUVs
// Fog
input.fogFactorNoise.x = ComputeFogFactor(input.clipPos.z);
input.preWaveSP = screenUV.xyz; // pre-displaced screenUVs
float3 viewPos = TransformWorldToView(o.posWS.xyz);
o.additionalData.x = length(viewPos / viewPos.z);// distance to surface
o.additionalData.y = length(GetCameraPositionWS().xyz - o.posWS); // local position in camera space
o.additionalData.z = wave.position.y / _MaxWaveHeight; // encode the normalized wave height into additional data
o.additionalData.w = wave.position.x + wave.position.z;
input.additionalData = AdditionalData(input.posWS, wave);
half distanceBlend = saturate(o.additionalData.y * 0.005);
half distanceBlend = saturate(input.additionalData.y * 0.005);
o.normal = lerp(o.normal, half3(0, 1, 0), distanceBlend);
input.normal = lerp(input.normal, half3(0, 1, 0), distanceBlend);
return input;
}
///////////////////////////////////////////////////////////////////////////////
// Vertex and Fragment functions //
///////////////////////////////////////////////////////////////////////////////
// Vertex: Used for Standard non-tessellated water
WaterVertexOutput WaterVertex(WaterVertexInput v)
{
WaterVertexOutput o;// = (WaterVertexOutput)0;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_TRANSFER_INSTANCE_ID(v, o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.uv.xy = v.texcoord; // geo uvs
o.posWS = TransformObjectToWorld(v.vertex.xyz);
o = WaveVertexOperations(o);
return o;
}

distortion = depth.x < 0 ? screenUV.xy : distortion;
depth.x = depth.x < 0 ? d : depth.x;
// Seabed UVs from depth
//float4 H = float4(distortion*2.0-1.0, UNITY_REVERSED_Z == 1 ? depth.z : 1-depth.z, 1.0);
//float4 D = mul(_InvViewProjection,H);
//float2 seabedWS = D.xz/D.w;
// Caustics
//half2 causticUV = (seabedWS * 0.3h + t + half2((IN.fogFactorNoise.y * 0.25), (1-IN.fogFactorNoise.y) * 0.25)) + IN.additionalData.w * 0.1h;
//half caustics = SAMPLE_TEXTURE2D_ARRAY_LOD(_SurfaceMap, sampler_SurfaceMap, causticUV, animT, depth.x * 0.5).z * saturate(depth.x); // caustics for sea floor, darkened to 25%
// Fresnel
half fresnelTerm = CalculateFresnelTerm(lerp(IN.normal, half3(0, 1, 0), 0.5), IN.viewDir.xyz);

// Specular
half3 spec = Highlights(IN.posWS, 0.001, IN.normal, IN.viewDir) * shadow;
Light mainLight = GetMainLight();
//half3 ambient = SampleSHPixel(IN.lightmapUVOrVertexSH, IN.normal) * (mainLight.color * mainLight.distanceAttenuation);
// Foam
float2 foamMapUV = (IN.uv.zw * 0.1) + (detailBump.xy * 0.0025) + half2(IN.fogFactorNoise.y * 0.1, (1-IN.fogFactorNoise.y) * 0.1) + _GlobalTime * 0.05;

// Final Colouring
half depthMulti = 1 / _MaxDepth;
half3 color = refraction;// (refraction + ((caustics * refraction) * mainLight.color));
half3 color = refraction;
color *= Absorption((depth.x) * depthMulti);
color += Scattering(depth.x * depthMulti) * (shadow * 0.5 + 0.5);// * saturate(1-length(reflection));// TODO - scattering from main light(maybe additional lights too depending on cost)
color *= 1 - saturate(foam);

float fogFactor = IN.fogFactorNoise.x;
comp = MixFog(comp, fogFactor);
return half4(comp, 1);
//return half4(refraction, 1); // debug line
//return half4(shadow.xxx, 1); // debug line
}
#endif // WATER_COMMON_INCLUDED

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


// conver the uvs into view space by "undoing" projection
float3 viewDir = -(float3((screenUV * 2 - 1) / p11_22, -1));
//half3 viewDir = (mul((real3x3)GetWorldToViewMatrix(), -viewDirectionWS));
half3 viewNormal = mul(-normalWS, GetWorldToViewMatrix()).xyz;
half3 reflectVector = reflect(-viewDir, viewNormal) - half3(0, 0.35, 0);
half3 viewNormal = mul(-normalWS, (float3x3)GetWorldToViewMatrix()).xyz;
half3 reflectVector = reflect(-viewDir, viewNormal);
half2 reflectionUV = screenUV + reflectVector.xy * 0.05;
half2 reflectionUV = screenUV + normalWS.zx * half2(0.02, 0.1);
reflection += SAMPLE_TEXTURE2D_LOD(_PlanarReflectionTexture, sampler_ScreenTextures_linear_clamp, reflectionUV, 6 * roughness).rgb;//planar reflection
#endif
//do backup

18
Packages/com.verasl.water-system/Shaders/WaterTessellated.shader


HLSLPROGRAM
#pragma require tessellation tessHW
#pragma prefer_hlslcc gles
#pragma shader_feature _REFLECTION_CUBEMAP _REFLECTION_PROBES _REFLECTION_PLANARREFLECTION
#pragma multi_compile _ FOG_LINEAR FOG_EXP2
#pragma multi_compile _REFLECTION_CUBEMAP _REFLECTION_PROBES _REFLECTION_PLANARREFLECTION
#pragma multi_compile _ USE_STRUCTURED_BUFFER
// -------------------------------------
// Lightweight Pipeline keywords
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS
#pragma multi_compile _ _SHADOWS_SOFT
//--------------------------------------
// GPU Instancing
#pragma multi_compile_instancing
#pragma multi_compile_fog
////////////////////INCLUDES//////////////////////
#include "WaterCommon.hlsl"
#include "WaterTessellation.hlsl"

38
Packages/com.verasl.water-system/Shaders/WaterTessellation.hlsl


float4 vertex : INTERNALTESSPOS;
float4 texcoord : TEXCOORD0; // Geometric UVs stored in xy, and world(pre-waves) in zw
float3 posWS : TEXCOORD1; // world position of the vertices
float4 color : TEXCOORD2; // vertex color
//float2 preWaveSP : TEXCOORD2; // screen position of the verticies before wave distortion
UNITY_VERTEX_INPUT_INSTANCE_ID
};

o.posWS = TransformObjectToWorld(v.vertex.xyz);
o.texcoord.xy = v.texcoord;
o.texcoord.zw = o.posWS.xz;
o.color = v.color;
//o.color = v.color;
return o;
}

[domain("tri")]
WaterVertexOutput Domain( HS_ConstantOutput HSConstantData, const OutputPatch<TessellationControlPoint, 3> Input, float3 BarycentricCoords : SV_DomainLocation)
{
WaterVertexOutput o = (WaterVertexOutput)0;
WaterVertexOutput o = (WaterVertexOutput)0;
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
float fU = BarycentricCoords.x;
float fV = BarycentricCoords.y;
float fW = BarycentricCoords.z;

o.posWS = Input[0].posWS * fU + Input[1].posWS * fV + Input[2].posWS * fW;
o.vertColor = Input[0].color * fU + Input[1].color * fV + Input[2].color * fW;
// initializes o.normal
o.normal = float3(0, 1, 0);
//Waves
WaveStruct wave;
SampleWaves(o.posWS, saturate(o.vertColor.r * 0.1), wave);
o.normal = normalize(wave.normal.xzy);
o.posWS += wave.position;
//o.uv.zw -= wave.position.xz;
o.clipPos = TransformWorldToHClip(o.posWS);
o.shadowCoord = ComputeScreenPos(o.clipPos);
o.viewDir = SafeNormalize(_WorldSpaceCameraPos - o.posWS);
// We either sample GI from lightmap or SH. lightmap UV and vertex SH coefficients
// are packed in lightmapUVOrVertexSH to save interpolator.
// The following funcions initialize
OUTPUT_LIGHTMAP_UV(v.lightmapUV, unity_LightmapST, o.lightmapUVOrVertexSH);
OUTPUT_SH(o.normal, o.lightmapUVOrVertexSH);
o.fogFactorAndVertexLight = VertexLightingAndFog(o.normal, o.posWS, o.clipPos);
// Additional data
float3 viewPos = TransformWorldToView(o.posWS.xyz);
o.additionalData.x = length(viewPos / viewPos.z);// distance to surface
length(GetCameraPositionWS().xyz - o.posWS);
o.additionalData.z = wave.position.y / _MaxWaveHeight; // encode the normalized wave height into additional data
o.additionalData.w = wave.position.x + wave.position.z;
o = WaveVertexOperations(o);
return o;
}

95
Assets/Materials/Seaweed.mat


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Seaweed
m_Shader: {fileID: 4800000, guid: 8d2bb70cbf9db8d4da26e15b26e74248, type: 3}
m_ShaderKeywords: _ALPHATEST_ON
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: 2500
stringTagMap:
RenderType: TransparentCutout
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BaseMap:
m_Texture: {fileID: 2800000, guid: cc4461962f3156d449f7a6273a2d11a7, 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}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 2800000, guid: cc4461962f3156d449f7a6273a2d11a7, type: 3}
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}
- _SpecGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _AlphaClip: 1
- _Blend: 0
- _BumpScale: 1
- _Cull: 2
- _Cutoff: 0.5
- _DstBlend: 0
- _EnvironmentReflections: 1
- _GlossMapScale: 0
- _Glossiness: 0
- _GlossinessSource: 0
- _GlossyReflections: 0
- _Metallic: 0
- _OcclusionStrength: 1
- _QueueOffset: 0
- _ReceiveShadows: 1
- _Shininess: 0
- _Smoothness: 0.5
- _SmoothnessSource: 0
- _SmoothnessTextureChannel: 0
- _SpecSource: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _Surface: 0
- _WorkflowMode: 1
- _ZWrite: 1
m_Colors:
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
- _Color: {r: 0.5, g: 0.5, b: 0.5, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecColor: {r: 0.19999993, g: 0.19999993, b: 0.19999993, a: 0.5}
--- !u!114 &743226389367642094
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_GeneratorAsset: {fileID: 0}
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
m_Name:
m_EditorClassIdentifier:
version: 1

8
Assets/Materials/Seaweed.mat.meta


fileFormatVersion: 2
guid: ad576ac25156b614199c50816aa56dcc
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

1001
Assets/Textures/seaweedtemp.png
文件差异内容过多而无法显示
查看文件

389
Assets/Textures/seaweedtemp.png.meta


fileFormatVersion: 2
guid: cc4461962f3156d449f7a6273a2d11a7
TextureImporter:
internalIDToNameTable:
- first:
213: 2070579405914638917
second: seaweedtemp_0
- first:
213: 6953415236642347197
second: seaweedtemp_1
- first:
213: 2011398730452703665
second: seaweedtemp_2
- first:
213: -5293604505027546174
second: seaweedtemp_3
- first:
213: 3586653459566250728
second: seaweedtemp_4
- first:
213: -2203736334888200849
second: seaweedtemp_5
- first:
213: 7684757929429416417
second: seaweedtemp_6
- first:
213: 7923480362896806873
second: seaweedtemp_7
- first:
213: -7357963357551301488
second: seaweedtemp_8
- first:
213: -4359772888661098362
second: seaweedtemp_9
- first:
213: -4293720270900019543
second: seaweedtemp_10
- first:
213: -3568659909592068359
second: seaweedtemp_11
externalObjects: {}
serializedVersion: 9
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 1
mipMapsPreserveCoverage: 1
alphaTestReferenceValue: 0.8
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: 4
mipBias: -100
wrapU: -1
wrapV: -1
wrapW: -1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
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: 1
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- serializedVersion: 2
buildTarget: DefaultTexturePlatform
maxTextureSize: 512
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
- serializedVersion: 2
buildTarget: Standalone
maxTextureSize: 512
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
spriteSheet:
serializedVersion: 2
sprites:
- serializedVersion: 2
name: seaweedtemp_0
rect:
serializedVersion: 2
x: 42
y: 452
width: 37
height: 287
alignment: 7
pivot: {x: 0.5, y: 0}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: 97a2c42ed98b5734d8f27b5fca2e2e96
internalID: 2070579405914638917
vertices: []
indices:
edges: []
weights: []
- serializedVersion: 2
name: seaweedtemp_1
rect:
serializedVersion: 2
x: 106
y: 451
width: 47
height: 255
alignment: 7
pivot: {x: 0.5, y: 0}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: 62c74ced364473340a1c1a16642e6d88
internalID: 6953415236642347197
vertices: []
indices:
edges: []
weights: []
- serializedVersion: 2
name: seaweedtemp_2
rect:
serializedVersion: 2
x: 179
y: 445
width: 52
height: 341
alignment: 7
pivot: {x: 0.5, y: 0}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: 887ffb4d096811649a309f668b9a9e6c
internalID: 2011398730452703665
vertices: []
indices:
edges: []
weights: []
- serializedVersion: 2
name: seaweedtemp_3
rect:
serializedVersion: 2
x: 266
y: 450
width: 184
height: 339
alignment: 7
pivot: {x: 0.5, y: 0}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: d19e1c4c005b9cc4fa01ddf38705e385
internalID: -5293604505027546174
vertices: []
indices:
edges: []
weights: []
- serializedVersion: 2
name: seaweedtemp_4
rect:
serializedVersion: 2
x: 503
y: 451
width: 143
height: 334
alignment: 7
pivot: {x: 0.5, y: 0}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: aa624a9f203a59349a2491754c4b9b7c
internalID: 3586653459566250728
vertices: []
indices:
edges: []
weights: []
- serializedVersion: 2
name: seaweedtemp_5
rect:
serializedVersion: 2
x: 721
y: 445
width: 121
height: 335
alignment: 7
pivot: {x: 0.5, y: 0}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: fef41ef7e9ce26e44b54dc0045a36a96
internalID: -2203736334888200849
vertices: []
indices:
edges: []
weights: []
- serializedVersion: 2
name: seaweedtemp_6
rect:
serializedVersion: 2
x: 42
y: 133
width: 26
height: 286
alignment: 7
pivot: {x: 0.5, y: 0}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: d0637000e8812c04f9b16c04e6bea50b
internalID: 7684757929429416417
vertices: []
indices:
edges: []
weights: []
- serializedVersion: 2
name: seaweedtemp_7
rect:
serializedVersion: 2
x: 76
y: 117
width: 43
height: 300
alignment: 7
pivot: {x: 0.5, y: 0}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: 0db80e8c958eda74ca28b07cd78162dc
internalID: 7923480362896806873
vertices: []
indices:
edges: []
weights: []
- serializedVersion: 2
name: seaweedtemp_8
rect:
serializedVersion: 2
x: 129
y: 88
width: 116
height: 342
alignment: 7
pivot: {x: 0.5, y: 0}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: f3622b33fc7e6fd478c9953f4c9fe58a
internalID: -7357963357551301488
vertices: []
indices:
edges: []
weights: []
- serializedVersion: 2
name: seaweedtemp_9
rect:
serializedVersion: 2
x: 264
y: 76
width: 105
height: 339
alignment: 7
pivot: {x: 0.5, y: 0}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: dd407c176671bc248878ab30ab3222c0
internalID: -4359772888661098362
vertices: []
indices:
edges: []
weights: []
- serializedVersion: 2
name: seaweedtemp_10
rect:
serializedVersion: 2
x: 400
y: 84
width: 147
height: 329
alignment: 7
pivot: {x: 0.5, y: 0}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: b9e719c5eb7a08b4f9c671b00fd56ea0
internalID: -4293720270900019543
vertices: []
indices:
edges: []
weights: []
- serializedVersion: 2
name: seaweedtemp_11
rect:
serializedVersion: 2
x: 576
y: 93
width: 286
height: 339
alignment: 7
pivot: {x: 0.5, y: 0}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: 9efefcdccbb2f4f4fb785209353f1af8
internalID: -3568659909592068359
vertices: []
indices:
edges: []
weights: []
outline: []
physicsShape: []
bones: []
spriteID: f8ee34f0b06540442b4c0022e358630d
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

8
Assets/scenes/Island/OcclusionCullingData.asset.meta


fileFormatVersion: 2
guid: c50beb49de97543d9986b239981f6b8b
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 36300000
userData:
assetBundleName:
assetBundleVariant:

部分文件因为文件数量过多而无法显示

|||||||
100:0
正在加载...
取消
保存