浏览代码

optimised water caustics shader and pass

/demo-work
André McGrail 5 年前
当前提交
43338855
共有 2 个文件被更改,包括 9 次插入17 次删除
  1. 9
      Packages/com.verasl.water-system/Scripts/Rendering/WaterCausticsFeature.cs
  2. 17
      Packages/com.verasl.water-system/Shaders/Caustics.shader

9
Packages/com.verasl.water-system/Scripts/Rendering/WaterCausticsFeature.cs


using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
public class WaterCausticsFeature : UnityEngine.Rendering.Universal.ScriptableRendererFeature
public class WaterCausticsFeature : ScriptableRendererFeature
{
private WaterCausticsPass m_WaterCausticsPass;
public WaterCausticSettings settings = new WaterCausticSettings();

{
m_WaterCausticsPass = new WaterCausticsPass();
m_WaterCausticsPass.m_WaterCausticMaterial = settings.material;
m_WaterCausticsPass.renderPassEvent = RenderPassEvent.AfterRenderingSkybox + 1;
}
public override void AddRenderPasses(UnityEngine.Rendering.Universal.ScriptableRenderer renderer, ref UnityEngine.Rendering.Universal.RenderingData renderingData)

}
CommandBuffer cmd = CommandBufferPool.Get(k_RenderWaterCausticsTag);
cmd.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity);
cmd.DrawMesh(UnityEngine.Rendering.Universal.RenderingUtils.fullscreenMesh, Matrix4x4.identity, m_WaterCausticMaterial, 0, 0);
cmd.SetViewProjectionMatrices(renderingData.cameraData.camera.worldToCameraMatrix, renderingData.cameraData.camera.projectionMatrix);
cmd.DrawMesh(RenderingUtils.fullscreenMesh, Matrix4x4.identity, m_WaterCausticMaterial, 0, 0);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}

17
Packages/com.verasl.water-system/Shaders/Caustics.shader


return worldPos;
}
// Can be done per-vertex
{
{
//anim
float2 uv = rawUV * _Size + float2(_Time.y, _Time.x) * 0.1;
return uv + offset * 0.25;

{
Varyings output = (Varyings)0;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_TRANSFER_INSTANCE_ID(input, output);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
output.positionOS = vertexInput.positionCS;
output.uv = input.uv;
Varyings output;
output.positionOS = float4(input.positionOS.xyz, 1.0);
output.uv = float2(input.uv.x, 1.0 - input.uv.y);
return output;
}

正在加载...
取消
保存