Unity Web Shader IDE
Full source <URP>/Shaders/2D/Include/Lit2DCommon.hlsl HLSL 53 lines 13 symbols 1 includes Hide source Show source
Lit2DCommon.hlsl <URP>/Shaders/2D/Include/Lit2DCommon.hlsl
Language
HLSL
Lines
53
Symbols
13
Includes
1
Open IDE root

<URP>/Shaders/2D/Include/Lit2DCommon.hlsl full source

#ifndef _LIT_2D_COMMON
#define _LIT_2D_COMMON

#include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/CombinedShapeLightShared.hlsl"

TEXTURE2D(_MainTex);
SAMPLER(sampler_MainTex);
UNITY_TEXTURE_STREAMING_DEBUG_VARS_FOR_TEX(_MainTex);

TEXTURE2D(_MaskTex);
SAMPLER(sampler_MaskTex);

TEXTURE2D(_NormalMap);
SAMPLER(sampler_NormalMap);

Varyings CommonLitVertex(Attributes input)
{
    Varyings o = (Varyings) 0;
    UNITY_SETUP_INSTANCE_ID(input);
    UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);

    o.positionCS = TransformObjectToHClip(input.positionOS);
#if defined(DEBUG_DISPLAY)
    o.positionWS = TransformObjectToWorld(input.positionOS);
    o.normalWS = TransformObjectToWorldDir(input.normal);
#endif
    o.uv = input.uv;
    o.lightingUV = half2(ComputeScreenPos(o.positionCS / o.positionCS.w).xy);
    return o;
}

half4 CommonLitFragment(Varyings input, half4 color)
{
    const half4 main = color * SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.uv);
    const half4 mask = SAMPLE_TEXTURE2D(_MaskTex, sampler_MaskTex, input.uv);
    const half3 normalTS = UnpackNormal(SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, input.uv));
    
    SurfaceData2D surfaceData;
    InputData2D inputData;

    InitializeSurfaceData(main.rgb, main.a, mask, normalTS, surfaceData);
    InitializeInputData(input.uv, input.lightingUV, inputData);

#if defined(DEBUG_DISPLAY)
    SETUP_DEBUG_TEXTURE_DATA_2D_NO_TS(inputData, input.positionWS, input.positionCS, _MainTex);
    surfaceData.normalWS = input.normalWS;
#endif

    return CombinedShapeLightShared(surfaceData, inputData);
}

#endif // _LIT_2D_COMMON