vertex shader์—์„œ pos : position์„ ์ธํ’‹์œผ๋กœ ๋ฐ›์€ ํ›„ pos.xyz๊ฐ€ ์•ก์„ธ์Šค๊ฐ€ ์•ˆ๋˜๋Š”๋ฐ ๊ตฌ์ฒด์ ์œผ๋กœ๋Š” y ๊ด€๋ จ ๋ญ”๊ฐ€ ์•ˆ๋˜๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. float4๋ผ๋Š” ๊ฒƒ๋งŒ ์•Œ๊ณ  ๋” ๋””ํ…Œ์ผํ•œ ๋ฉ”์„œ๋“œ ๊ด€๋ จ ์ •๋ณด๋Š” ๋ชป์ฐพ๊ฒ ๋Š”๋ฐ ์•Œ๋ ค์ฃผ์‹ฌ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค

์ˆ˜์ • -- ์ฝ”๋“œ ์ถ”๊ฐ€


Shader "Unlit/test" {

Properties {

_MainTex ("Albedo (RGB)", 2D) = "white" {}

}

SubShader {

Tags {

"RenderType" = "Opaque"

"RenderPipeLine" = "UniversalPipeline"

}

Pass {

Tags {

"LightMode" = "UniversalForward"

}

HLSLPROGRAM

#pragma vertex vert

#pragma fragment frag

#pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap novertexlight

#pragma target 4.5

// #include "UnityCG.cginc"

// #include "UnityLightingCommon.cginc"

// #include "AutoLight.cginc"

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

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

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

sampler2D _MainTex;

#if SHADER_TARGET >= 45

StructuredBuffer<float4> positionBuffer;

#endif

struct appdata

{

float vertex : POSITION;

float4 tangent : TANGENT;

float3 normal : NORMAL;

float4 texcoord : TEXCOORD0;

float4 texcoord1 : TEXCOORD1;

float4 color : COLOR;

};

struct v2f

{

float4 pos : SV_POSITION;

float2 uv_MainTex : TEXCOORD0;

float3 ambient : TEXCOORD1;

float3 diffuse : TEXCOORD2;

float3 color : TEXCOORD3;

// SHADOW_COORDS(4)

};

void rotate2D(inout float2 v, float r)

{

float s, c;

sincos(r, s, c);

v = float2(v.x * c - v.y * s, v.x * s + v.y * c);

}

v2f vert (appdata v, uint instanceID : SV_InstanceID)

{

#if SHADER_TARGET >= 45

float4 data = positionBuffer[instanceID];

#else

float4 data = 0;

#endif

// float rotation = data.w * data.w * _Time.x * 0.5f;

// rotate2D(data.xz, rotation);

float3 localPosition = v.vertex * data.w;

float3 worldPosition = data.xyz + localPosition;

float3 worldNormal = v.normal;

float3 ndotl = saturate(dot(worldNormal, half3(_MainLightPosition.xyz)));

float3 ambient = SampleSHVertex(worldNormal);

Light light = GetMainLight();

float3 diffuse = (ndotl * light.color.rgb);

float3 color = v.color.xyz;

v2f o;

// o.pos = mul(UNITY_MATRIX_VP, worldPosition);

o.pos = TransformToHClip(v.vertex.xyz);

o.uv_MainTex = v.texcoord;

o.ambient = ambient;

o.diffuse = diffuse;

o.color = color;

// TRANSFER_SHADOW(o)

return o;

}

half4 frag (v2f i) : SV_Target

{

// fixed shadow = SHADOW_ATTENUATION(i);

float4 albedo = tex2D(_MainTex, i.uv_MainTex);

// float3 lighting = i.diffuse * shadow + i.ambient;

float3 lighting = i.diffuse + i.ambient;

float4 output = float4(albedo.rgb * i.color * lighting, albedo.w);

// UNITY_APPLY_FOG(i.fogCoord, output);

// return output;

float4 customColor = float4(0.5, 0, 0, 1);

return customColor;

}

ENDHLSL

}

}

}