• 大小: 41.55MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-07-24
  • 语言: 其他
  • 标签: 水面波纹  

资源简介

非常漂亮的水面扰动效果,可以用来模拟人物在水中游泳的波纹效果

资源截图

代码片段和文件信息

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;


/// 
/// 焦散渲染器
/// 

public class CausticRenderer : MonoBehaviour
{
    /// 
    /// 网格单元格大小
    /// 

    public float geometryCellSize;
    /// 
    /// 焦散宽度
    /// 

    public float width;
    /// 
    /// 焦散长度
    /// 

    public float length;
    /// 
    /// 焦散强度
    /// 

    public float causticIntensity = 1.0f;
    /// 
    /// 深度范围(该参数目前实现比较简单,只是简单的传入世界空间的最小高度和有效高度范围,以计算焦散的有效高度范围(线性插值),暂时没有实现复杂的范围计算效果)
    /// 

    public Vector2 causticDepthRange;

    public Material material;

    private Mesh m_Mesh;

    private Camera m_Camera;

    private RenderTexture m_RenderTexture;
    private CommandBuffer m_CommandBuffer;

    void Start()
    {
        m_Camera = gameobject.AddComponent();
        m_Camera.aspect = width / length;
        m_Camera.backgroundColor = Color.black;
        //m_Camera.enabled = false;
        m_Camera.depth = 0;
        m_Camera.farClipPlane = 5;
        m_Camera.nearClipPlane = -5;
        m_Camera.orthographic = true;
        m_Camera.orthographicSize = length * 0.5f;
        //m_Camera.clearFlags = CameraClearFlags.SolidColor;
        m_Camera.clearFlags = CameraClearFlags.SolidColor;
        m_Camera.allowHDR = false;
        m_Camera.backgroundColor = Color.black;
        m_Camera.cullingMask = 0;

        m_RenderTexture = RenderTexture.GetTemporary(512 512 16);
        m_RenderTexture.name = “[Caustic]“;
        m_Camera.targetTexture = m_RenderTexture;

        m_CommandBuffer = new CommandBuffer();
        m_CommandBuffer.name = “[Caustic CB]“;
        m_Camera.AddCommandBuffer(CameraEvent.AfterImageEffectsOpaque m_CommandBuffer);

        m_Mesh = Utils.GenerateLiquidMesh(width length geometryCellSize);

    }

    void OnPostRender()
    {
        //绘制焦散mesh
        Matrix4x4 trs = Matrix4x4.TRS(transform.position Quaternion.identity Vector3.one);
        m_CommandBuffer.Clear();
        m_CommandBuffer.ClearRenderTarget(true true Color.black);

        m_CommandBuffer.SetRenderTarget(m_RenderTexture);

        m_CommandBuffer.DrawMesh(m_Mesh trs material);

        Vector4 plane = new Vector4(0 1 0 Vector3.Dot(new Vector3(0 1 0) transform.position));
        Vector4 range = new Vector4(transform.position.x transform.position.z width * 0.5f length * 0.5f);

        Shader.SetGlobalVector(“_CausticPlane“ plane);
        Shader.SetGlobalVector(“_CausticRange“ range);
        Shader.SetGlobalTexture(“_CausticMap“ m_RenderTexture);
        Shader.SetGlobalVector(“_CausticDepthRange“ causticDepthRange);
        Shader.SetGlobalFloat(“_CausticIntensity“ causticIntensity);
    }

    void OnDestroy()
    {
        if (m_RenderTexture)
            Destroy(m_RenderTexture);
        if (m_Mesh)
            Destroy(m_Mesh);
        if (m_CommandBuffer != null)

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-10-08 15:11  UnityWaveEquation-master\
     文件         422  2018-10-08 15:11  UnityWaveEquation-master\.gitignore
     目录           0  2018-10-08 15:11  UnityWaveEquation-master\Assets\
     文件         191  2018-10-08 15:11  UnityWaveEquation-master\Assets\LiquidSimulator.meta
     目录           0  2018-10-08 15:11  UnityWaveEquation-master\Assets\LiquidSimulator\
     文件         191  2018-10-08 15:11  UnityWaveEquation-master\Assets\LiquidSimulator\Examples.meta
     目录           0  2018-10-08 15:11  UnityWaveEquation-master\Assets\LiquidSimulator\Examples\
     文件       26448  2018-10-08 15:11  UnityWaveEquation-master\Assets\LiquidSimulator\Examples\Demo.unity
     文件         174  2018-10-08 15:11  UnityWaveEquation-master\Assets\LiquidSimulator\Examples\Demo.unity.meta
     文件         191  2018-10-08 15:11  UnityWaveEquation-master\Assets\LiquidSimulator\Examples\Materials.meta
     目录           0  2018-10-08 15:11  UnityWaveEquation-master\Assets\LiquidSimulator\Examples\Materials\
     文件         191  2018-10-08 15:11  UnityWaveEquation-master\Assets\LiquidSimulator\Examples\Materials\Render.meta
     目录           0  2018-10-08 15:11  UnityWaveEquation-master\Assets\LiquidSimulator\Examples\Materials\Render\
     文件        5048  2018-10-08 15:11  UnityWaveEquation-master\Assets\LiquidSimulator\Examples\Materials\Render\caustic.mat
     文件         207  2018-10-08 15:11  UnityWaveEquation-master\Assets\LiquidSimulator\Examples\Materials\Render\caustic.mat.meta
     文件        5620  2018-10-08 15:11  UnityWaveEquation-master\Assets\LiquidSimulator\Examples\Materials\Render\water.mat
     文件         207  2018-10-08 15:11  UnityWaveEquation-master\Assets\LiquidSimulator\Examples\Materials\Render\water.mat.meta
     文件        5172  2018-10-08 15:11  UnityWaveEquation-master\Assets\LiquidSimulator\Examples\Materials\Render\waterbody.mat
     文件         207  2018-10-08 15:11  UnityWaveEquation-master\Assets\LiquidSimulator\Examples\Materials\Render\waterbody.mat.meta
     文件        5116  2018-10-08 15:11  UnityWaveEquation-master\Assets\LiquidSimulator\Examples\Materials\sky.mat
     文件         207  2018-10-08 15:11  UnityWaveEquation-master\Assets\LiquidSimulator\Examples\Materials\sky.mat.meta
     文件         191  2018-10-08 15:11  UnityWaveEquation-master\Assets\LiquidSimulator\Examples\Meshes.meta
     目录           0  2018-10-08 15:11  UnityWaveEquation-master\Assets\LiquidSimulator\Examples\Meshes\
     文件         191  2018-10-08 15:11  UnityWaveEquation-master\Assets\LiquidSimulator\Examples\Meshes\Materials.meta
     目录           0  2018-10-08 15:11  UnityWaveEquation-master\Assets\LiquidSimulator\Examples\Meshes\Materials\
     文件        5448  2018-10-08 15:11  UnityWaveEquation-master\Assets\LiquidSimulator\Examples\Meshes\Materials\01 - Default 1.mat
     文件         207  2018-10-08 15:11  UnityWaveEquation-master\Assets\LiquidSimulator\Examples\Meshes\Materials\01 - Default 1.mat.meta
     文件        5448  2018-10-08 15:11  UnityWaveEquation-master\Assets\LiquidSimulator\Examples\Meshes\Materials\01 - Default 2.mat
     文件         207  2018-10-08 15:11  UnityWaveEquation-master\Assets\LiquidSimulator\Examples\Meshes\Materials\01 - Default 2.mat.meta
     文件        5408  2018-10-08 15:11  UnityWaveEquation-master\Assets\LiquidSimulator\Examples\Meshes\Materials\01 - Default.mat
     文件         207  2018-10-08 15:11  UnityWaveEquation-master\Assets\LiquidSimulator\Examples\Meshes\Materials\01 - Default.mat.meta
............此处省略104个文件信息

评论

共有 条评论

相关资源