NFS 2015 Decal system idea

Hi there
Can any one help me with some idea on how to implement in Unity a decal system like NFS 2015 or Real Racing 3.
Links references or any others sort of help are welcome.
Thanks!!

Screen Space Decals in Warhammer 40,000: Space Marine

Not sure whether screen space decals are still the thing in 2017 though.

If the idea is to have a car with multiple decals that can be freely positioned and/or rotated by user…

Add second layer texture to the shader, then use render to texture to render the texture for it before the car is created for the first time. You could also grab this data and save it to disk later.

Hi @neginfinity i like your idea but can you please be more explicit on how to use rendertexture for decal?
I’ve already add a texture for decal for that I must paint the decal by hand in PS for example and it’s painful

I’ll try to read but screen space decal is not usable for complex shape…I’ve already tried an asset

Do you have experience writing shaders? There’s a tricky part there, and writing your own shaders is required.

Basically… painting a decal onto a mesh is the same as using a projector shader.
So, make a car material that has base texutre and decal texture, and then plug in render texture as a decal texture.

Here’s where it gets tricky. To paint a decal onto unwrapped car mesh, you need to write a shader that renders into texture space instead of world space. If you haven’t worked with shaders before, this may be confusing.

Basically, in vertex program you’ll need to use object’s uv coordinates to project it onto screen, but uses world position coordinates to determine where decal is projected. Something like this:

https://www.youtube.com/watch?v=hpWNeEmj38A

Shader "Unlit/DecalUnwrap"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        _decalBlend ("DecalBlend", Range(0.0, 1.0)) = 0.0
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 100

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float3 normal: NORMAL;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                float3 worldPos: TEXCOORD1;
                float3 worldNormal: TEXCOORD2;
                float4 vertex : SV_POSITION;
            };

            sampler2D _MainTex;
            float4 _MainTex_ST;
            float _decalBlend;
           
            v2f vert (appdata v)
            {
                v2f o;
                o.worldPos = mul(_Object2World, v.vertex).xyz;

                float3 curWorldPos = lerp(o.worldPos, float3(v.uv*2.0 - 1.0, 0.0), _decalBlend);
                o.vertex = mul(UNITY_MATRIX_VP, float4(curWorldPos, 1.0));
                o.worldNormal = mul(_Object2World, float4(v.normal, 0.0)).xyz;
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                return o;
            }
           
            fixed4 frag (v2f i) : SV_Target
            {
                fixed4 col = tex2D(_MainTex, i.uv);
                col.xyz *= i.worldNormal*0.5+0.5;
                return col;
            }
            ENDCG
        }
    }
}

I have some experience with shaders let met try what you suggested and I let you know what’s going on Thank for your help