URP and Standard Tonemapped Lit Shader without postprocessing (for Oculus Quest or mobile)

UPDATE: Now it includes a version of the shader for the Standard Builtin Pipeline + an example on how to implement it on a custom surface shader.
If you want to use with the builtin pipeline, just delete the URP folder to avoid compilation errors and use the “Tonemapped Standard” shader instead of the “Standard” shader.

This shader is a simple modification of the Universal Render Pipeline Lit shader to allow for tonemapping and color correction without having to use any postprocessing effect and without using HDR buffers.

All color corrections are applied inside the shader, so you don’t even need to use HDR in the camera to have nice color corrected tonemapped images. (although the shader is compatible with HDR in case you want to use postprocesses like Bloom or Glow)

This is specially important for the Oculus Quest, since you can’t do postprocessing effects on it.

Just import the package and replace all “Lit” shaders in your materials with the supplied “Universal Render Pipeline/Tonemapped Lit” and put the included “Tonemapped Lit Controller” prefab in your scene to control the color correction.

DOWNLOAD IT HERE FOR Unity 2019 (only URP)

DOWNLOAD IT HERE FOR Unity 2020.3.2f1 LTS (URP + Built-in Standard)

Color correction adjustments available:

  • Color Filter
  • Gamma
  • Contrast
  • Brightness
  • Saturation
  • Hue Shift (trippy effect)

Of course, you can modify those adjustments in realtime in your game to match the mood of each zone :wink:

WARNING! Be sure to disable the color correction before rendering lightmaps!
Otherwise the lightmaps colors will be off!

Limitations: Keep in mind this is only the regular Lit shader. Any other shader like the skybox shader would need to be modified to include the same color corrections. Although you only have to include the “TonemappedLitColorCorrection_Include.hlsl” in the shader an use the function “TonemappedLitColorCorrection(color)” to apply the global color corrections to any custom shader.
Also, since the shadergraph doesn’t expose any way (that I know) to modify the final output color, any custom shadergraph shader will not be compatible with this and just render without color correction.
Take a look at the shader file “LitForwardPass.hlsl” to see how to implement it in other shaders. (from '#include “TonemappedLitColorCorrection_Include.hlsl” ’ to the end)

Some examples:






this is using negative gamma, negative brightness, saturation boost and hue shift to correct the color:
Notice how the hue of the color is the same as the original render but the luminosity has been inverted. That would be cool for a comic book effect.

v1.01: Added Hue Shift and some minor QoL mods.
v1.02: Removed URP dependencies in the shader. This should make it easier to add in non URP specific shaders.

6 Likes

Amazing, I am definately giving this a try, you cheeky digital rascal, you :smile:

1 Like

Let’s hope someone at Unity sees this and exposes a way to modify the final output color of the shadergraph master node with custom functions.

3 Likes

It seems like such an obvious omission. I cannot imagine a single person not wanting this, and not just for VR.

Well, there is some performance penalty in this shader, since it has to convert from RGB to Hue Saturation and Value space color and back, also there is a “pow” in there to apply the gamma correction, and power functions are really expensive on mobile.
All of this can make this shader more expensive if you do a lot of overdraw in your scene, although if you do a lot of overdraw, you have bigger issues to deal with… lol
On desktop or consoles, the performance difference is negligible. On mobile, depending on the GPU, it will be slightly slower than applying a fullscreen effect if you were going to do some Glow or Bloom anyway (that’s the case of the TegraX1 in the Switch. The TegraX1 behaves more like a mini desktop GPU than a mobile one. It is thus very comfortable using fullscreen postprocesses and grabpasses)

However, for the Oculus Quest, it’s the only solution and it’s blazing fast :slight_smile:

EDIT: Oh, you were talking about exposing the final color in the shader graph! Well, yes, it’s a really weird omission.

1 Like

I mean both actually, I can’t see anyone not wanting a solution like what you’ve developed. I’d probably be able to add valves dither as well with a bit of tinkering (it’s kind of useless without final pixel as banding is caused by lighting).

1 Like

Oh! I forgot to specify it but, you NEED to disable the color correction before rendering your lightmaps!
There is a checkbox to enable and disable the effect in the shader controller script.

1 Like

I just added Hue Shift and some minor improvements (tooltips and minor refactoring)
I also removed the 0 limit for gamma, since it can be useful to go negative to have negative image effects :slight_smile:

this is using negative gamma, negative brightness, saturation boost and hue shift to correct the color:

1 Like

Updated to remove URP dependencies in the shader.
This should make it easier to add in non URP specific shaders.

That latest one seems to cause errors in latest 2020.2f2. Can’t trace where it’s from as it causes some error in URP according to the console (seems Unity’s got a lot worse at figuring out where errors come from recently).

Please try a fresh 2020.2f2 project - mine is mostly empty and I’ll try again in an empty one soon.

They probably changed the URP lit shader.
Not a problem, I’ll fix it later.

1 Like

Just having a nose now, it’s bewildering if you haven’t dived deep before. How do you even navigate this stuff ? :slight_smile:

1 Like

Yeah, it would be great if we had the docs of the actual code. Otherwise it’s a nightmare to navigate it.
That’s why I did my own uber shader for regular built-in forward renderer with single pass lighting.
And it ended up being both faster and prettier than URP because I only had to support the features I actually use and I could implement others that aren’t present by default, like specular lighting from lightmapped textures and lightprobes, anisotropy, fake subsurface scattering and iridescence. Plus it’s retrocompatible with built-in standard content, unlike URP and HDRP.
I really don’t like the current state of the render pipelines.
I just installed Unity 2020.2.2f1, I’ll fix it now.

1 Like

Fixed.
They changed quite a lot of things in URP’s lit shader.
I have uploaded a new version for Unity 2020.2.2f1 and higher but have left the 2019 version because it could be handy for someone on the LTS.

1 Like

You will have to delete the whole folder and import the new package to avoid errors.
Also, you may have to reassign the tonemapped Lit URP shader to your materials in case they still show pink after that.
(the shader is named the same, but it didn’t automatically reassign the shader to the materials in my project. I don’t know why.)

1 Like

Fantastic work with this :slight_smile:

1 Like

Thanks! But what we really need is a way to modify the final color in the shader graph master node. Otherwise we can’t do things like that in shaders made with the shader graph.
If you could bring this to the attention of the shader graph team, THAT would be fantastic :wink:

4 Likes

+1

Without doubt, already planned.

Without TMI, I’m working some of that Package Manager love within the Graphics forums these days to make sure we can get some more feedback acknowledged.

2 Likes

@atomicjoe Looks great. Do you think anything like can be done for built-in pipeline? :smile: Thanks for tips!