색상을 바꾸는 것은 간단합니다.
#pragma fragment frag 에서 정의한 frag()함의 값을 반환함으로써 색상을 바꿀 수 있습니다.
더보기
Shader "StudySRP/Catlike1"
{
Properties{}
SubShader{
Pass {
HLSLPROGRAM
#include "Catlike1Pass.hlsl"
#include "UnityInput.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#define UNITY_MATRIX_M unity_ObjectToWorld
#define UNITY_MATRIX_I_M unity_WorldToObject
#define UNITY_MATRIX_V unity_MatrixV
#define UNITY_MATRIX_VP unity_MatrixVP
#define UNITY_MATRIX_P glstate_matrix_projection
#ifndef CUSTOM_UNITY_INPUT_INCLUDED
#define CUSTOM_UNITY_INPUT_INCLUDED
float4x4 unity_ObjectToWorld;
float4x4 unity_WorldToObject;
real4 unity_WorldTransformParams;
float4x4 unity_MatrixVP;
float4x4 unity_MatrixV;
float4x4 glstate_matrix_projection;
#endif
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl"
#pragma vertex vert
#pragma fragment frag
#ifndef CUSTOM_UNLIT_PASS_INCLUDED
#define CUSTOM_UNLIT_PASS_INCLUDED
#endif
float4 vert(float3 positionOS : POSITION) : SV_POSITION {
float3 positionWS = TransformObjectToWorld(positionOS.xyz);
return TransformWorldToHClip(positionWS);
}
float4 frag() : SV_TARGET{
return float4(0.5, 0.7, 0.5, 0);
}
ENDHLSL
}
}
}
변수로 색상제어하기 |
Properties에 추가하고 사용한다고 선언한 뒤 사용하면 됩니다.
Properties {
_BaseColor("Color", Color) = (1.0, 1.0, 1.0, 1.0)
}
float4 _BaseColor;
더보기
Shader "StudySRP/Catlike1"
{
Properties{
_BaseColor("Color", Color) = (1.0, 1.0, 1.0, 1.0)
}
SubShader{
Pass {
HLSLPROGRAM
#include "Catlike1Pass.hlsl"
#include "UnityInput.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#define UNITY_MATRIX_M unity_ObjectToWorld
#define UNITY_MATRIX_I_M unity_WorldToObject
#define UNITY_MATRIX_V unity_MatrixV
#define UNITY_MATRIX_VP unity_MatrixVP
#define UNITY_MATRIX_P glstate_matrix_projection
#ifndef CUSTOM_UNITY_INPUT_INCLUDED
#define CUSTOM_UNITY_INPUT_INCLUDED
float4x4 unity_ObjectToWorld;
float4x4 unity_WorldToObject;
real4 unity_WorldTransformParams;
float4x4 unity_MatrixVP;
float4x4 unity_MatrixV;
float4x4 glstate_matrix_projection;
#endif
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl"
#pragma vertex vert
#pragma fragment frag
#ifndef CUSTOM_UNLIT_PASS_INCLUDED
#define CUSTOM_UNLIT_PASS_INCLUDED
#endif
float4 _BaseColor;
float4 vert(float3 positionOS : POSITION) : SV_POSITION {
float3 positionWS = TransformObjectToWorld(positionOS.xyz);
return TransformWorldToHClip(positionWS);
}
float4 frag() : SV_TARGET{
return _BaseColor;
}
ENDHLSL
}
}
}
반응형