How to change render state in URP16

I just want to change the cull mode CullMode.Back to CullMode.Front though, I can not make it with CommandBuffer.DrawRendererList() new RendererList sytem function. Since there is no parameter in the parameter list that receive RenderStateBlock in CreateDrawingSetteing() function, I have to set RenderStateBlock to param.stateBlocks manually(this is real weired isn’t it?).

Used to be Context.DrawRenderers() function had the parameter as;

// Before URP 16
context.DrawRenderers(renderingData.cullResults, ref drawSettings, ref _filteringSettings, ref _renderStateBlock);

Now URP16 RendererList system, what I guessed and tried is as follows,

_renderStateBlock = new RenderStateBlock(RenderStateMask.Raster);
_renderStateBlock.rasterState = new RasterState(cullingMode: CullMode.Front, offsetUnits: 0, offsetFactor: 0, depthClip: true);
.
.
.
var sortingCriteria = _isOpaque ? renderingData.cameraData.defaultOpaqueSortFlags : SortingCriteria.CommonTransparent;
var drawSettings = CreateDrawingSettings(_shaderTagIdList, ref renderingData, sortingCriteria);
RendererListParams param = new RendererListParams(renderingData.cullResults, drawSettings, _filteringSettings );
NativeArray<RenderStateBlock> blocks = new NativeArray<RenderStateBlock>( 1, Allocator.Temp );
blocks[0] = _renderStateBlock;
param.stateBlocks = blocks;

RendererList rendererList = context.CreateRendererList(ref param);
cmd.DrawRendererList(rendererList);

This code brings exception that tagValue seems to be not initialized even though the tagName passed to drawSettings propery.

So, I want to know proper way to set RenderStateBlock for DrawRendererList function.

Hi, yes I think you’re right, and what’s even weirder is the multiple ways to create a RendererList (RendererListDesc & RendererListParams).

I also noticed before that using RendererListParams to create a RendererList was broken on some older versions of URP. (probably URP 12)

Do you have it passed to the param.tagValues (or maybe param.tagName)? I don’t use the Params way but it should be similar to Desc.

Hello, wwWwwwW1

Yes. It worked by setting tagValues!
But this is weired because I pass shader tag id array to drawingSettings and RendererListParams constructor supposes to receive shader tag ids through the drawingSettings. A bug isn’t it? or intended?
Thank you anyway!

NativeArray<ShaderTagId> id = new NativeArray<ShaderTagId>(1, Allocator.Temp );
id[0] = _shaderTagIdList[0];
param.tagValues = id;
1 Like