Seeing there is no tutorial about this and I’ve been recently playing with this so hopefully this would help someone like myself 🙂
In my case I’m using AppRemote only as I only want to grab Spotify’s current playing track information on my Android app + trigger song playing. If you are also going to use the Spotify Android SDK, make sure you have installed latest Spotify app on your Android device.
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:
Of course you have enabled Fog in LightingSettings
Create a ShaderGraph and add these 3 FOG keywords
Make sure the Reference are exactly “FOG_LINEAR“, “FOG_EXP” and “FOG_EXP2“
Create a material and use this ShaderGraph
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:
Create a shader variant stripping script
Put it in Editor folder
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;
}
}
}
}
A picture will be visually looking good when all these things are right. – silhoutte – composition – structure – layers – colors – greyscale – 2 level shading
(not talking about concept / ideas / stories etc..)
Tested with: 2020.1.0b16.4138 + URP 9.0.0-preview.38, Windows DX11
Objects with same material & same property values
SRP batcher ON material GPU instancing OFF
SRP batched
SRP batcher ON material GPU instancing ON
SRP batched (because if SRP batcher is ON, gpu instancing will be ignored)
SRP batcher OFF material GPU instancing ON
GPU instanced
Objects with different material & differentproperty values
SRP batcher ON material GPU instancing OFF
SRP batched
SRP batcher ON material GPU instancing ON
SRP batched (because if SRP batcher is ON, gpu instancing will be ignored)
SRP batcher OFF material GPU instancing ON
Not batched nor instanced (expected because they are different materials)
Objects with same material & differentproperty values set by MaterialPropertyBlock
SRP batcher ON material GPU instancing OFF
Not batched nor instanced (because MPB values are not same)
SRP batcher ON material GPU instancing ON
Not batched nor instanced (same as above)
SRP batcher OFF material GPU instancing ON
Not batched nor instanced (because properties are non-instanced)
According to Unity Documentation about GPU instancing, user can use MaterialProperyBlock to have different material properties for each instances. Apparently the test showed that this is not true anymore in Universal Render Pipeline.
Reason:
URP shader properties are all wrapped by SRP batcher macros “CBUFFER_START(UnityPerMaterial)”. GPU instancing need to use this macro “UNITY_INSTANCING_BUFFER_START(MyProps)”
This is my hack week project. First time trying to play with DOTS. Still not really sure how DOTS work after the week but getting components data are so easy and incredibly fast…