Skip to content

Instantly share code, notes, and snippets.

@haosizheng
Last active August 23, 2022 05:44
Show Gist options
  • Save haosizheng/0b6f628149ee8645d3219c2c8cd8694e to your computer and use it in GitHub Desktop.
Save haosizheng/0b6f628149ee8645d3219c2c8cd8694e to your computer and use it in GitHub Desktop.
UnityUrpVertexColoredShader
// this shader using vertex color as input and show on meshes' surface.
// have searched a long time but there is no one upload a vertex-colored shader for urp so I made this.
// have a good day.
Shader "Example/VertexColor" {
Properties
{
}
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;
float4 vertColor: COLOR;
};
struct Varyings {
float4 positionHCS : SV_POSITION;
float4 color: COLOR;
};
Varyings vert(Attributes IN){
Varyings OUT;
OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);
OUT.color = IN.vertColor;
return OUT;
}
half4 frag(Varyings IN) : SV_Target
{
return IN.color.rgba;
// return float4(0,0,1,0);
}
ENDHLSL
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment