148 lines
5.8 KiB
Plaintext
148 lines
5.8 KiB
Plaintext
Shader "NatureManufacture Shaders/Trees/Tree Bark Metalic"
|
|
{
|
|
Properties
|
|
{
|
|
_Color ("Color", Vector) = (1,1,1,0)
|
|
_MainTex ("MainTex", 2D) = "white" {}
|
|
[NoScaleOffset] _BumpMap ("BumpMap", 2D) = "bump" {}
|
|
_BumpScale ("BumpScale", Range(0, 5)) = 1
|
|
[NoScaleOffset] _MetalicRAOGSmothnessA ("Metalic (R) AO (G) Smothness (A)", 2D) = "white" {}
|
|
_MetallicPower ("Metallic Power", Range(0, 2)) = 0
|
|
_AmbientOcclusionPower ("Ambient Occlusion Power", Range(0, 1)) = 1
|
|
_SmoothnessPower ("Smoothness Power", Range(0, 2)) = 0
|
|
_DetailMask ("DetailMask", 2D) = "black" {}
|
|
_DetailAlbedoMap ("DetailAlbedoMap", 2D) = "white" {}
|
|
[Toggle(_DETALUSEUV3_ON)] _DetalUseUV3 ("Detal Use UV3", Float) = 0
|
|
[NoScaleOffset] _DetailNormalMap ("DetailNormalMap", 2D) = "bump" {}
|
|
_DetailNormalMapScale ("DetailNormalMapScale", Range(0, 5)) = 1
|
|
[NoScaleOffset] _DetailMetalicRAOGSmothnessA ("Detail Metalic (R) AO (G) Smothness (A) ", 2D) = "white" {}
|
|
[Toggle(_WIND_DISABLE)] _WindDisable ("Disable Wind", Float) = 0
|
|
_InitialBend ("Wind Initial Bend", Float) = 1
|
|
_Stiffness ("Wind Stiffness", Float) = 1
|
|
_Drag ("Wind Drag", Float) = 1
|
|
[Toggle(_TOUCHREACTACTIVE_ON)] _TouchReactActive ("TouchReactActive", Float) = 0
|
|
[HideInInspector] _texcoord3 ("", 2D) = "white" {}
|
|
[HideInInspector] _texcoord ("", 2D) = "white" {}
|
|
[HideInInspector] __dirty ("", Float) = 1
|
|
}
|
|
|
|
SubShader
|
|
{
|
|
Tags
|
|
{
|
|
"RenderPipeline"="UniversalRenderPipeline" "RenderType"="Opaque"
|
|
}
|
|
LOD 200
|
|
|
|
Pass
|
|
{
|
|
Name "ForwardLit"
|
|
Tags
|
|
{
|
|
"LightMode"="UniversalForward"
|
|
}
|
|
|
|
HLSLPROGRAM
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#pragma target 3.0
|
|
#pragma multi_compile_fog
|
|
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE
|
|
#pragma multi_compile _ _ADDITIONAL_LIGHTS
|
|
#pragma multi_compile_fragment _ _SHADOWS_SOFT
|
|
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderVariablesFunctions.hlsl"
|
|
|
|
// Textures
|
|
TEXTURE2D(_MainTex);
|
|
SAMPLER(sampler_MainTex);
|
|
TEXTURE2D(_BumpMap);
|
|
SAMPLER(sampler_BumpMap);
|
|
TEXTURE2D(_MetalicRAOGSmothnessA);
|
|
SAMPLER(sampler_MetalicRAOGSmothnessA);
|
|
|
|
// Properties
|
|
float4 _Color;
|
|
float _BumpScale;
|
|
float _MetallicPower;
|
|
float _AmbientOcclusionPower;
|
|
float _SmoothnessPower;
|
|
|
|
float4 _MainTex_ST;
|
|
|
|
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 viewDirWS : TEXCOORD4;
|
|
};
|
|
|
|
Varyings vert(Attributes IN)
|
|
{
|
|
Varyings OUT;
|
|
float3 positionWS = TransformObjectToWorld(IN.positionOS.xyz);
|
|
OUT.positionHCS = TransformWorldToHClip(positionWS);
|
|
|
|
OUT.uv = TRANSFORM_TEX(IN.uv, _MainTex);
|
|
|
|
OUT.normalWS = TransformObjectToWorldNormal(IN.normalOS);
|
|
OUT.tangentWS = TransformObjectToWorldDir(IN.tangentOS.xyz);
|
|
OUT.bitangentWS = cross(OUT.normalWS, OUT.tangentWS) * IN.tangentOS.w;
|
|
OUT.viewDirWS = _WorldSpaceCameraPos - positionWS;
|
|
|
|
return OUT;
|
|
}
|
|
|
|
half4 frag(Varyings IN) : SV_Target
|
|
{
|
|
// Albedo
|
|
half4 baseColor = _Color * SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, IN.uv);
|
|
|
|
// Normal map
|
|
float3 normalTS = UnpackNormalScale(SAMPLE_TEXTURE2D(_BumpMap, sampler_BumpMap, IN.uv), _BumpScale);
|
|
float3x3 TBN = float3x3(normalize(IN.tangentWS), normalize(IN.bitangentWS), normalize(IN.normalWS));
|
|
float3 normalWS = normalize(mul(normalTS, TBN));
|
|
|
|
// Metallic / AO / Smoothness map
|
|
float4 packed = SAMPLE_TEXTURE2D(_MetalicRAOGSmothnessA, sampler_MetalicRAOGSmothnessA, IN.uv);
|
|
float metallic = packed.r * _MetallicPower;
|
|
float ao = lerp(1.0, packed.g, _AmbientOcclusionPower);
|
|
float smoothness = packed.a * _SmoothnessPower;
|
|
|
|
// Lighting
|
|
InputData lightingInput = (InputData)0;
|
|
lightingInput.normalWS = normalWS;
|
|
lightingInput.viewDirectionWS = normalize(IN.viewDirWS);
|
|
lightingInput.positionWS = float3(0, 0, 0); // optional, for advanced lighting
|
|
lightingInput.shadowCoord = float4(0, 0, 0, 0); // optional
|
|
|
|
SurfaceData surfaceData = (SurfaceData)0;
|
|
surfaceData.albedo = baseColor.rgb;
|
|
surfaceData.metallic = metallic;
|
|
surfaceData.specular = 0.0;
|
|
surfaceData.smoothness = smoothness;
|
|
surfaceData.emission = 0.0;
|
|
surfaceData.occlusion = ao;
|
|
surfaceData.alpha = baseColor.a;
|
|
|
|
return UniversalFragmentPBR(lightingInput, surfaceData);
|
|
}
|
|
ENDHLSL
|
|
}
|
|
}
|
|
|
|
FallBack "Hidden/InternalErrorShader"
|
|
} |