void Start() { if (waveEquationShader == null) { waveEquationShader = Shader.Find("LinHowe/WaveEquation"); } if (normalGenerateShader == null) { normalGenerateShader = Shader.Find("LinHowe/NormalGenerate"); } forceShader = Shader.Find("LinHowe/Force"); InitComponent(); waveComponent = WaveComponentsDictionary[ChooseWaveComponent]; d = 1.0f / MapSize; InitMesh(); if (!CheckSupport()) { return; } InitWaterCamera(); Shader.SetGlobalFloat("internal_Force", forceFactor); Shader.SetGlobalTexture("_WaveMap", WaveMap); }
public void Init(float width, float height, float depth, int texSize, IWaveComponent waveComponent) { this.waveComponent = waveComponent; waveComponent.InitWaterCamera(texSize, waveEquationMat); m_Camera = gameObject.AddComponent <Camera>(); m_Camera.aspect = width / height; m_Camera.backgroundColor = Color.black; m_Camera.cullingMask = 0; m_Camera.depth = 0; m_Camera.farClipPlane = depth; m_Camera.nearClipPlane = 0; m_Camera.orthographic = true; m_Camera.orthographicSize = height * 0.5f; m_Camera.clearFlags = CameraClearFlags.Depth; m_Camera.allowHDR = false; m_CommandBuffer = new CommandBuffer(); m_Camera.AddCommandBuffer(CameraEvent.AfterImageEffectsOpaque, m_CommandBuffer); RenderTexture tmp = RenderTexture.active; CurTexture = RenderTexture.GetTemporary(texSize, texSize, 16); CurTexture.name = "[CurTex]"; RenderTexture.active = CurTexture; GL.Clear(false, true, new Color(0, 0, 0, 0)); //PreTexture = RenderTexture.GetTemporary(texSize, texSize, 16); //PreTexture.name = "[PreTex]"; //RenderTexture.active = PreTexture; //GL.Clear(false, true, new Color(0, 0, 0, 0)); HeightMap = RenderTexture.GetTemporary(texSize, texSize, 16); HeightMap.name = "[HeightMap]"; RenderTexture.active = HeightMap; GL.Clear(false, true, new Color(0, 0, 0, 0)); NormalMap = RenderTexture.GetTemporary(texSize, texSize, 16); //NormalMap.format = RenderTextureFormat.ARGB32; NormalMap.name = "[NormalMap]"; RenderTexture.active = tmp; m_Camera.targetTexture = CurTexture; }