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
}
}
}
https://gall.dcinside.com/mgallery/board/view/?id=game_dev&no=134560&page=1
Draw๋ renderํจ์๋ก ์ง์ ๊ทธ๋ฆฌ์๋์? - dc App
drawmeshinstancedindirect์ผ์ด์. ์ง๊ธ์ ํด๊ฒฐ ๋์์ต๋๋ค