Disable Fog for URP Lit ShaderGraph

Scenario: An environment with many objects with different materials that need fog but there is some special ShaderGraph material objects that do not need fog.

Hack for Editor:

  1. Of course you have enabled Fog in LightingSettings
  2. Create a ShaderGraph and add these 3 FOG keywords
  3. Make sure the Reference are exactly “FOG_LINEAR“, “FOG_EXP” and “FOG_EXP2
  4. Create a material and use this ShaderGraph
  5. I’m using Exponential Squared fog in Lighting Settings so I turn off “FOG_EXP” and “FOG_EXP2”, but leaving “FOG_LINEAR” checked does the trick

Hack for Player:

  1. Create a shader variant stripping script
  2. Put it in Editor folder
  3. Make a player build
using System.Collections.Generic;
using UnityEditor.Build;
using UnityEditor.Rendering;
using UnityEngine;
using UnityEngine.Rendering;

class StrippingExample_Shader : IPreprocessShaders
{
    public StrippingExample_Shader()
    {

    }

    public int callbackOrder { get { return 99; } }

    public void OnProcessShader(Shader shader, ShaderSnippetData snippet, IList<ShaderCompilerData> data)
    {
        for (int i = 0; i < data.Count; ++i)
        {
            //Get a string of keywords
            string variantText = "";
            foreach(ShaderKeyword s in data[i].shaderKeywordSet.GetShaderKeywords())
            {
                variantText += " " +s.name;
            }

            bool wantToStrip = false;

            //Only stripping the shader graph that we don't want fog
            if(
                shader.name == "Shader Graphs/ShaderGraphNoFog" &&
                variantText.Contains("FOG_")
            )
            {
                wantToStrip = true;
            }

            if ( wantToStrip )
            {
                //Strip the variant
                data.RemoveAt(i);
                --i;
            }
        }
    }
}

Get the test project here if you need (Open with Unity 2022.2)

3D scene need Linear but UI need Gamma

update: including UniversalRP (URP) workaround at bottom!

Having this problem?
https://forum.unity.com/threads/gamma-colors-for-ui-and-linear-for-scene.529923/

20190530_problem.jpg

Looking for a way to make only the UI matches to what is designed in Photoshop? Don’t want artists to change any workflow(possible solution for artists please refer to this comment) because you are in the middle of development? Try this.

Continue reading “3D scene need Linear but UI need Gamma”

[Custom SRP] How to use Unity features?

Update:

If you are using 2019.1+, you might notice there is a big change to the SRP APIs.
I’ve created a new repository and you can grab here. Much cleaner and minimal.

https://github.com/cinight/CustomSRP

 


 

May-14-2018 gif

Screen Shot 2018-06-02 at 22.16.24

SRPFlowScreen Shot 2018-05-12 at 18.52.43

(My playground pipeline)

Here lists out exact what codes enable the Unity feature when making our custom SRP.

*Note that my codes may not be perfectly optimised, but the concept itself won’t change.
(!) Alert: Below information might be outdated. I stopped updating this note after 2018.x releases.

Indicators:
icon_script In pipeline code
icon_shader In shader code
✅ Doesn’t need to specifically care about it in codes. Write the codes as usual.

Continue reading “[Custom SRP] How to use Unity features?”

Shader Compilation

Import time – when you create a .shader file

  • compile the shader variants only when needed, etc. platform, variants

Build time – when you build a player

  • [level 1] ShaderLab -> glsl or hlsl or …etc
    • if platform supports, from [level 2] hlsl -> IL or MetalSL to AIR…etc
  • Cache identical shaders under Library/ShaderCache
  • compile only not-yet-ever-compiled shaders (variants for this platform only)

Run time – when you open the app

  • [level 3] glsl or hlsl or IL or AIR…etc -> driver (GPU bytecode)
    • because target device is unknown for PC/mobile at buildtime
  • Depends on driver, when to compile these codes e.g. only when it’s used
    • use shader pre-warm to “use” shaders to trigger compilation

 

Sources from lukasc, robs, Unity Manual and https://blogs.unity3d.com/2014/05/06/shader-compilation-in-unity-4-5/

2 Unity Packages are already up

As mentioned, the Lava Flowing Shader has been released for free on Unity Asset Store!

Link: https://www.assetstore.unity3d.com/en/#!/content/33635

As my knowledge about shader keeps growing slowly, I found that I can blend more than 2 layers of “UV”…..It is because the 2 texcoords limit only limits on input. Your FBX model can only have 2 UV channels but shader can make instances of the 2 UV texcoords and thus let you have more layers of texture blending. I will try to update the package later.

*************************

Another package Simple SeeThrough Shader has been released on Unity Asset Store also. Link: https://www.assetstore.unity3d.com/en/#!/content/33924

Continue reading “2 Unity Packages are already up”