96 lines
3.7 KiB
Plaintext
96 lines
3.7 KiB
Plaintext
![]() |
Shader "2Ginge/Potion/Glass_Potion_URP" {
|
||
|
Properties {
|
||
|
_Color ("Color", Color) = (0.5, 0.5, 0.5, 1)
|
||
|
_Fres_Exp ("Fresnel Exp", Float ) = 0
|
||
|
_metallic ("Metallic", Range(0, 1)) = 0
|
||
|
_Gloss ("Gloss", Range(0, 1)) = 0
|
||
|
_Texture ("Texture", 2D) = "white" {}
|
||
|
_Normal ("Normal", 2D) = "bump" {}
|
||
|
[HideInInspector]_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
|
||
|
}
|
||
|
SubShader {
|
||
|
Tags {
|
||
|
"RenderType"="Transparent"
|
||
|
"Queue"="Transparent"
|
||
|
}
|
||
|
Pass {
|
||
|
Name "FORWARD"
|
||
|
Tags { "LightMode"="UniversalForward" }
|
||
|
Blend SrcAlpha OneMinusSrcAlpha
|
||
|
ZWrite Off
|
||
|
|
||
|
HLSLPROGRAM
|
||
|
#pragma vertex vert
|
||
|
#pragma fragment frag
|
||
|
#pragma multi_compile_fragment _ _MAIN_LIGHT_SHADOWS _ADDITIONAL_LIGHTS
|
||
|
#pragma multi_compile_fragment _ _SHADOWS_SOFT
|
||
|
#pragma multi_compile_fragment _ _LIGHT_LAYERS
|
||
|
#pragma multi_compile_fog
|
||
|
|
||
|
#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 positionCS : SV_POSITION;
|
||
|
float2 uv : TEXCOORD0;
|
||
|
float3 normalWS : TEXCOORD1;
|
||
|
float3 tangentWS : TEXCOORD2;
|
||
|
float3 bitangentWS : TEXCOORD3;
|
||
|
float3 viewDirWS : TEXCOORD4;
|
||
|
};
|
||
|
|
||
|
CBUFFER_START(UnityPerMaterial)
|
||
|
float4 _Color;
|
||
|
float _Fres_Exp;
|
||
|
float _metallic;
|
||
|
float _Gloss;
|
||
|
CBUFFER_END
|
||
|
|
||
|
TEXTURE2D(_Texture); SAMPLER(sampler_Texture);
|
||
|
TEXTURE2D(_Normal); SAMPLER(sampler_Normal);
|
||
|
|
||
|
Varyings vert(Attributes IN) {
|
||
|
Varyings OUT;
|
||
|
VertexPositionInputs posInputs = GetVertexPositionInputs(IN.positionOS.xyz);
|
||
|
VertexNormalInputs normalInputs = GetVertexNormalInputs(IN.normalOS, IN.tangentOS);
|
||
|
|
||
|
OUT.positionCS = posInputs.positionCS;
|
||
|
OUT.uv = IN.uv;
|
||
|
OUT.normalWS = normalInputs.normalWS;
|
||
|
OUT.tangentWS = normalInputs.tangentWS;
|
||
|
OUT.bitangentWS = normalInputs.bitangentWS;
|
||
|
OUT.viewDirWS = GetWorldSpaceViewDir(posInputs.positionWS);
|
||
|
|
||
|
return OUT;
|
||
|
}
|
||
|
|
||
|
half4 frag(Varyings IN) : SV_Target {
|
||
|
float3 normalTS = UnpackNormal(SAMPLE_TEXTURE2D(_Normal, sampler_Normal, IN.uv));
|
||
|
float3x3 TBN = float3x3(IN.tangentWS, IN.bitangentWS, IN.normalWS);
|
||
|
float3 normalWS = normalize(mul(normalTS, TBN));
|
||
|
|
||
|
float3 viewDir = normalize(IN.viewDirWS);
|
||
|
float3 lightDir = normalize(GetMainLight().direction);
|
||
|
float3 lightColor = GetMainLight().color;
|
||
|
|
||
|
float fresnelEffect = pow(1.0 - dot(viewDir, normalWS), _Fres_Exp);
|
||
|
float3 diffuse = lightColor * max(dot(normalWS, lightDir), 0.0);
|
||
|
float3 specular = pow(max(dot(reflect(-lightDir, normalWS), viewDir), 0.0), _Gloss * 128) * _metallic;
|
||
|
|
||
|
float4 baseColor = SAMPLE_TEXTURE2D(_Texture, sampler_Texture, IN.uv) * _Color;
|
||
|
float3 finalColor = baseColor.rgb * diffuse + specular + fresnelEffect;
|
||
|
|
||
|
return float4(finalColor, baseColor.a);
|
||
|
}
|
||
|
ENDHLSL
|
||
|
}
|
||
|
}
|
||
|
}
|