아티스트를 위한 URP 셰이더 링크

아티스트를 위한 URP 셰이더 링크

https://chulin28ho.tistory.com/644

기본

// This shader fills the mesh shape with a color predefined in the code. Shader "Example/URPUnlitShaderBasic" { // The properties block of the Unity shader. In this example this block is empty // because the output color is predefined in the fragment shader code. Properties { } // The SubShader block containing the Shader code. SubShader { // SubShader Tags define when and under which conditions a SubShader block or // a pass is executed. Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" } Pass { // The HLSL code block. Unity SRP uses the HLSL language. HLSLPROGRAM // This line defines the name of the vertex shader. #pragma vertex vert // This line defines the name of the fragment shader. #pragma fragment frag // The Core.hlsl file contains definitions of frequently used HLSL // macros and functions, and also contains #include references to other // HLSL files (for example, Common.hlsl, SpaceTransforms.hlsl, etc.). #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" // The structure definition defines which variables it contains. // This example uses the Attributes structure as an input structure in // the vertex shader. struct Attributes { // The positionOS variable contains the vertex positions in object // space. float4 positionOS : POSITION; }; struct Varyings { // The positions in this struct must have the SV_POSITION semantic. float4 positionHCS : SV_POSITION; }; // The vertex shader definition with properties defined in the Varyings // structure. The type of the vert function must match the type (struct) // that it returns. Varyings vert(Attributes IN) { // Declaring the output object (OUT) with the Varyings struct. Varyings OUT; // The TransformObjectToHClip function transforms vertex positions // from object space to homogenous clip space. OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz); // Returning the output. return OUT; } // The fragment shader definition. half4 frag() : SV_Target { // Defining the color variable and returning it. half4 customColor = half4(0.5, 0, 0, 1); return customColor; } ENDHLSL } } }

칼라, 텍스쳐 UV

// This shader fills the mesh shape with a color predefined in the code. Shader "Example/URPUnlitShaderBasic" { // The properties block of the Unity shader. In this example this block is empty // because the output color is predefined in the fragment shader code. Properties { _BaseColor("Base Color", Color) = (1, 1, 1, 1) _BaseMap("Base Map", 2D) = "white" } // The SubShader block containing the Shader code. SubShader { // SubShader Tags define when and under which conditions a SubShader block or // a pass is executed. Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" } Pass { // The HLSL code block. Unity SRP uses the HLSL language. HLSLPROGRAM // This line defines the name of the vertex shader. #pragma vertex vert // This line defines the name of the fragment shader. #pragma fragment frag // The Core.hlsl file contains definitions of frequently used HLSL // macros and functions, and also contains #include references to other // HLSL files (for example, Common.hlsl, SpaceTransforms.hlsl, etc.). #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" // The structure definition defines which variables it contains. // This example uses the Attributes structure as an input structure in // the vertex shader. struct Attributes { // The positionOS variable contains the vertex positions in object // space. float4 positionOS : POSITION; float2 uv : TEXCOORD0; }; struct Varyings { // The positions in this struct must have the SV_POSITION semantic. float4 positionHCS : SV_POSITION; float2 uv : TEXCOORD0; }; // This macro declares _BaseMap as a Texture2D object. TEXTURE2D(_BaseMap); // This macro declares the sampler for the _BaseMap texture. SAMPLER(sampler_BaseMap); CBUFFER_START(UnityPerMaterial) // The following line declares the _BaseMap_ST variable, so that you // can use the _BaseMap variable in the fragment shader. The _ST // suffix is necessary for the tiling and offset function to work. float4 _BaseMap_ST; CBUFFER_END CBUFFER_START(UnityPerMaterial) // The following line declares the _BaseColor variable, so that you // can use it in the fragment shader. half4 _BaseColor; CBUFFER_END // The vertex shader definition with properties defined in the Varyings // structure. The type of the vert function must match the type (struct) // that it returns. Varyings vert(Attributes IN) { // Declaring the output object (OUT) with the Varyings struct. Varyings OUT; // The TransformObjectToHClip function transforms vertex positions // from object space to homogenous clip space. OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz); OUT.uv = TRANSFORM_TEX(IN.uv, _BaseMap); // Returning the output. return OUT; } // The fragment shader definition. half4 frag(Varyings IN) : SV_Target { half4 color = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, IN.uv); return color; } ENDHLSL } } }

법선벡터

// This shader fills the mesh shape with a color predefined in the code. Shader "Example/URPUnlitShaderBasic_Normal" { // The properties block of the Unity shader. In this example this block is empty // because the output color is predefined in the fragment shader code. Properties { _BaseColor("Base Color", Color) = (1, 1, 1, 1) } // The SubShader block containing the Shader code. SubShader { // SubShader Tags define when and under which conditions a SubShader block or // a pass is executed. Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" } Pass { // The HLSL code block. Unity SRP uses the HLSL language. HLSLPROGRAM // This line defines the name of the vertex shader. #pragma vertex vert // This line defines the name of the fragment shader. #pragma fragment frag // The Core.hlsl file contains definitions of frequently used HLSL // macros and functions, and also contains #include references to other // HLSL files (for example, Common.hlsl, SpaceTransforms.hlsl, etc.). #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" // The structure definition defines which variables it contains. // This example uses the Attributes structure as an input structure in // the vertex shader. struct Attributes { // The positionOS variable contains the vertex positions in object // space. float4 positionOS : POSITION; half3 normal : NORMAL; }; struct Varyings { // The positions in this struct must have the SV_POSITION semantic. float4 positionHCS : SV_POSITION; half3 normal : TEXCOORD0; }; CBUFFER_START(UnityPerMaterial) // The following line declares the _BaseColor variable, so that you // can use it in the fragment shader. half4 _BaseColor; CBUFFER_END // The vertex shader definition with properties defined in the Varyings // structure. The type of the vert function must match the type (struct) // that it returns. Varyings vert(Attributes IN) { // Declaring the output object (OUT) with the Varyings struct. Varyings OUT; // The TransformObjectToHClip function transforms vertex positions // from object space to homogenous clip space. OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz); OUT.normal = IN.normal; // Returning the output. return OUT; } // The fragment shader definition. half4 frag(Varyings IN) : SV_Target { half4 color = 0; //color.rgb = IN.normal; color.rgb = IN.normal * 0.5 + 0.5; return color; } ENDHLSL } } }

from http://pinelike.tistory.com/348 by ccl(A) rewrite - 2021-12-23 11:00:18