HDShadowData CreateShadowData(HDShadowRequest shadowRequest, HDShadowAtlas atlas) { HDShadowData data = new HDShadowData(); var devProj = shadowRequest.deviceProjection; var view = shadowRequest.view; data.proj = new Vector4(devProj.m00, devProj.m11, devProj.m22, devProj.m23); data.pos = shadowRequest.position; data.rot0 = new Vector3(view.m00, view.m01, view.m02); data.rot1 = new Vector3(view.m10, view.m11, view.m12); data.rot2 = new Vector3(view.m20, view.m21, view.m22); data.shadowToWorld = shadowRequest.shadowToWorld; // Compute the scale and offset (between 0 and 1) for the atlas coordinates float rWidth = 1.0f / atlas.width; float rHeight = 1.0f / atlas.height; data.atlasOffset = Vector2.Scale(new Vector2(rWidth, rHeight), new Vector2(shadowRequest.atlasViewport.x, shadowRequest.atlasViewport.y)); data.shadowMapSize = new Vector4(shadowRequest.atlasViewport.width, shadowRequest.atlasViewport.height, 1.0f / shadowRequest.atlasViewport.width, 1.0f / shadowRequest.atlasViewport.height); data.viewBias = shadowRequest.viewBias; data.normalBias = shadowRequest.normalBias; data.flags = shadowRequest.flags; data.edgeTolerance = shadowRequest.edgeTolerance; data.shadowFilterParams0.x = shadowRequest.shadowSoftness; data.shadowFilterParams0.y = HDShadowUtils.Asfloat(shadowRequest.blockerSampleCount); data.shadowFilterParams0.z = HDShadowUtils.Asfloat(shadowRequest.filterSampleCount); data.shadowFilterParams0.w = 0; return(data); }
void BuildLightCluster(CommandBuffer cmd, ComputeShader lightClusterCS, HDRaytracingEnvironment currentEnv, int numLights) { using (new ProfilingSample(cmd, "Build Light Cluster", CustomSamplerId.RaytracingBuildCluster.GetSampler())) { // Make sure the Cluster buffer has the right size int bufferSize = 64 * 64 * 32 * (currentEnv.maxNumLightsPercell + 3); if (m_LightCluster.count != bufferSize) { ResizeClusterBuffer(bufferSize); } // Grab the kernel int lightClusterKernel = lightClusterCS.FindKernel(m_LightClusterKernelName); // Inject all the parameters cmd.SetComputeBufferParam(lightClusterCS, lightClusterKernel, _RaytracingLightCluster, m_LightCluster); cmd.SetComputeVectorParam(lightClusterCS, _MinClusterPos, minClusterPos); cmd.SetComputeVectorParam(lightClusterCS, _MaxClusterPos, maxClusterPos); cmd.SetComputeVectorParam(lightClusterCS, _ClusterCellSize, clusterCellSize); cmd.SetComputeFloatParam(lightClusterCS, _LightPerCellCount, HDShadowUtils.Asfloat(currentEnv.maxNumLightsPercell)); cmd.SetComputeBufferParam(lightClusterCS, lightClusterKernel, _LightVolumes, m_LightVolumeGPUArray); cmd.SetComputeFloatParam(lightClusterCS, _LightVolumeCount, HDShadowUtils.Asfloat(numLights)); cmd.SetComputeBufferParam(lightClusterCS, lightClusterKernel, _RaytracingLightCullResult, m_LightCullResult); // Dispatch a compute int numGroupsX = 8; int numGroupsY = 8; int numGroupsZ = 4; cmd.DispatchCompute(lightClusterCS, lightClusterKernel, numGroupsX, numGroupsY, numGroupsZ); } }
void CullLights(CommandBuffer cmd, ComputeShader lightClusterCS, int numLights) { using (new ProfilingSample(cmd, "Cull Light Cluster", CustomSamplerId.RaytracingCullLights.GetSampler())) { // Make sure the culling buffer has the right size if (m_LightCullResult == null || m_LightCullResult.count != numLights) { ResizeCullResultBuffer(numLights); } // Grab the kernel int lightClusterCullKernel = lightClusterCS.FindKernel(m_LightCullKernelName); // Inject all the parameters cmd.SetComputeVectorParam(lightClusterCS, _ClusterCenterPosition, clusterCenter); cmd.SetComputeVectorParam(lightClusterCS, _ClusterDimension, clusterDimension); cmd.SetComputeFloatParam(lightClusterCS, _LightVolumeCount, HDShadowUtils.Asfloat(numLights)); cmd.SetComputeBufferParam(lightClusterCS, lightClusterCullKernel, _LightVolumes, m_LightVolumeGPUArray); cmd.SetComputeBufferParam(lightClusterCS, lightClusterCullKernel, _RaytracingLightCullResult, m_LightCullResult); // Dispatch a compute int numLightGroups = (numLights / 16 + 1); cmd.DispatchCompute(lightClusterCS, lightClusterCullKernel, numLightGroups, 1, 1); } }
HDShadowData CreateShadowData(HDShadowRequest shadowRequest, HDShadowAtlas atlas) { HDShadowData data = new HDShadowData(); var devProj = shadowRequest.deviceProjection; var view = shadowRequest.view; data.proj = new Vector4(devProj.m00, devProj.m11, devProj.m22, devProj.m23); data.pos = shadowRequest.position; data.rot0 = new Vector3(view.m00, view.m01, view.m02); data.rot1 = new Vector3(view.m10, view.m11, view.m12); data.rot2 = new Vector3(view.m20, view.m21, view.m22); data.shadowToWorld = shadowRequest.shadowToWorld; data.cacheTranslationDelta = new Vector3(0.0f, 0.0f, 0.0f); // Compute the scale and offset (between 0 and 1) for the atlas coordinates float rWidth = 1.0f / atlas.width; float rHeight = 1.0f / atlas.height; data.atlasOffset = Vector2.Scale(new Vector2(rWidth, rHeight), new Vector2(shadowRequest.atlasViewport.x, shadowRequest.atlasViewport.y)); data.shadowMapSize = new Vector4(shadowRequest.atlasViewport.width, shadowRequest.atlasViewport.height, 1.0f / shadowRequest.atlasViewport.width, 1.0f / shadowRequest.atlasViewport.height); data.viewBias = shadowRequest.viewBias; data.normalBias = shadowRequest.normalBias; data.flags = shadowRequest.flags; data.edgeTolerance = shadowRequest.edgeTolerance; data.shadowFilterParams0.x = shadowRequest.shadowSoftness; data.shadowFilterParams0.y = HDShadowUtils.Asfloat(shadowRequest.blockerSampleCount); data.shadowFilterParams0.z = HDShadowUtils.Asfloat(shadowRequest.filterSampleCount); data.shadowFilterParams0.w = shadowRequest.minFilterSize; var hdAsset = (GraphicsSettings.renderPipelineAsset as HDRenderPipelineAsset); if (hdAsset.currentPlatformRenderPipelineSettings.hdShadowInitParams.shadowQuality == HDShadowQuality.VeryHigh && shadowRequest.lightType == (int)LightType.Directional) { data.shadowFilterParams0.x = shadowRequest.kernelSize; data.shadowFilterParams0.y = shadowRequest.lightAngle; data.shadowFilterParams0.z = shadowRequest.maxDepthBias; } if (atlas.HasBlurredEVSM()) { data.shadowFilterParams0 = shadowRequest.evsmParams; } return(data); }
void SetDiffusionProfileAtIndex(DiffusionProfileSettings settings, int index) { // if the diffusion profile was already set and it haven't changed then there is nothing to upgrade if (setDiffusionProfiles[index] == settings && diffusionProfileUpdate[index] == settings.updateCount) { return; } // if the settings have not yet been initialized if (settings.profile.filterKernelNearField == null) { return; } thicknessRemaps[index] = settings.thicknessRemaps; shapeParams[index] = settings.shapeParams; transmissionTintsAndFresnel0[index] = settings.transmissionTintsAndFresnel0; disabledTransmissionTintsAndFresnel0[index] = settings.disabledTransmissionTintsAndFresnel0; worldScales[index] = settings.worldScales; for (int j = 0, n = DiffusionProfileConstants.SSS_N_SAMPLES_NEAR_FIELD; j < n; j++) { filterKernels[n * index + j].x = settings.profile.filterKernelNearField[j].x; filterKernels[n * index + j].y = settings.profile.filterKernelNearField[j].y; if (j < DiffusionProfileConstants.SSS_N_SAMPLES_FAR_FIELD) { filterKernels[n * index + j].z = settings.profile.filterKernelFarField[j].x; filterKernels[n * index + j].w = settings.profile.filterKernelFarField[j].y; } } diffusionProfileHashes[index] = HDShadowUtils.Asfloat(settings.profile.hash); // Erase previous value (This need to be done here individually as in the SSS editor we edit individual component) uint mask = 1u << index; texturingModeFlags &= ~mask; transmissionFlags &= ~mask; texturingModeFlags |= (uint)settings.profile.texturingMode << index; transmissionFlags |= (uint)settings.profile.transmissionMode << index; setDiffusionProfiles[index] = settings; diffusionProfileUpdate[index] = settings.updateCount; }
void EvaluateClusterDebugView(CommandBuffer cmd, HDCamera hdCamera, HDRaytracingEnvironment currentEnv) { ComputeShader lightClusterDebugCS = m_RenderPipelineRayTracingResources.lightClusterDebugCS; if (lightClusterDebugCS == null) { return; } Texture2D gradientTexture = m_RenderPipelineResources.textures.colorGradient; if (gradientTexture == null) { return; } var settings = VolumeManager.instance.stack.GetComponent <LightCluster>(); // Grab the kernel int m_LightClusterDebugKernel = lightClusterDebugCS.FindKernel("DebugLightCluster"); // Inject all the parameters to the debug compute cmd.SetComputeBufferParam(lightClusterDebugCS, m_LightClusterDebugKernel, _RaytracingLightCluster, m_LightCluster); cmd.SetComputeVectorParam(lightClusterDebugCS, _MinClusterPos, minClusterPos); cmd.SetComputeVectorParam(lightClusterDebugCS, _MaxClusterPos, maxClusterPos); cmd.SetComputeVectorParam(lightClusterDebugCS, _ClusterCellSize, clusterCellSize); cmd.SetComputeFloatParam(lightClusterDebugCS, _LightPerCellCount, HDShadowUtils.Asfloat(settings.maxNumLightsPercell.value)); cmd.SetComputeTextureParam(lightClusterDebugCS, m_LightClusterDebugKernel, _DebugColorGradientTexture, gradientTexture); cmd.SetComputeTextureParam(lightClusterDebugCS, m_LightClusterDebugKernel, HDShaderIDs._CameraDepthTexture, m_SharedRTManager.GetDepthStencilBuffer()); // Target output texture cmd.SetComputeTextureParam(lightClusterDebugCS, m_LightClusterDebugKernel, _DebutLightClusterTexture, m_DebugLightClusterTexture); // Texture dimensions int texWidth = hdCamera.actualWidth; int texHeight = hdCamera.actualHeight; // Dispatch the compute int lightVolumesTileSize = 8; int numTilesX = (texWidth + (lightVolumesTileSize - 1)) / lightVolumesTileSize; int numTilesY = (texHeight + (lightVolumesTileSize - 1)) / lightVolumesTileSize; cmd.DispatchCompute(lightClusterDebugCS, m_LightClusterDebugKernel, numTilesX, numTilesY, 1); }