protected override void SetAdditionalSimParams(IPropertyWrapper simMaterial) { base.SetAdditionalSimParams(simMaterial); simMaterial.SetFloat(sp_Damping, Settings._damping); simMaterial.SetFloat(sp_Gravity, OceanRenderer.Instance.Gravity * Settings._gravityMultiplier); float laplacianKernelAngle = _rotateLaplacian ? Mathf.PI * 2f * Random.value : 0f; simMaterial.SetVector(sp_LaplacianAxisX, new Vector2(Mathf.Cos(laplacianKernelAngle), Mathf.Sin(laplacianKernelAngle))); // assign sea floor depth - to slot 1 current frame data. minor bug here - this depth will actually be from the previous frame, // because the depth is scheduled to render just before the animated waves, and this sim happens before animated waves. if (OceanRenderer.Instance._lodDataSeaDepths != null) { OceanRenderer.Instance._lodDataSeaDepths.BindResultData(simMaterial); } else { LodDataMgrSeaFloorDepth.BindNull(simMaterial); } if (OceanRenderer.Instance._lodDataFlow != null) { OceanRenderer.Instance._lodDataFlow.BindResultData(simMaterial); } else { LodDataMgrFlow.BindNull(simMaterial); } }
protected override void SetAdditionalSimParams(int lodIdx, IPropertyWrapper simMaterial) { base.SetAdditionalSimParams(lodIdx, simMaterial); simMaterial.SetFloat(sp_FoamFadeRate, Settings._foamFadeRate); simMaterial.SetFloat(sp_WaveFoamStrength, Settings._waveFoamStrength); simMaterial.SetFloat(sp_WaveFoamCoverage, Settings._waveFoamCoverage); simMaterial.SetFloat(sp_ShorelineFoamMaxDepth, Settings._shorelineFoamMaxDepth); simMaterial.SetFloat(sp_ShorelineFoamStrength, Settings._shorelineFoamStrength); // assign animated waves - to slot 1 current frame data OceanRenderer.Instance._lodDataAnimWaves.BindResultData(lodIdx, 1, simMaterial); // assign sea floor depth - to slot 1 current frame data if (OceanRenderer.Instance._lodDataSeaDepths) { OceanRenderer.Instance._lodDataSeaDepths.BindResultData(lodIdx, 1, simMaterial); } else { LodDataMgrSeaFloorDepth.BindNull(1, simMaterial); } // assign flow - to slot 1 current frame data if (OceanRenderer.Instance._lodDataFlow) { OceanRenderer.Instance._lodDataFlow.BindResultData(lodIdx, 1, simMaterial); } else { LodDataMgrFlow.BindNull(1, simMaterial); } }
protected override void SetAdditionalSimParams(int lodIdx, Material simMaterial) { base.SetAdditionalSimParams(lodIdx, simMaterial); simMaterial.SetFloat("_Damping", Settings._damping); simMaterial.SetFloat("_Gravity", OceanRenderer.Instance.Gravity); float laplacianKernelAngle = _rotateLaplacian ? Mathf.PI * 2f * Random.value : 0f; simMaterial.SetVector("_LaplacianAxisX", new Vector2(Mathf.Cos(laplacianKernelAngle), Mathf.Sin(laplacianKernelAngle))); // assign sea floor depth - to slot 1 current frame data. minor bug here - this depth will actually be from the previous frame, // because the depth is scheduled to render just before the animated waves, and this sim happens before animated waves. if (OceanRenderer.Instance._createSeaFloorDepthData) { OceanRenderer.Instance._lodDataSeaDepths.BindResultData(lodIdx, 1, simMaterial); } else { LodDataMgrSeaFloorDepth.BindNull(1, simMaterial); } if (OceanRenderer.Instance._createFlowSim) { OceanRenderer.Instance._lodDataFlow.BindResultData(lodIdx, 1, simMaterial); } else { LodDataMgrFlow.BindNull(1, simMaterial); } }
private void CleanUp() { foreach (var lodData in _lodDatas) { lodData.OnDisable(); } _lodDatas.Clear(); #if UNITY_EDITOR if (!EditorApplication.isPlaying && Root != null) { DestroyImmediate(Root.gameObject); } else #endif if (Root != null) { Destroy(Root.gameObject); } Root = null; _lodTransform = null; _lodDataAnimWaves = null; _lodDataClipSurface = null; _lodDataDynWaves = null; _lodDataFlow = null; _lodDataFoam = null; _lodDataSeaDepths = null; _lodDataShadow = null; }
void CombinePassPingPong(CommandBuffer buf) { var lodCount = OceanRenderer.Instance.CurrentLodCount; const int shaderPassCombineIntoAux = 0, shaderPassCopyResultBack = 1; // combine waves for (int lodIdx = lodCount - 1; lodIdx >= 0; lodIdx--) { // The per-octave wave buffers BindWaveBuffer(_combineMaterial[lodIdx], false); // Bind this LOD data (displacements). Option to disable the combine pass - very useful debugging feature. if (_shapeCombinePass) { BindResultData(_combineMaterial[lodIdx]); } else { BindNull(_combineMaterial[lodIdx]); } // Dynamic waves if (OceanRenderer.Instance._lodDataDynWaves) { OceanRenderer.Instance._lodDataDynWaves.BindCopySettings(_combineMaterial[lodIdx]); OceanRenderer.Instance._lodDataDynWaves.BindResultData(_combineMaterial[lodIdx]); } else { LodDataMgrDynWaves.BindNull(_combineMaterial[lodIdx]); } // Flow if (OceanRenderer.Instance._lodDataFlow) { OceanRenderer.Instance._lodDataFlow.BindResultData(_combineMaterial[lodIdx]); } else { LodDataMgrFlow.BindNull(_combineMaterial[lodIdx]); } _combineMaterial[lodIdx].SetInt(sp_LD_SliceIndex, lodIdx); // Combine this LOD's waves with waves from the LODs above into auxiliary combine buffer buf.SetRenderTarget(_combineBuffer); buf.DrawProcedural(Matrix4x4.identity, _combineMaterial[lodIdx].material, shaderPassCombineIntoAux, MeshTopology.Triangles, 3); // Copy combine buffer back to lod texture array buf.SetRenderTarget(_targets, 0, CubemapFace.Unknown, lodIdx); _combineMaterial[lodIdx].SetTexture(Shader.PropertyToID("_CombineBuffer"), _combineBuffer); buf.DrawProcedural(Matrix4x4.identity, _combineMaterial[lodIdx].material, shaderPassCopyResultBack, MeshTopology.Triangles, 3); } }
protected override void SetAdditionalSimParams(IPropertyWrapper simMaterial) { base.SetAdditionalSimParams(simMaterial); simMaterial.SetFloat(sp_Damping, Settings._damping); simMaterial.SetFloat(sp_Gravity, OceanRenderer.Instance.Gravity * Settings._gravityMultiplier); simMaterial.SetFloat(sp_CourantNumber, Settings._courantNumber); // assign sea floor depth - to slot 1 current frame data. minor bug here - this depth will actually be from the previous frame, // because the depth is scheduled to render just before the animated waves, and this sim happens before animated waves. LodDataMgrSeaFloorDepth.Bind(simMaterial); LodDataMgrFlow.Bind(simMaterial); }
protected override void BindInputsAndOutputs(PropertyWrapperComputeStandalone wrapper, ComputeBuffer resultsBuffer) { if (OceanRenderer.Instance._lodDataFlow != null) { OceanRenderer.Instance._lodDataFlow.BindResultData(wrapper); ShaderProcessQueries.SetTexture(_kernelHandle, sp_LD_TexArray_Flow, OceanRenderer.Instance._lodDataFlow.DataTexture); } else { LodDataMgrFlow.BindNull(wrapper); } ShaderProcessQueries.SetBuffer(_kernelHandle, sp_ResultFlows, resultsBuffer); }
protected override void SetAdditionalSimParams(IPropertyWrapper simMaterial) { base.SetAdditionalSimParams(simMaterial); simMaterial.SetFloat(sp_FoamFadeRate, Settings._foamFadeRate); simMaterial.SetFloat(sp_WaveFoamStrength, Settings._waveFoamStrength); simMaterial.SetFloat(sp_WaveFoamCoverage, Settings._waveFoamCoverage); simMaterial.SetFloat(sp_ShorelineFoamMaxDepth, Settings._shorelineFoamMaxDepth); simMaterial.SetFloat(sp_ShorelineFoamStrength, Settings._shorelineFoamStrength); // assign animated waves - to slot 1 current frame data LodDataMgrAnimWaves.Bind(simMaterial); // assign sea floor depth - to slot 1 current frame data LodDataMgrSeaFloorDepth.Bind(simMaterial); // assign flow - to slot 1 current frame data LodDataMgrFlow.Bind(simMaterial); }
// Called when visible to a camera void OnWillRenderObject() { if (OceanRenderer.Instance == null || Rend == null) { return; } // check if built-in pipeline being used if (Camera.current != null) { _currentCamera = Camera.current; } // Depth texture is used by ocean shader for transparency/depth fog, and for fading out foam at shoreline. _currentCamera.depthTextureMode |= DepthTextureMode.Depth; if (Rend.sharedMaterial != OceanRenderer.Instance.OceanMaterial) { Rend.sharedMaterial = OceanRenderer.Instance.OceanMaterial; } // per instance data if (_mpb == null) { _mpb = new PropertyWrapperMPB(); } Rend.GetPropertyBlock(_mpb.materialPropertyBlock); // blend LOD 0 shape in/out to avoid pop, if the ocean might scale up later (it is smaller than its maximum scale) var needToBlendOutShape = _lodIndex == 0 && OceanRenderer.Instance.ScaleCouldIncrease; var meshScaleLerp = needToBlendOutShape ? OceanRenderer.Instance.ViewerAltitudeLevelAlpha : 0f; // blend furthest normals scale in/out to avoid pop, if scale could reduce var needToBlendOutNormals = _lodIndex == _totalLodCount - 1 && OceanRenderer.Instance.ScaleCouldDecrease; var farNormalsWeight = needToBlendOutNormals ? OceanRenderer.Instance.ViewerAltitudeLevelAlpha : 1f; _mpb.SetVector(sp_InstanceData, new Vector3(meshScaleLerp, farNormalsWeight, _lodIndex)); // geometry data // compute grid size of geometry. take the long way to get there - make sure we land exactly on a power of two // and not inherit any of the lossy-ness from lossyScale. var scale_pow_2 = OceanRenderer.Instance.CalcLodScale(_lodIndex); var gridSizeGeo = scale_pow_2 / (0.25f * _lodDataResolution / _geoDownSampleFactor); var gridSizeLodData = gridSizeGeo / _geoDownSampleFactor; var mul = 1.875f; // fudge 1 var pow = 1.4f; // fudge 2 var normalScrollSpeed0 = Mathf.Pow(Mathf.Log(1f + 2f * gridSizeLodData) * mul, pow); var normalScrollSpeed1 = Mathf.Pow(Mathf.Log(1f + 4f * gridSizeLodData) * mul, pow); _mpb.SetVector(sp_GeomData, new Vector4(gridSizeLodData, gridSizeGeo, normalScrollSpeed0, normalScrollSpeed1)); // Assign LOD data to ocean shader var ldaws = OceanRenderer.Instance._lodDataAnimWaves; var ldsds = OceanRenderer.Instance._lodDataSeaDepths; var ldclip = OceanRenderer.Instance._lodDataClipSurface; var ldfoam = OceanRenderer.Instance._lodDataFoam; var ldflow = OceanRenderer.Instance._lodDataFlow; var ldshadows = OceanRenderer.Instance._lodDataShadow; _mpb.SetInt(LodDataMgr.sp_LD_SliceIndex, _lodIndex); if (ldaws != null) { ldaws.BindResultData(_mpb); } if (ldflow != null) { ldflow.BindResultData(_mpb); } else { LodDataMgrFlow.BindNull(_mpb); } if (ldfoam != null) { ldfoam.BindResultData(_mpb); } else { LodDataMgrFoam.BindNull(_mpb); } if (ldsds != null) { ldsds.BindResultData(_mpb); } else { LodDataMgrSeaFloorDepth.BindNull(_mpb); } if (ldclip != null) { ldclip.BindResultData(_mpb); } else { LodDataMgrClipSurface.BindNull(_mpb); } if (ldshadows != null) { ldshadows.BindResultData(_mpb); } else { LodDataMgrShadow.BindNull(_mpb); } var reflTex = PreparedReflections.GetRenderTexture(_currentCamera.GetHashCode()); if (reflTex) { _mpb.SetTexture(sp_ReflectionTex, reflTex); } else { _mpb.SetTexture(sp_ReflectionTex, Texture2D.blackTexture); } // Hack - due to SV_IsFrontFace occasionally coming through as true for back faces, // add a param here that forces ocean to be in underwater state. I think the root // cause here might be imprecision or numerical issues at ocean tile boundaries, although // i'm not sure why cracks are not visible in this case. var heightOffset = OceanRenderer.Instance.ViewerHeightAboveWater; _mpb.SetFloat(sp_ForceUnderwater, heightOffset < -2f ? 1f : 0f); Rend.SetPropertyBlock(_mpb.materialPropertyBlock); }
public override void BuildCommandBuffer(OceanRenderer ocean, CommandBuffer buf) { base.BuildCommandBuffer(ocean, buf); var lodCount = OceanRenderer.Instance.CurrentLodCount; // lod-dependent data _filterWavelength._lodCount = lodCount; for (int lodIdx = lodCount - 1; lodIdx >= 0; lodIdx--) { buf.SetRenderTarget(_waveBuffers, 0, CubemapFace.Unknown, lodIdx); buf.ClearRenderTarget(false, true, Color.black); foreach (var gerstner in _gerstnerComponents) { gerstner.BuildCommandBuffer(lodIdx, ocean, buf); } // draw any data with lod preference _filterWavelength._lodIdx = lodIdx; _filterWavelength._lodMaxWavelength = OceanRenderer.Instance._lodTransform.MaxWavelength(lodIdx); _filterWavelength._lodMinWavelength = _filterWavelength._lodMaxWavelength / 2f; SubmitDrawsFiltered(lodIdx, buf, _filterWavelength); } int combineShaderKernel = krnl_ShapeCombine; int combineShaderKernel_lastLOD = krnl_ShapeCombine_DISABLE_COMBINE; { bool isFlowOn = OceanRenderer.Instance._lodDataFlow != null; bool isDynWavesOn = OceanRenderer.Instance._lodDataDynWaves != null; // set the shader kernels that we will use. if (isFlowOn && isDynWavesOn) { combineShaderKernel = krnl_ShapeCombine_FLOW_ON_DYNAMIC_WAVE_SIM_ON; combineShaderKernel_lastLOD = krnl_ShapeCombine_FLOW_ON_DYNAMIC_WAVE_SIM_ON_DISABLE_COMBINE; } else if (isFlowOn) { combineShaderKernel = krnl_ShapeCombine_FLOW_ON; combineShaderKernel_lastLOD = krnl_ShapeCombine_FLOW_ON_DISABLE_COMBINE; } else if (isDynWavesOn) { combineShaderKernel = krnl_ShapeCombine_DYNAMIC_WAVE_SIM_ON; combineShaderKernel_lastLOD = krnl_ShapeCombine_DYNAMIC_WAVE_SIM_ON_DISABLE_COMBINE; } } // combine waves for (int lodIdx = lodCount - 1; lodIdx >= 0; lodIdx--) { int selectedShaderKernel; if (lodIdx < lodCount - 1 && _shapeCombinePass) { selectedShaderKernel = combineShaderKernel; } else { selectedShaderKernel = combineShaderKernel_lastLOD; } _combineProperties.Initialise(buf, _combineShader, selectedShaderKernel); BindWaveBuffer(_combineProperties); BindResultData(_combineProperties); // dynamic waves if (OceanRenderer.Instance._lodDataDynWaves) { OceanRenderer.Instance._lodDataDynWaves.BindCopySettings(_combineProperties); OceanRenderer.Instance._lodDataDynWaves.BindResultData(_combineProperties); } else { LodDataMgrDynWaves.BindNull(_combineProperties); } // flow if (OceanRenderer.Instance._lodDataFlow) { OceanRenderer.Instance._lodDataFlow.BindResultData(_combineProperties); } else { LodDataMgrFlow.BindNull(_combineProperties); } // Set the animated waves texture where the results will be combined. _combineProperties.SetTexture( sp_LD_TexArray_AnimatedWaves_Compute, DataTexture ); _combineProperties.SetFloat(OceanRenderer.sp_LD_SliceIndex, lodIdx); _combineProperties.DispatchShader(); } // lod-independent data for (int lodIdx = lodCount - 1; lodIdx >= 0; lodIdx--) { buf.SetRenderTarget(_targets, 0, CubemapFace.Unknown, lodIdx); // draw any data that did not express a preference for one lod or another SubmitDrawsFiltered(lodIdx, buf, _filterNoLodPreference); } }
void CreateDestroySubSystems() { { if (_lodDataAnimWaves == null) { _lodDataAnimWaves = new LodDataMgrAnimWaves(this); _lodDatas.Add(_lodDataAnimWaves); } } if (CreateClipSurfaceData) { if (_lodDataClipSurface == null) { _lodDataClipSurface = new LodDataMgrClipSurface(this); _lodDatas.Add(_lodDataClipSurface); } } else { if (_lodDataClipSurface != null) { _lodDataClipSurface.OnDisable(); _lodDatas.Remove(_lodDataClipSurface); _lodDataClipSurface = null; } } if (CreateDynamicWaveSim) { if (_lodDataDynWaves == null) { _lodDataDynWaves = new LodDataMgrDynWaves(this); _lodDatas.Add(_lodDataDynWaves); } } else { if (_lodDataDynWaves != null) { _lodDataDynWaves.OnDisable(); _lodDatas.Remove(_lodDataDynWaves); _lodDataDynWaves = null; } } if (CreateFlowSim) { if (_lodDataFlow == null) { _lodDataFlow = new LodDataMgrFlow(this); _lodDatas.Add(_lodDataFlow); } if (FlowProvider != null && !(FlowProvider is QueryFlow)) { FlowProvider.CleanUp(); FlowProvider = null; } } else { if (_lodDataFlow != null) { _lodDataFlow.OnDisable(); _lodDatas.Remove(_lodDataFlow); _lodDataFlow = null; } if (FlowProvider != null && FlowProvider is QueryFlow) { FlowProvider.CleanUp(); FlowProvider = null; } } if (FlowProvider == null) { FlowProvider = _lodDataAnimWaves.Settings.CreateFlowProvider(this); } if (CreateFoamSim) { if (_lodDataFoam == null) { _lodDataFoam = new LodDataMgrFoam(this); _lodDatas.Add(_lodDataFoam); } } else { if (_lodDataFoam != null) { _lodDataFoam.OnDisable(); _lodDatas.Remove(_lodDataFoam); _lodDataFoam = null; } } if (CreateSeaFloorDepthData) { if (_lodDataSeaDepths == null) { _lodDataSeaDepths = new LodDataMgrSeaFloorDepth(this); _lodDatas.Add(_lodDataSeaDepths); } } else { if (_lodDataSeaDepths != null) { _lodDataSeaDepths.OnDisable(); _lodDatas.Remove(_lodDataSeaDepths); _lodDataSeaDepths = null; } } if (CreateShadowData) { if (_lodDataShadow == null) { _lodDataShadow = new LodDataMgrShadow(this); _lodDatas.Add(_lodDataShadow); } } else { if (_lodDataShadow != null) { _lodDataShadow.OnDisable(); _lodDatas.Remove(_lodDataShadow); _lodDataShadow = null; } } // Potential extension - add 'type' field to collprovider and change provider if settings have changed - this would support runtime changes. if (CollisionProvider == null) { CollisionProvider = _lodDataAnimWaves.Settings.CreateCollisionProvider(); } }
void CombinePassCompute(CommandBuffer buf) { var lodCount = OceanRenderer.Instance.CurrentLodCount; int combineShaderKernel = krnl_ShapeCombine; int combineShaderKernel_lastLOD = krnl_ShapeCombine_DISABLE_COMBINE; { bool isFlowOn = OceanRenderer.Instance._lodDataFlow != null; bool isDynWavesOn = OceanRenderer.Instance._lodDataDynWaves != null; // set the shader kernels that we will use. if (isFlowOn && isDynWavesOn) { combineShaderKernel = krnl_ShapeCombine_FLOW_ON_DYNAMIC_WAVE_SIM_ON; combineShaderKernel_lastLOD = krnl_ShapeCombine_FLOW_ON_DYNAMIC_WAVE_SIM_ON_DISABLE_COMBINE; } else if (isFlowOn) { combineShaderKernel = krnl_ShapeCombine_FLOW_ON; combineShaderKernel_lastLOD = krnl_ShapeCombine_FLOW_ON_DISABLE_COMBINE; } else if (isDynWavesOn) { combineShaderKernel = krnl_ShapeCombine_DYNAMIC_WAVE_SIM_ON; combineShaderKernel_lastLOD = krnl_ShapeCombine_DYNAMIC_WAVE_SIM_ON_DISABLE_COMBINE; } } // combine waves for (int lodIdx = lodCount - 1; lodIdx >= 0; lodIdx--) { int selectedShaderKernel; if (lodIdx < lodCount - 1 && _shapeCombinePass) { selectedShaderKernel = combineShaderKernel; } else { selectedShaderKernel = combineShaderKernel_lastLOD; } _combineProperties.Initialise(buf, _combineShader, selectedShaderKernel); // The per-octave wave buffers BindWaveBuffer(_combineProperties); // Bind this LOD data (displacements) Bind(_combineProperties); // Dynamic waves LodDataMgrDynWaves.Bind(_combineProperties); if (OceanRenderer.Instance._lodDataDynWaves != null) { OceanRenderer.Instance._lodDataDynWaves.BindCopySettings(_combineProperties); } // Flow LodDataMgrFlow.Bind((_combineProperties)); // Set the animated waves texture where the results will be combined. _combineProperties.SetTexture( sp_LD_TexArray_AnimatedWaves_Compute, DataTexture ); _combineProperties.SetInt(sp_LD_SliceIndex, lodIdx); buf.DispatchCompute(_combineShader, selectedShaderKernel, OceanRenderer.Instance.LodDataResolution / THREAD_GROUP_SIZE_X, OceanRenderer.Instance.LodDataResolution / THREAD_GROUP_SIZE_Y, 1); } }
void CreateDestroyLodDatas() { { if (_lodDataAnimWaves == null) { _lodDataAnimWaves = new LodDataMgrAnimWaves(this); _lodDatas.Add(_lodDataAnimWaves); } } if (CreateClipSurfaceData) { if (_lodDataClipSurface == null) { _lodDataClipSurface = new LodDataMgrClipSurface(this); _lodDatas.Add(_lodDataClipSurface); } } else { if (_lodDataClipSurface != null) { _lodDataClipSurface.OnDisable(); _lodDatas.Remove(_lodDataClipSurface); _lodDataClipSurface = null; } } if (CreateDynamicWaveSim) { if (_lodDataDynWaves == null) { _lodDataDynWaves = new LodDataMgrDynWaves(this); _lodDatas.Add(_lodDataDynWaves); } } else { if (_lodDataDynWaves != null) { _lodDataDynWaves.OnDisable(); _lodDatas.Remove(_lodDataDynWaves); _lodDataDynWaves = null; } } if (CreateFlowSim) { if (_lodDataFlow == null) { _lodDataFlow = new LodDataMgrFlow(this); _lodDatas.Add(_lodDataFlow); } } else { if (_lodDataFlow != null) { _lodDataFlow.OnDisable(); _lodDatas.Remove(_lodDataFlow); _lodDataFlow = null; } } if (CreateFoamSim) { if (_lodDataFoam == null) { _lodDataFoam = new LodDataMgrFoam(this); _lodDatas.Add(_lodDataFoam); } } else { if (_lodDataFoam != null) { _lodDataFoam.OnDisable(); _lodDatas.Remove(_lodDataFoam); _lodDataFoam = null; } } if (CreateSeaFloorDepthData) { if (_lodDataSeaDepths == null) { _lodDataSeaDepths = new LodDataMgrSeaFloorDepth(this); _lodDatas.Add(_lodDataSeaDepths); } } else { if (_lodDataSeaDepths != null) { _lodDataSeaDepths.OnDisable(); _lodDatas.Remove(_lodDataSeaDepths); _lodDataSeaDepths = null; } } if (CreateShadowData) { if (_lodDataShadow == null) { _lodDataShadow = new LodDataMgrShadow(this); _lodDatas.Add(_lodDataShadow); } } else { if (_lodDataShadow != null) { _lodDataShadow.OnDisable(); _lodDatas.Remove(_lodDataShadow); _lodDataShadow = null; } } }
public override void BuildCommandBuffer(OceanRenderer ocean, CommandBuffer buf) { base.BuildCommandBuffer(ocean, buf); var lodCount = OceanRenderer.Instance.CurrentLodCount; // lod-dependent data for (int lodIdx = lodCount - 1; lodIdx >= 0; lodIdx--) { buf.SetRenderTarget(_waveBuffers[lodIdx]); buf.ClearRenderTarget(false, true, Color.black); foreach (var gerstner in _gerstnerComponents) { gerstner.BuildCommandBuffer(lodIdx, ocean, buf); } // draw any data with lod preference var lodMaxWavelength = OceanRenderer.Instance._lods[lodIdx].MaxWavelength(); var lodMinWavelength = lodMaxWavelength / 2f; DrawFilter filter = (data) => { var drawOctaveWavelength = (data as RegisterAnimWavesInput).OctaveWavelength; return(lodMinWavelength <= drawOctaveWavelength && drawOctaveWavelength < lodMaxWavelength); }; SubmitDrawsFiltered(lodIdx, buf, filter); } // combine waves for (int lodIdx = lodCount - 1; lodIdx >= 0; lodIdx--) { // this lod data BindWaveBuffer(lodIdx, 0, _combineMaterial[lodIdx], false); // combine data from next larger lod into this one if (lodIdx < lodCount - 1 && _shapeCombinePass) { BindResultData(lodIdx + 1, 1, _combineMaterial[lodIdx]); } else { // this binds black texture BindWaveBuffer(lodIdx, 1, _combineMaterial[lodIdx], true); } // dynamic waves if (OceanRenderer.Instance._lodDataDynWaves) { OceanRenderer.Instance._lodDataDynWaves.BindCopySettings(_combineMaterial[lodIdx]); OceanRenderer.Instance._lodDataDynWaves.BindResultData(lodIdx, 0, _combineMaterial[lodIdx]); } else { LodDataMgrDynWaves.BindNull(0, _combineMaterial[lodIdx]); } // flow if (OceanRenderer.Instance._lodDataFlow) { OceanRenderer.Instance._lodDataFlow.BindResultData(lodIdx, 0, _combineMaterial[lodIdx]); } else { LodDataMgrFlow.BindNull(0, _combineMaterial[lodIdx]); } buf.Blit(null, DataTexture(lodIdx), _combineMaterial[lodIdx]); } // lod-independent data for (int lodIdx = lodCount - 1; lodIdx >= 0; lodIdx--) { buf.SetRenderTarget(DataTexture(lodIdx)); // draw any data that did not express a preference for one lod or another DrawFilter filter = (data) => { return((data as RegisterAnimWavesInput).OctaveWavelength == 0f); }; SubmitDrawsFiltered(lodIdx, buf, filter); } }
protected override void BindInputsAndOutputs(PropertyWrapperComputeStandalone wrapper, ComputeBuffer resultsBuffer) { LodDataMgrFlow.Bind(wrapper); ShaderProcessQueries.SetBuffer(_kernelHandle, sp_ResultFlows, resultsBuffer); }
public override void BuildCommandBuffer(OceanRenderer ocean, CommandBuffer buf) { base.BuildCommandBuffer(ocean, buf); var lodCount = OceanRenderer.Instance.CurrentLodCount; // lod-dependent data _filterWavelength._lodCount = lodCount; for (int lodIdx = lodCount - 1; lodIdx >= 0; lodIdx--) { buf.SetRenderTarget(_waveBuffers[lodIdx]); buf.ClearRenderTarget(false, true, Color.black); foreach (var gerstner in _gerstnerComponents) { gerstner.BuildCommandBuffer(lodIdx, ocean, buf); } // draw any data with lod preference _filterWavelength._lodIdx = lodIdx; _filterWavelength._lodMaxWavelength = OceanRenderer.Instance._lods[lodIdx].MaxWavelength(); _filterWavelength._lodMinWavelength = _filterWavelength._lodMaxWavelength / 2f; SubmitDrawsFiltered(lodIdx, buf, _filterWavelength); } // combine waves for (int lodIdx = lodCount - 1; lodIdx >= 0; lodIdx--) { // this lod data BindWaveBuffer(lodIdx, 0, _combineProperties[lodIdx], false); // combine data from next larger lod into this one if (lodIdx < lodCount - 1 && _shapeCombinePass) { BindResultData(lodIdx + 1, 1, _combineProperties[lodIdx]); } else { // this binds black texture BindWaveBuffer(lodIdx, 1, _combineProperties[lodIdx], true); } // dynamic waves if (OceanRenderer.Instance._lodDataDynWaves) { OceanRenderer.Instance._lodDataDynWaves.BindCopySettings(_combineProperties[lodIdx]); OceanRenderer.Instance._lodDataDynWaves.BindResultData(lodIdx, 0, _combineProperties[lodIdx]); } else { LodDataMgrDynWaves.BindNull(0, _combineProperties[lodIdx]); } // flow if (OceanRenderer.Instance._lodDataFlow) { OceanRenderer.Instance._lodDataFlow.BindResultData(lodIdx, 0, _combineProperties[lodIdx]); } else { LodDataMgrFlow.BindNull(0, _combineProperties[lodIdx]); } buf.SetRenderTarget(DataTexture(lodIdx)); buf.DrawProcedural(Matrix4x4.identity, _combineMaterial, 0, MeshTopology.Triangles, 3, 1, _combineProperties[lodIdx].materialPropertyBlock); } // lod-independent data for (int lodIdx = lodCount - 1; lodIdx >= 0; lodIdx--) { buf.SetRenderTarget(DataTexture(lodIdx)); // draw any data that did not express a preference for one lod or another SubmitDrawsFiltered(lodIdx, buf, _filterNoLodPreference); } }