Notice
«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Tags
more
Archives
Today
Total
관리 메뉴

자라고싶다

[HLSL]Triplanar 본문

Unity/UnityShader

[HLSL]Triplanar

멍산 2023. 10. 16. 00:27

 

Shader "Example/Triplanar"
{

    Properties
    {
         _BaseTex("BaseTex", 2D) = "white"{}

         _Sharpen("Sharpen", Range(1,64)) = 1
    }


        SubShader
    {

        Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" }

        Pass
        {

            HLSLPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"

            struct Attributes
            {
                float4 positionOS   : POSITION;
                float3 normal       : NORMAL;
            };

            struct Varyings
            {
                float4 positionHCS  : SV_POSITION;
                float3 positionWS   : TEXCOORD1;
                float3 normal       : NORMAL;
                float3 normalWS     : TEXCOORD2;

            };

            float _Sharpen;

            TEXTURE2D(_BaseTex);
            SAMPLER(sampler_BaseTex);

            Varyings vert(Attributes IN)
            {
                Varyings OUT;

                OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);
                OUT.positionWS = TransformObjectToWorld(IN.positionOS);
                OUT.normal = IN.normal;
                OUT.normalWS = TransformObjectToWorldNormal(IN.normal);

                return OUT;
            }


            half4 frag(Varyings IN) : SV_Target
            {

                float3 tuv = IN.positionWS.xyz;

                half4 txz = SAMPLE_TEXTURE2D(_BaseTex, sampler_BaseTex, tuv.xz);
                half4 txy = SAMPLE_TEXTURE2D(_BaseTex, sampler_BaseTex, tuv.xy);
                half4 tyz = SAMPLE_TEXTURE2D(_BaseTex, sampler_BaseTex, tuv.yz);


                float3 tnormal = pow(abs(IN.normalWS.xyz), _Sharpen);
                tnormal /= dot(tnormal, float3(1, 1, 1));

                half4 color = lerp(txy, txz , tnormal.y);
                color = lerp(color,tyz, tnormal.x);

                return color;

            }
            ENDHLSL
        }
    }
}

'Unity > UnityShader' 카테고리의 다른 글

[HLSL] Diffuse Wrap + Shadow Ramp  (0) 2023.10.17
[HLSL]2 Pass Outline  (0) 2023.10.16
[HLSL]DepthTexture  (0) 2023.10.16
[HLSL]MainLight  (0) 2023.10.16
[HLSL]NormalTexture To WorldNormal  (0) 2023.10.16