135 lines
4.3 KiB
Plaintext
135 lines
4.3 KiB
Plaintext
Shader "Custom/URP/TransparentDiffuseImproved"
|
|
{
|
|
Properties
|
|
{
|
|
_BaseMap("Base Map", 2D) = "white" {}
|
|
_BaseColor("Color", Color) = (1,1,1,1)
|
|
|
|
_Metallic("Metallic", Range(0,1)) = 0
|
|
_Smoothness("Smoothness", Range(0,1)) = 0.5
|
|
|
|
_BumpMap("Normal Map", 2D) = "bump" {}
|
|
}
|
|
|
|
SubShader
|
|
{
|
|
Tags
|
|
{
|
|
"RenderPipeline"="UniversalRenderPipeline"
|
|
"Queue"="Transparent"
|
|
"RenderType"="Transparent"
|
|
}
|
|
|
|
Pass
|
|
{
|
|
Name "ForwardLit"
|
|
Tags { "LightMode"="UniversalForward" }
|
|
|
|
Blend SrcAlpha OneMinusSrcAlpha
|
|
ZWrite Off
|
|
Cull Back
|
|
|
|
HLSLPROGRAM
|
|
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
|
|
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS
|
|
#pragma multi_compile _ _ADDITIONAL_LIGHTS
|
|
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
|
|
|
struct Attributes
|
|
{
|
|
float4 positionOS : POSITION;
|
|
float3 normalOS : NORMAL;
|
|
float4 tangentOS : TANGENT;
|
|
float2 uv : TEXCOORD0;
|
|
};
|
|
|
|
struct Varyings
|
|
{
|
|
float4 positionHCS : SV_POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
float3 normalWS : TEXCOORD1;
|
|
float3 tangentWS : TEXCOORD2;
|
|
float3 bitangentWS : TEXCOORD3;
|
|
float3 positionWS : TEXCOORD4;
|
|
};
|
|
|
|
TEXTURE2D(_BaseMap);
|
|
SAMPLER(sampler_BaseMap);
|
|
|
|
TEXTURE2D(_BumpMap);
|
|
SAMPLER(sampler_BumpMap);
|
|
|
|
CBUFFER_START(UnityPerMaterial)
|
|
float4 _BaseColor;
|
|
float _Metallic;
|
|
float _Smoothness;
|
|
CBUFFER_END
|
|
|
|
Varyings vert (Attributes IN)
|
|
{
|
|
Varyings OUT;
|
|
|
|
OUT.positionWS = TransformObjectToWorld(IN.positionOS.xyz);
|
|
OUT.positionHCS = TransformWorldToHClip(OUT.positionWS);
|
|
OUT.uv = IN.uv;
|
|
|
|
OUT.normalWS = TransformObjectToWorldNormal(IN.normalOS);
|
|
OUT.tangentWS = TransformObjectToWorldDir(IN.tangentOS.xyz);
|
|
OUT.bitangentWS = cross(OUT.normalWS, OUT.tangentWS) * IN.tangentOS.w;
|
|
|
|
return OUT;
|
|
}
|
|
|
|
half4 frag (Varyings IN) : SV_Target
|
|
{
|
|
float4 baseMap = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, IN.uv);
|
|
float3 albedo = baseMap.rgb * _BaseColor.rgb;
|
|
float alpha = baseMap.a * _BaseColor.a;
|
|
|
|
float3 normalTS = UnpackNormal(SAMPLE_TEXTURE2D(_BumpMap, sampler_BumpMap, IN.uv));
|
|
|
|
float3x3 TBN = float3x3(
|
|
normalize(IN.tangentWS),
|
|
normalize(IN.bitangentWS),
|
|
normalize(IN.normalWS)
|
|
);
|
|
|
|
float3 normalWS = normalize(mul(normalTS, TBN));
|
|
|
|
InputData lightingInput;
|
|
lightingInput.positionWS = IN.positionWS;
|
|
lightingInput.normalWS = normalWS;
|
|
lightingInput.viewDirectionWS = normalize(GetWorldSpaceViewDir(IN.positionWS));
|
|
lightingInput.shadowCoord = TransformWorldToShadowCoord(IN.positionWS);
|
|
lightingInput.fogCoord = 0;
|
|
lightingInput.vertexLighting = float3(0,0,0);
|
|
lightingInput.bakedGI = SampleSH(normalWS);
|
|
|
|
SurfaceData surfaceData = (SurfaceData)0;
|
|
surfaceData.albedo = albedo;
|
|
surfaceData.alpha = alpha;
|
|
surfaceData.metallic = _Metallic;
|
|
surfaceData.specular = 0;
|
|
surfaceData.smoothness = _Smoothness;
|
|
surfaceData.normalTS = normalTS;
|
|
surfaceData.occlusion = 1;
|
|
surfaceData.emission = 0;
|
|
|
|
surfaceData.clearCoatMask = 0;
|
|
surfaceData.clearCoatSmoothness = 0;
|
|
|
|
half4 color = UniversalFragmentPBR(lightingInput, surfaceData);
|
|
|
|
color.a = alpha;
|
|
return color;
|
|
}
|
|
|
|
ENDHLSL
|
|
}
|
|
}
|
|
} |