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); }
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); } }
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. LodDataMgrSeaFloorDepth.Bind(simMaterial); LodDataMgrFlow.Bind(simMaterial); }
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); }
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); } }
protected override void BindInputsAndOutputs(PropertyWrapperComputeStandalone wrapper, ComputeBuffer resultsBuffer) { LodDataMgrFlow.Bind(wrapper); ShaderProcessQueries.SetBuffer(_kernelHandle, sp_ResultFlows, resultsBuffer); }