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 = shadowRequest.minFilterSize; var hdAsset = (GraphicsSettings.renderPipelineAsset as HDRenderPipelineAsset); if (hdAsset.renderPipelineSettings.hdShadowInitParams.shadowQuality == HDShadowQuality.VeryHigh && shadowRequest.lightType == (int)LightType.Directional) { data.shadowFilterParams0.x = shadowRequest.kernelSize; data.shadowFilterParams0.y = shadowRequest.lightAngle; data.shadowFilterParams0.z = shadowRequest.maxDepthBias; } return(data); }
public HDShadowManager(int width, int height, int maxShadowRequests, DepthBits atlasDepthBits, Shader clearShader) { Material clearMaterial = CoreUtils.CreateEngineMaterial(clearShader); // Prevent the list from resizing their internal container when we add shadow requests m_ShadowDatas.Capacity = maxShadowRequests; m_ShadowResolutionRequests.Capacity = maxShadowRequests; m_ShadowRequests = new HDShadowRequest[maxShadowRequests]; // The cascade atlas will be allocated only if there is a directional light m_Atlas = new HDShadowAtlas(width, height, HDShaderIDs._ShadowAtlasSize, clearMaterial, depthBufferBits: atlasDepthBits, name: "Shadow Map Atlas"); // Cascade atlas render texture will only be allocated if there is a shadow casting directional light m_CascadeAtlas = new HDShadowAtlas(1, 1, HDShaderIDs._CascadeShadowAtlasSize, clearMaterial, depthBufferBits: atlasDepthBits, name: "Cascade Shadow Map Atlas"); m_ShadowDataBuffer = new ComputeBuffer(maxShadowRequests, System.Runtime.InteropServices.Marshal.SizeOf(typeof(HDShadowData))); m_DirectionalShadowDataBuffer = new ComputeBuffer(1, System.Runtime.InteropServices.Marshal.SizeOf(typeof(HDDirectionalShadowData))); m_MaxShadowRequests = maxShadowRequests; }
public HDShadowManager(RenderPipelineResources renderPipelineResources, DepthBits directionalShadowDepthBits, HDShadowInitParameters.HDShadowAtlasInitParams punctualLightAtlasInfo, HDShadowInitParameters.HDShadowAtlasInitParams areaLightAtlasInfo, int maxShadowRequests, Shader clearShader) { Material clearMaterial = CoreUtils.CreateEngineMaterial(clearShader); // Prevent the list from resizing their internal container when we add shadow requests m_ShadowDatas.Capacity = maxShadowRequests; m_ShadowResolutionRequests.Capacity = maxShadowRequests; m_ShadowRequests = new HDShadowRequest[maxShadowRequests]; // The cascade atlas will be allocated only if there is a directional light m_Atlas = new HDShadowAtlas(renderPipelineResources, punctualLightAtlasInfo.shadowAtlasResolution, punctualLightAtlasInfo.shadowAtlasResolution, HDShaderIDs._ShadowmapAtlas, HDShaderIDs._ShadowAtlasSize, clearMaterial, depthBufferBits: punctualLightAtlasInfo.shadowAtlasDepthBits, name: "Shadow Map Atlas"); // Cascade atlas render texture will only be allocated if there is a shadow casting directional light HDShadowAtlas.BlurAlgorithm cascadeBlur = GetDirectionalShadowAlgorithm() == DirectionalShadowAlgorithm.IMS ? HDShadowAtlas.BlurAlgorithm.IM : HDShadowAtlas.BlurAlgorithm.None; m_CascadeAtlas = new HDShadowAtlas(renderPipelineResources, 1, 1, HDShaderIDs._ShadowmapCascadeAtlas, HDShaderIDs._CascadeShadowAtlasSize, clearMaterial, cascadeBlur, depthBufferBits: directionalShadowDepthBits, name: "Cascade Shadow Map Atlas"); m_AreaLightShadowAtlas = new HDShadowAtlas(renderPipelineResources, areaLightAtlasInfo.shadowAtlasResolution, areaLightAtlasInfo.shadowAtlasResolution, HDShaderIDs._AreaLightShadowmapAtlas, HDShaderIDs._AreaShadowAtlasSize, clearMaterial, HDShadowAtlas.BlurAlgorithm.EVSM, depthBufferBits: areaLightAtlasInfo.shadowAtlasDepthBits, name: "Area Light Shadow Map Atlas", momentAtlasShaderID: HDShaderIDs._AreaShadowmapMomentAtlas); m_ShadowDataBuffer = new ComputeBuffer(maxShadowRequests, System.Runtime.InteropServices.Marshal.SizeOf(typeof(HDShadowData))); m_DirectionalShadowDataBuffer = new ComputeBuffer(1, System.Runtime.InteropServices.Marshal.SizeOf(typeof(HDDirectionalShadowData))); m_MaxShadowRequests = maxShadowRequests; }