public Lighting(RenderSetting renderSetting) { maxPointLights = renderSetting.maxPointLights; maxDirectionalLights = renderSetting.maxDirectionalLights; maxSpotLights = renderSetting.maxSpotLights; //将shader中需要的属性参数映射为ID,加速传参 dLightCountId = Shader.PropertyToID("_DirectionalLightCount"); DLightColors = new Vector4[maxDirectionalLights]; DLightDirections = new Vector4[maxDirectionalLights]; dLightDirId = Shader.PropertyToID("_DirectionalLightDirections"); dLightColorId = Shader.PropertyToID("_DirectionalLightColors"); //点光源 pLightCountId = Shader.PropertyToID("_PointLightCount"); PLightColors = new Vector4[maxPointLights]; PLightPos = new Vector4[maxPointLights]; pLightPosId = Shader.PropertyToID("_PointLightPosition"); pLightColorId = Shader.PropertyToID("_PointLightColors"); //聚光灯 sLightCountId = Shader.PropertyToID("_SpotLightCount"); SLightColors = new Vector4[maxSpotLights]; SLightDirections = new Vector4[maxSpotLights]; SLightPos = new Vector4[maxSpotLights]; sLightPosId = Shader.PropertyToID("_SpotLightPosition"); sLightColorId = Shader.PropertyToID("_SpotLightColors"); sLightDirId = Shader.PropertyToID("_SpotLightDirections"); }
public Shadow(RenderSetting renderSetting) { shadowSetting = renderSetting.shadowSetting; //所有灯光的阴影信息 allDirectinalLightShadowDataId = Shader.PropertyToID("_DirectionalLightShadowData"); allDirectionalLightShadowData = new Vector4[renderSetting.maxDirectionalLights]; //世界转灯光空间矩阵 shadowmapMatricesId = Shader.PropertyToID("_DirectionalShadowMatrices"); shadowmapMatrices = new Matrix4x4[shadowSetting.directional.maxShadowedDirectionalLightCount * shadowSetting.directional.CascadeCount]; //shadowmap图集(通过DrawShadows自动设置?) dirShadowAtlasId = Shader.PropertyToID("_DirectionalShadowAtlas"); shadowAtlastSizeId = Shader.PropertyToID("_ShadowAtlasSize"); //cascadeCountId cascadeCountId = Shader.PropertyToID("_CascadeCount"); cascadeCullingSpheresId = Shader.PropertyToID("_CascadeCullingSpheres"); cascadeCullingSpheres = new Vector4[shadowSetting.directional.CascadeCount]; //1.边缘消隐 shadowDistanceFadeId = Shader.PropertyToID("_ShadowDistanceFade"); //2.normalbias castedNormalBiasId = Shader.PropertyToID("_CastedNormalBias"); castedNormalBias = new float[shadowSetting.directional.CascadeCount]; //3.PCF shadowPCFDataId = Shader.PropertyToID("_ShadowPCFData"); //4. //有效的阴影灯光数量 shadowmapLights = new ShadowedDirectionalLight[shadowSetting.directional.maxShadowedDirectionalLightCount]; }
public CatlikePipeline(RenderSetting renderSetting) { this.renderSetting = renderSetting; lighting = new Lighting(renderSetting); shadow = new Shadow(renderSetting); GraphicsSettings.useScriptableRenderPipelineBatching = this.renderSetting.useSRPBatcher; GraphicsSettings.lightsUseLinearIntensity = true; }
public void Render(ScriptableRenderContext context, Camera camera, RenderSetting renderSetting, CullingResults cullingResults) { this.context = context; this.camera = camera; this.renderSetting = renderSetting; this.cullingResults = cullingResults; buffer = CommandBufferPool.Get(GetType().Name); OnRender(); CommandBufferPool.Release(buffer); }