void CombinePassPingPong(CommandBuffer buf) { if (_combineMaterial == null) { return; } 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]); // Bind this LOD data (displacements). Option to disable the combine pass - very useful debugging feature. if (_shapeCombinePass) { Bind(_combineMaterial[lodIdx]); } else { _combineMaterial[lodIdx].SetTexture(GetParamIdSampler(), TextureArrayHelpers.BlackTextureArray); } // Dynamic waves LodDataMgrDynWaves.Bind(_combineMaterial[lodIdx]); if (OceanRenderer.Instance._lodDataDynWaves != null) { OceanRenderer.Instance._lodDataDynWaves.BindCopySettings(_combineMaterial[lodIdx]); } // Flow LodDataMgrFlow.Bind((_combineMaterial[lodIdx])); _combineMaterial[lodIdx].SetInt(sp_LD_SliceIndex, lodIdx); _combineMaterial[lodIdx].SetBuffer(OceanRenderer.sp_cascadeData, OceanRenderer.Instance._bufCascadeDataTgt); _combineMaterial[lodIdx].SetBuffer(OceanRenderer.sp_perCascadeInstanceData, OceanRenderer.Instance._bufPerCascadeInstanceData); // 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); } }
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); } }