public override void Render (ScriptableRenderContext context, Camera[] cameras)
2.清除屏幕颜色缓存
context.DrawSkybox(camera);
可以采用 ComdBuffer 写法
// clear buffers to the configured color
var cmd = new CommandBuffer();
cmd.ClearRenderTarget(true, true, m_ClearColor);
context.ExecuteCommandBuffer(cmd);
cmd.Release();
foreach (var camera in cameras){
// Create an structure to hold the culling paramaters
ScriptableCullingParameters cullingParams;
//Populate the culling paramaters from the camera
if (!CullResults.GetCullingParameters(camera, stereoEnabled, out cullingParams)) continue;
// if you like you can modify the culling paramaters here
cullingParams.isOrthographic = true;
// Create a structure to hold the cull results
CullResults cullResults = new CullResults();
// Perform the culling operation
CullResults.Cull(ref cullingParams, context, ref cullResults);
//接下来的代码
}
2.3 模型选择
从裁剪出的模型 挑选出此次需要渲染的模型,根据:
(1) 渲染队列中的位置
(2) layer的序号
示例1
// Get the opaque rendering filter settings
var opaqueRange = new FilterRenderersSettings();
//Set the range to be the opaque queues
opaqueRange.renderQueueRange = new RenderQueueRange() {
min = 0,
max = (int)UnityEngine.Rendering.RenderQueue.GeometryLast,
};
//Include all layers opaqueRange.layerMask = ~0;
示例 2
var filterSettings = new FilterRenderersSettings(true) {
renderQueueRange = RenderQueueRange.transparent,
layerMask = 1 << LayerDefine.CHARA
};
renderQueueRange 可通过 min和max 或者 Shader 中的渲染模式获取
layerMask 采用二进制掩码的方式获取应该渲染的层级
2.4 渲染参数
模型的渲染可以考虑下面这些渲染参数的选择
HDR vs LDR
Linear vs Gamma
MSAA vs Post Process AA
PBR Materials vs Simple Materials
Lighting vs No Lighting
Lighting Technique
Shadowing Technique
设置渲染参数 ,即渲染所使用的Shader配置
// Create the draw render settings
// note that it takes a shader pass name
var drs = new DrawRendererSettings(myCamera, new ShaderPassName("Opaque"));
// enable instancing for the draw call
drs.flags = DrawRendererFlags.EnableInstancing;
// pass light probe and lightmap data to each renderer
drs.rendererConfiguration = RendererConfiguration.PerObjectLightProbe | RendererConfiguration.PerObjectLightmaps;
// sort the objects like normal opaque objects
drs.sorting.flags = SortFlags.CommonOpaque;
// draw all of the renderers
context.DrawRenderers(cullResults.visibleRenderers, ref drs, opaqueRange);