public void ClearAll() { RTUtility.ClearColor(transmittanceT); RTUtility.ClearColor(irradianceT_Read); RTUtility.ClearColor(irradianceT_Write); }
void ApplySlippage() { for (int i = 0; i < TERRAIN_LAYERS; i++) { if (m_talusAngle[i] < 90.0f) { float talusAngle = (Mathf.PI * m_talusAngle[i]) / 180.0f; float maxHeightDif = Mathf.Tan(talusAngle) * CELL_LENGTH; m_slippageHeightMat.SetFloat("_TexSize", (float)TEX_SIZE); m_slippageHeightMat.SetFloat("_Layers", (float)(i + 1)); m_slippageHeightMat.SetFloat("_MaxHeightDif", maxHeightDif); m_slippageHeightMat.SetTexture("_TerrainField", m_terrainField[READ]); Graphics.Blit(null, m_slippageHeight, m_slippageHeightMat); m_slippageOutflowMat.SetFloat("_TexSize", (float)TEX_SIZE); m_slippageOutflowMat.SetFloat("_Layers", (float)(i + 1)); m_slippageOutflowMat.SetFloat("T", TIME_STEP); m_slippageOutflowMat.SetTexture("_MaxSlippageHeights", m_slippageHeight); m_slippageOutflowMat.SetTexture("_TerrainField", m_terrainField[READ]); Graphics.Blit(null, m_slippageOutflow, m_slippageOutflowMat); m_slippageUpdateMat.SetFloat("T", TIME_STEP); m_slippageUpdateMat.SetFloat("_TexSize", (float)TEX_SIZE); m_slippageUpdateMat.SetFloat("_Layers", (float)(i + 1)); m_slippageUpdateMat.SetTexture("_SlippageOutflow", m_slippageOutflow); Graphics.Blit(m_terrainField[READ], m_terrainField[WRITE], m_slippageUpdateMat); RTUtility.Swap(m_terrainField); } } }
/// <summary> /// Create the render targets for the reflection camera and the reflection texture. /// </summary> void CreateRenderTarget(ReflectionData data, string camName, int width, int height, bool isHdr, OceanCameraSettings settings) { int scale = ResolutionToNumber(GetReflectionResolution(settings)); width /= scale; height /= scale; //If the texture has been created and settings have not changed //just update the ansio settings and return. if (data.tex != null && data.tex.width == width && data.tex.height == height) { data.tex.anisoLevel = ansio; return; } //Settings have changed or textures not created. if (data.tex != null) { RTUtility.ReleaseAndDestroy(data.tex); } RenderTextureFormat format; if (isHdr || QualitySettings.activeColorSpace == ColorSpace.Linear) { format = RenderTextureFormat.ARGBHalf; } else { format = RenderTextureFormat.ARGB32; } //This is the actual texture that will be sampled from for the reflections data.tex = new RenderTexture(width, height, 0, format, RenderTextureReadWrite.Default); data.tex.filterMode = FilterMode.Bilinear; data.tex.wrapMode = TextureWrapMode.Clamp; data.tex.useMipMap = false; data.tex.anisoLevel = ansio; data.tex.hideFlags = HideFlags.HideAndDontSave; data.tex.name = "Ceto Reflection Texture: " + camName; //This is the camera that will render the reflections. //Maybe null if a custom reflection method is being used. if (data.cam != null) { if (data.cam.targetTexture != null) { RTUtility.ReleaseAndDestroy(data.cam.targetTexture); } data.cam.targetTexture = new RenderTexture(width, height, 16, format, RenderTextureReadWrite.Default); data.cam.targetTexture.filterMode = FilterMode.Bilinear; data.cam.targetTexture.wrapMode = TextureWrapMode.Clamp; //data.cam.targetTexture.useMipMap = false; data.cam.targetTexture.anisoLevel = 0; data.cam.targetTexture.hideFlags = HideFlags.HideAndDontSave; data.cam.targetTexture.name = "Ceto Reflection Render Target: " + camName; } }
public void DestroyTargets() { RTUtility.ReleaseAndDestroy(target0); RTUtility.ReleaseAndDestroy(target1); target0 = null; target1 = null; }
/// <summary> /// /// </summary> public void ClearBuffers(WaveOverlayData data) { RTUtility.ClearColor(data.height, m_clearColor); RTUtility.ClearColor(data.normal, m_clearColor); RTUtility.ClearColor(data.foam, m_clearColor); RTUtility.ClearColor(data.clip, m_clearColor); }
void ErosionAndDeposition() { m_tiltAngleMat.SetFloat("_TexSize", (float)TEX_SIZE); m_tiltAngleMat.SetFloat("_Layers", TERRAIN_LAYERS); m_tiltAngleMat.SetTexture("_TerrainField", m_terrainField[READ]); Graphics.Blit(null, m_tiltAngle, m_tiltAngleMat); m_erosionAndDepositionMat.SetTexture("_TerrainField", m_terrainField[READ]); m_erosionAndDepositionMat.SetTexture("_SedimentField", m_sedimentField[READ]); m_erosionAndDepositionMat.SetTexture("_VelocityField", m_waterVelocity[READ]); m_erosionAndDepositionMat.SetTexture("_TiltAngle", m_tiltAngle); m_erosionAndDepositionMat.SetFloat("_MinTiltAngle", m_minTiltAngle); m_erosionAndDepositionMat.SetFloat("_SedimentCapacity", m_sedimentCapacity); m_erosionAndDepositionMat.SetVector("_DissolvingConstant", m_dissolvingConstant); m_erosionAndDepositionMat.SetFloat("_DepositionConstant", m_depositionConstant); m_erosionAndDepositionMat.SetFloat("_Layers", (float)TERRAIN_LAYERS); RenderTexture[] terrainAndSediment = new RenderTexture[2] { m_terrainField[WRITE], m_sedimentField[WRITE] }; RTUtility.MultiTargetBlit(terrainAndSediment, m_erosionAndDepositionMat); RTUtility.Swap(m_terrainField); //RTUtility.Swap(m_sedimentField); }
void ApplyFreeSlip(RenderTexture[] field) { float u = 1.0f / (float)TEX_SIZE; Vector2 offset; Graphics.Blit(field[READ], field[WRITE]); offset = new Vector2(u, 0.0f); m_applyFreeSlipMat.SetVector("_Offset", offset); RTUtility.Blit(field[READ], field[WRITE], m_applyFreeSlipMat, m_rectLeft, 0, false); offset = new Vector2(0.0f, u); m_applyFreeSlipMat.SetVector("_Offset", offset); RTUtility.Blit(field[READ], field[WRITE], m_applyFreeSlipMat, m_rectBottom, 0, false); offset = new Vector2(-u, 0.0f); m_applyFreeSlipMat.SetVector("_Offset", offset); RTUtility.Blit(field[READ], field[WRITE], m_applyFreeSlipMat, m_rectRight, 0, false); offset = new Vector2(0.0f, -u); m_applyFreeSlipMat.SetVector("_Offset", offset); RTUtility.Blit(field[READ], field[WRITE], m_applyFreeSlipMat, m_rectTop, 0, false); RTUtility.Swap(field); }
public int PeformFFT(RenderTexture[] data0, RenderTexture[] data1) { if (this.m_butterflyLookupTable == null) { return(-1); } if (SystemInfo.supportedRenderTargetCount < 2) { throw new InvalidOperationException("System does not support at least 2 render targets"); } this.m_pass0RT2[0] = data0[0].colorBuffer; this.m_pass0RT2[1] = data1[0].colorBuffer; this.m_pass1RT2[0] = data0[1].colorBuffer; this.m_pass1RT2[1] = data1[1].colorBuffer; RenderBuffer depthBuffer = data0[0].depthBuffer; RenderBuffer depthBuffer2 = data0[1].depthBuffer; int num = 0; int num2 = 0; int i = 0; while (i < this.m_passes) { num = num2 % 2; int num3 = (num2 + 1) % 2; this.m_fourier.SetTexture("Ceto_ButterFlyLookUp", this.m_butterflyLookupTable[i]); this.m_fourier.SetTexture("Ceto_ReadBuffer0", data0[num3]); this.m_fourier.SetTexture("Ceto_ReadBuffer1", data1[num3]); if (num == 0) { RTUtility.MultiTargetBlit(this.m_pass0RT2, depthBuffer, this.m_fourier, 2); } else { RTUtility.MultiTargetBlit(this.m_pass1RT2, depthBuffer2, this.m_fourier, 2); } i++; num2++; } i = 0; while (i < this.m_passes) { num = num2 % 2; int num3 = (num2 + 1) % 2; this.m_fourier.SetTexture("Ceto_ButterFlyLookUp", this.m_butterflyLookupTable[i]); this.m_fourier.SetTexture("Ceto_ReadBuffer0", data0[num3]); this.m_fourier.SetTexture("Ceto_ReadBuffer1", data1[num3]); if (num == 0) { RTUtility.MultiTargetBlit(this.m_pass0RT2, depthBuffer, this.m_fourier, 3); } else { RTUtility.MultiTargetBlit(this.m_pass1RT2, depthBuffer2, this.m_fourier, 3); } i++; num2++; } return(num); }
protected override void Initilize(WaveSpectrumCondition condition, float time) { if (base.InitMaterial == null) { throw new InvalidOperationException("GPU buffer has not had its Init material set"); } if (base.InitPass == -1) { throw new InvalidOperationException("GPU buffer has not had its Init material pass set"); } base.InitMaterial.SetTexture("Ceto_Spectrum01", (!(condition.Spectrum01 != null)) ? Texture2D.blackTexture : condition.Spectrum01); base.InitMaterial.SetTexture("Ceto_Spectrum23", (!(condition.Spectrum23 != null)) ? Texture2D.blackTexture : condition.Spectrum23); base.InitMaterial.SetTexture("Ceto_WTable", condition.WTable); base.InitMaterial.SetVector("Ceto_InverseGridSizes", condition.InverseGridSizes()); base.InitMaterial.SetVector("Ceto_GridSizes", condition.GridSizes); base.InitMaterial.SetVector("Ceto_Offset", this.m_offset); base.InitMaterial.SetFloat("Ceto_Time", time); this.m_tmpList.Clear(); int num = this.m_buffers.Length; for (int i = 0; i < num; i++) { if (!this.m_buffers[i].disabled) { this.m_tmpList.Add(this.m_buffers[i].data[1]); } } num = this.m_tmpList.Count; if (num == 0) { return; } if (num == 1) { Graphics.Blit(null, this.m_tmpList[0], base.InitMaterial, base.InitPass); } else if (num == 2) { this.m_tmpBuffer2[0] = this.m_tmpList[0].colorBuffer; this.m_tmpBuffer2[1] = this.m_tmpList[1].colorBuffer; RTUtility.MultiTargetBlit(this.m_tmpBuffer2, this.m_tmpList[0].depthBuffer, base.InitMaterial, base.InitPass); } else if (num == 3) { this.m_tmpBuffer3[0] = this.m_tmpList[0].colorBuffer; this.m_tmpBuffer3[1] = this.m_tmpList[1].colorBuffer; this.m_tmpBuffer3[2] = this.m_tmpList[2].colorBuffer; RTUtility.MultiTargetBlit(this.m_tmpBuffer3, this.m_tmpList[0].depthBuffer, base.InitMaterial, base.InitPass); } else if (num == 4) { this.m_tmpBuffer4[0] = this.m_tmpList[0].colorBuffer; this.m_tmpBuffer4[1] = this.m_tmpList[1].colorBuffer; this.m_tmpBuffer4[2] = this.m_tmpList[2].colorBuffer; this.m_tmpBuffer4[3] = this.m_tmpList[3].colorBuffer; RTUtility.MultiTargetBlit(this.m_tmpBuffer4, this.m_tmpList[0].depthBuffer, base.InitMaterial, base.InitPass); } }
private void CreateMaskCameraFor(Camera cam, MaskData data) { if (data.cam == null) { GameObject gameObject = new GameObject("Ceto Mask Camera: " + cam.name); gameObject.hideFlags = HideFlags.HideAndDontSave; gameObject.AddComponent <IgnoreOceanEvents>(); gameObject.AddComponent <DisableFog>(); gameObject.AddComponent <DisableShadows>(); data.cam = gameObject.AddComponent <Camera>(); data.cam.clearFlags = CameraClearFlags.Color; data.cam.backgroundColor = Color.black; data.cam.cullingMask = 1 << LayerMask.NameToLayer(Ocean.OCEAN_LAYER); data.cam.enabled = false; data.cam.renderingPath = RenderingPath.Forward; data.cam.targetTexture = null; data.cam.useOcclusionCulling = false; data.cam.RemoveAllCommandBuffers(); data.cam.targetTexture = null; } data.cam.fieldOfView = cam.fieldOfView; data.cam.nearClipPlane = cam.nearClipPlane; data.cam.farClipPlane = cam.farClipPlane; data.cam.transform.position = cam.transform.position; data.cam.transform.rotation = cam.transform.rotation; data.cam.worldToCameraMatrix = cam.worldToCameraMatrix; data.cam.projectionMatrix = cam.projectionMatrix; data.cam.orthographic = cam.orthographic; data.cam.aspect = cam.aspect; data.cam.orthographicSize = cam.orthographicSize; data.cam.rect = new Rect(0f, 0f, 1f, 1f); if (data.cam.farClipPlane < this.OCEAN_BOTTOM_DEPTH * 2f) { data.cam.farClipPlane = this.OCEAN_BOTTOM_DEPTH * 2f; data.cam.ResetProjectionMatrix(); } RenderTexture targetTexture = data.cam.targetTexture; if (targetTexture == null || targetTexture.width != cam.pixelWidth || targetTexture.height != cam.pixelHeight) { if (targetTexture != null) { RTUtility.ReleaseAndDestroy(targetTexture); } int pixelWidth = cam.pixelWidth; int pixelHeight = cam.pixelHeight; int depth = 32; RenderTextureFormat format = RenderTextureFormat.RGHalf; if (!SystemInfo.SupportsRenderTextureFormat(format)) { format = RenderTextureFormat.ARGBHalf; } data.cam.targetTexture = new RenderTexture(pixelWidth, pixelHeight, depth, format, RenderTextureReadWrite.Linear); data.cam.targetTexture.filterMode = FilterMode.Point; data.cam.targetTexture.hideFlags = HideFlags.DontSave; data.cam.targetTexture.name = "Ceto Mask Render Target: " + cam.name; } }
/// <summary> /// Remove and release this camera /// and its data from the ocean. /// </summary> public void RemoveCameraData(Camera cam) { if (!m_cameraData.ContainsKey(cam)) { return; } CameraData data = m_cameraData[cam]; if (data.overlay != null) { OverlayManager.DestroyBuffers(data.overlay); } if (data.reflection != null) { RTUtility.ReleaseAndDestroy(data.reflection.tex); data.reflection.tex = null; if (data.reflection.cam != null) { RTUtility.ReleaseAndDestroy(data.reflection.cam.targetTexture); data.reflection.cam.targetTexture = null; Destroy(data.reflection.cam.gameObject); Destroy(data.reflection.cam); data.reflection.cam = null; } } if (data.depth != null) { if (data.depth.cam != null) { RTUtility.ReleaseAndDestroy(data.depth.cam.targetTexture); data.depth.cam.targetTexture = null; Destroy(data.depth.cam.gameObject); Destroy(data.depth.cam); data.depth.cam = null; } } if (data.mask != null) { if (data.mask.cam != null) { RTUtility.ReleaseAndDestroy(data.mask.cam.targetTexture); data.mask.cam.targetTexture = null; Destroy(data.mask.cam.gameObject); Destroy(data.mask.cam); data.mask.cam = null; } } m_cameraData.Remove(cam); }
private void CreateDepthCameraFor(Camera cam, DepthData data) { if (data.cam == null) { GameObject gameObject = new GameObject("Ceto Depth Camera: " + cam.name); gameObject.hideFlags = HideFlags.HideAndDontSave; gameObject.AddComponent <IgnoreOceanEvents>(); gameObject.AddComponent <DisableFog>(); gameObject.AddComponent <DisableShadows>(); data.cam = gameObject.AddComponent <Camera>(); data.cam.clearFlags = CameraClearFlags.Color; data.cam.backgroundColor = Color.white; data.cam.enabled = false; data.cam.renderingPath = RenderingPath.Forward; data.cam.targetTexture = null; data.cam.useOcclusionCulling = false; data.cam.RemoveAllCommandBuffers(); data.cam.targetTexture = null; } data.cam.fieldOfView = cam.fieldOfView; data.cam.nearClipPlane = cam.nearClipPlane; data.cam.farClipPlane = cam.farClipPlane; data.cam.transform.position = cam.transform.position; data.cam.transform.rotation = cam.transform.rotation; data.cam.worldToCameraMatrix = cam.worldToCameraMatrix; data.cam.projectionMatrix = cam.projectionMatrix; data.cam.orthographic = cam.orthographic; data.cam.aspect = cam.aspect; data.cam.orthographicSize = cam.orthographicSize; data.cam.rect = new Rect(0f, 0f, 1f, 1f); data.cam.layerCullDistances = cam.layerCullDistances; data.cam.layerCullSpherical = cam.layerCullSpherical; RenderTexture targetTexture = data.cam.targetTexture; if (targetTexture == null || targetTexture.width != cam.pixelWidth || targetTexture.height != cam.pixelHeight) { if (targetTexture != null) { RTUtility.ReleaseAndDestroy(targetTexture); } int pixelWidth = cam.pixelWidth; int pixelHeight = cam.pixelHeight; int depth = 24; RenderTextureFormat format = RenderTextureFormat.RGFloat; if (!SystemInfo.SupportsRenderTextureFormat(format)) { format = RenderTextureFormat.RGHalf; } if (!SystemInfo.SupportsRenderTextureFormat(format)) { format = RenderTextureFormat.ARGBHalf; } data.cam.targetTexture = new RenderTexture(pixelWidth, pixelHeight, depth, format, RenderTextureReadWrite.Linear); data.cam.targetTexture.filterMode = FilterMode.Bilinear; data.cam.targetTexture.hideFlags = HideFlags.DontSave; data.cam.targetTexture.name = "Ceto Ocean Depths Render Target: " + cam.name; } }
void WaterInput(Vector2 position) { waterInputMat.SetVector("_InputUV", position); waterInputMat.SetFloat("_Radius", waterInputRadius); waterInputMat.SetFloat("_Amount", waterInputAmount); Graphics.Blit(waterMap[READ], waterMap[WRITE], waterInputMat); RTUtility.Swap(waterMap); }
protected override void InitWaveSpectrum() { base.InitWaveSpectrum(); // Init jacobians (5,6,7) var buffers567 = new RenderTexture[] { FourierBuffer5[1], FourierBuffer6[1], FourierBuffer7[1] }; RTUtility.MultiTargetBlit(buffers567, InitJacobiansMaterial); }
private void Awake() { CreateBuffers(); HeightTexture = RTExtensions.CreateRTexture(QuadSettings.VerticesPerSideFull, 0, RenderTextureFormat.ARGB32); NormalTexture = RTExtensions.CreateRTexture(QuadSettings.VerticesPerSideFull, 0, RenderTextureFormat.ARGB32); RTUtility.ClearColor(new RenderTexture[] { HeightTexture, NormalTexture }); }
public int PeformFFT(RenderTexture[] data0) { if (ButterFlyLookupTable == null) { return(-1); } var pass0 = new RenderTexture[] { data0[0] }; var pass1 = new RenderTexture[] { data0[1] }; int i; int idx = 0; int idx1; int j = 0; for (i = 0; i < Passes; i++, j++) { idx = j % 2; idx1 = (j + 1) % 2; FourierMaterial.SetTexture("_ButterFlyLookUp", ButterFlyLookupTable[i]); FourierMaterial.SetTexture("_ReadBuffer0", data0[idx1]); if (idx == 0) { RTUtility.MultiTargetBlit(pass0, FourierMaterial, PASS_X_1); } else { RTUtility.MultiTargetBlit(pass1, FourierMaterial, PASS_X_1); } } for (i = 0; i < Passes; i++, j++) { idx = j % 2; idx1 = (j + 1) % 2; FourierMaterial.SetTexture("_ButterFlyLookUp", ButterFlyLookupTable[i]); FourierMaterial.SetTexture("_ReadBuffer0", data0[idx1]); if (idx == 0) { RTUtility.MultiTargetBlit(pass0, FourierMaterial, PASS_Y_1); } else { RTUtility.MultiTargetBlit(pass1, FourierMaterial, PASS_Y_1); } } return(idx); }
public void DestroyBuffers(WaveOverlayData data) { RTUtility.ReleaseAndDestroy(data.normal); RTUtility.ReleaseAndDestroy(data.height); RTUtility.ReleaseAndDestroy(data.foam); RTUtility.ReleaseAndDestroy(data.clip); data.normal = null; data.height = null; data.foam = null; data.clip = null; }
public void Tsunami() { RTUtility.SetToPoint(m_waterField); float line = 0f; m_tsunamiMat.SetFloat("_Z", line); m_tsunamiMat.SetFloat("_Amount", m_tsunamiAmount); Graphics.Blit(m_waterField[READ], m_waterField[WRITE], m_tsunamiMat); RTUtility.SetToBilinear(m_waterField); RTUtility.Swap(m_waterField); }
void LavaInput() { if (m_lavaInputAmount > 0.0f) { m_lavaInputMat.SetVector("_Point", m_lavaInputPoint); m_lavaInputMat.SetFloat("_Radius", m_lavaInputRadius); m_lavaInputMat.SetFloat("_Amount", m_lavaInputAmount); Graphics.Blit(m_lavaField[READ], m_lavaField[WRITE], m_lavaInputMat); RTUtility.Swap(m_lavaField); } }
public void addLava(float x, float y) { RTUtility.SetToPoint(m_lavaField); Vector2 m_lavaOutputPoint = new Vector2(x, y); m_lavaInputMat.SetVector("_Point", m_lavaOutputPoint); m_lavaInputMat.SetFloat("_Radius", m_terrainOutputRadius); m_lavaInputMat.SetFloat("_Amount", m_terrainOutputAmount); Graphics.Blit(m_lavaField[READ], m_lavaField[WRITE], m_lavaInputMat); RTUtility.SetToBilinear(m_lavaField); RTUtility.Swap(m_lavaField); }
/// <summary> /// Perform fourier tranform on three textures. /// </summary> public int PeformFFT(RenderTexture[] data0, RenderTexture[] data1, RenderTexture[] data2) { RenderTexture[] pass0 = new RenderTexture[] { data0[0], data1[0], data2[0] }; RenderTexture[] pass1 = new RenderTexture[] { data0[1], data1[1], data2[1] }; int i; int idx = 0; int idx1; int j = 0; for (i = 0; i < m_passes; i++, j++) { idx = j % 2; idx1 = (j + 1) % 2; m_fourier.SetTexture("_ButterFlyLookUp", m_butterflyLookupTable[i]); m_fourier.SetTexture("_ReadBuffer0", data0[idx1]); m_fourier.SetTexture("_ReadBuffer1", data1[idx1]); m_fourier.SetTexture("_ReadBuffer2", data2[idx1]); if (idx == 0) { RTUtility.MultiTargetBlit(pass0, m_fourier, PASS_X_3); } else { RTUtility.MultiTargetBlit(pass1, m_fourier, PASS_X_3); } } for (i = 0; i < m_passes; i++, j++) { idx = j % 2; idx1 = (j + 1) % 2; m_fourier.SetTexture("_ButterFlyLookUp", m_butterflyLookupTable[i]); m_fourier.SetTexture("_ReadBuffer0", data0[idx1]); m_fourier.SetTexture("_ReadBuffer1", data1[idx1]); m_fourier.SetTexture("_ReadBuffer2", data2[idx1]); if (idx == 0) { RTUtility.MultiTargetBlit(pass0, m_fourier, PASS_Y_3); } else { RTUtility.MultiTargetBlit(pass1, m_fourier, PASS_Y_3); } } return(idx); }
/// <summary> /// Initializes the data to the shader that needs to /// have the fourier transform applied to it this frame. /// </summary> /// <param name="t">time in seconds</param> protected virtual void InitWaveSpectrum(float t) { // init heights (0) and slopes (1,2) RenderTexture[] buffers012 = new RenderTexture[] { m_fourierBuffer0[1], m_fourierBuffer1[1], m_fourierBuffer2[1] }; m_initSpectrumMat.SetFloat("_T", t); RTUtility.MultiTargetBlit(buffers012, m_initSpectrumMat); // Init displacement (3,4) RenderTexture[] buffers34 = new RenderTexture[] { m_fourierBuffer3[1], m_fourierBuffer4[1] }; m_initDisplacementMat.SetTexture("_Buffer1", m_fourierBuffer1[1]); m_initDisplacementMat.SetTexture("_Buffer2", m_fourierBuffer2[1]); RTUtility.MultiTargetBlit(buffers34, m_initDisplacementMat); }
protected override void InitNode() { CreateBuffers(); HeightTexture = RTExtensions.CreateRTexture(QuadSettings.VerticesPerSideFull, 0, RenderTextureFormat.ARGB32); NormalTexture = RTExtensions.CreateRTexture(QuadSettings.VerticesPerSideFull, 0, RenderTextureFormat.ARGB32); RTUtility.ClearColor(new RenderTexture[] { HeightTexture, NormalTexture }); InitMaterial(); InitUniforms(QuadMaterial); }
void InitWaveSpectrum(float t) { m_initSpectrumMat.SetTexture("_Spectrum01", m_spectrum01); m_initSpectrumMat.SetTexture("_Spectrum23", m_spectrum23); m_initSpectrumMat.SetTexture("_WTable", m_WTable); m_initSpectrumMat.SetVector("_Offset", m_offset); m_initSpectrumMat.SetVector("_InverseGridSizes", m_inverseGridSizes); m_initSpectrumMat.SetFloat("_T", t); RenderTexture[] buffers = new RenderTexture[] { m_fourierBuffer0[1], m_fourierBuffer1[1], m_fourierBuffer2[1] }; RTUtility.MultiTargetBlit(buffers, m_initSpectrumMat); }
public void grabElement(float x, float y, int layer) { RTUtility.SetToPoint(m_terrainField); Vector2 m_terrainOutputPoint = new Vector2(x, y); m_terrainOutputMat.SetVector("_Point", m_terrainOutputPoint); m_terrainOutputMat.SetFloat("_Radius", m_terrainOutputRadius); m_terrainOutputMat.SetFloat("_Amount", m_terrainOutputAmount); m_terrainOutputMat.SetFloat("_Layer", layer); Graphics.Blit(m_terrainField[READ], m_terrainField[WRITE], m_terrainOutputMat); RTUtility.SetToBilinear(m_terrainField); RTUtility.Swap(m_terrainField); }
public void grabWater(float x, float y) { RTUtility.SetToPoint(m_waterField); float amnt = -m_terrainOutputAmount; Vector2 m_waterOutputPoint = new Vector2(x, y); m_waterInputMat.SetVector("_Point", m_waterOutputPoint); m_waterInputMat.SetFloat("_Radius", m_terrainOutputRadius); m_waterInputMat.SetFloat("_Amount", amnt); Graphics.Blit(m_waterField[READ], m_waterField[WRITE], m_waterInputMat); RTUtility.SetToBilinear(m_waterField); RTUtility.Swap(m_waterField); }
public override void Release() { this.m_tmpList.Clear(); this.m_fourier.Release(); int num = this.m_buffers.Length; for (int i = 0; i < num; i++) { RTUtility.ReleaseAndDestroy(this.m_buffers[i].data); this.m_buffers[i].data[0] = null; this.m_buffers[i].data[1] = null; } }
/// <summary> /// Initializes the data to the shader that needs to have the fourier transform applied to it this frame. /// </summary> protected virtual void InitWaveSpectrum() { // Init heights (0) and slopes (1,2) var buffers012 = new RenderTexture[] { FourierBuffer0[1], FourierBuffer1[1], FourierBuffer2[1] }; RTUtility.MultiTargetBlit(buffers012, InitSpectrumMaterial); // Init displacement (3,4) var buffers34 = new RenderTexture[] { FourierBuffer3[1], FourierBuffer4[1] }; InitDisplacementMaterial.SetTexture("_Buffer1", FourierBuffer1[1]); InitDisplacementMaterial.SetTexture("_Buffer2", FourierBuffer2[1]); RTUtility.MultiTargetBlit(buffers34, InitDisplacementMaterial); }
/// <summary> /// Release the buffers. /// </summary> public override void Release() { m_tmpList.Clear(); m_fourier.Release(); int count = m_buffers.Length; for (int i = 0; i < count; i++) { RTUtility.ReleaseAndDestroy(m_buffers[i].data); m_buffers[i].data[0] = null; m_buffers[i].data[1] = null; } }
void DisintegrateAndDeposit() { m_disintegrateAndDepositMat.SetFloat("_Layers", (float)TERRAIN_LAYERS); m_disintegrateAndDepositMat.SetTexture("_TerrainField", m_terrainField[READ]); m_disintegrateAndDepositMat.SetTexture("_WaterField", m_waterField[READ]); m_disintegrateAndDepositMat.SetTexture("_RegolithField", m_regolithField[READ]); m_disintegrateAndDepositMat.SetFloat("_MaxRegolith", m_maxRegolith); RenderTexture[] terrainAndRegolith = new RenderTexture[2] { m_terrainField[WRITE], m_regolithField[WRITE] }; RTUtility.MultiTargetBlit(terrainAndRegolith, m_disintegrateAndDepositMat); RTUtility.Swap(m_terrainField); RTUtility.Swap(m_regolithField); }