when does Clamp(0,1) happens?

On the screen,color is between(0,1), when pixel on GPU, blend is on ,like this:Blend ScrFactor DstFactor,SO ,when does Clamp Action happens,
when blending, the clamp operation happens immideately?
or just after all renderering end, flush to screen?

I would say within the Unity editor itself, before it even gets to the CPU or GPU considering that all colours are handled in the float 0,1 format within unity, its just the Editor extension which displays the colours as their RGB/HSV components.

I assume you’re not talking about the format of the color selector in Unity :wink:

In the rendering pipeline the output of a shader used to be clamped, but this is no longer the case. This means the values going into the blending operation can be outside of the 0 to 1 range. On desktop GPU’s that is. On mobile hardware it might still be clamped, because it makes computation a bit simpler.

On a desktop GPU, the blending operations are simply floating point calculations like in the shader. So doing alpha blending with a negative alpha might lead to some surprising results. To prevent this, you can of course just saturate the alpha in the shader before you output it.

lol jvo, swear the last time I read this it said something about 255 :wink: must have been another forum post, my bad.

I want to know the result values of blending,is that clamped? at what condition? may be related to the buffer format.like a HDR rendering, will not clamp values in it,not sure, so I need a guru make sure this issue[/QUOTE

All colour ouput is clamped to within the 0-1 intensity range, HOWEVER, whatever you want to do to modify that colour within the shader itself is totally up to you. There is a HDR rendering option within Unity, which I believe might actually be something you want to look into.

The condition runs a little like this vertex color in = clamped
Texture colour… well, that’s pretty much a given to be clamped in SDR formats.

Any other values… are whatever you make them to be.

That : COLOR semantic at the end of your fragment shader means its expecting a return pixel color value… which will be between 0-1.

Hope that’s a little clearer for you. :slight_smile:

Thanks guy,It is really helpful, I will see if could i make some miracle out of the COLOR semantic

My experience is that that COLOR semantic is not clamped to the 0 to 1 range right at that time. If you output an alpha from the shader with a value of -1 and use this alpha in the blending operation, the value used is -1 and not 0.

If you render to a 8 bit (non-HDR) target, it will of course get clamped to the 0 to 1 range after the blending operation. But that’s just because the render target implies a limitation to this range.

So, on desktop hardware, the shader output in COLOR will not be clamped to the 0 to 1 range.

I mean, unless Unity actually adds a saturate for you. But on hardware level, COLOR can consist of any four floating point values. (Including NaN for example.)

I was confused,when does the clamp operaton happens? It seems return to the original point :frowning: :slight_smile:

Just add alpha blending to a shader and output an alpha outside the 0 to 1 range and see what happens.