Skip to content

Instantly share code, notes, and snippets.

@TimothyFitz
Last active December 22, 2017 21:20
Show Gist options
  • Save TimothyFitz/3a14723fb138c4664b38125f247db0fe to your computer and use it in GitHub Desktop.
Save TimothyFitz/3a14723fb138c4664b38125f247db0fe to your computer and use it in GitHub Desktop.
Hack to get up to 15 dynamicly changing colors in a single PicaVoxel model
VertexOutput vert (VertexInput v) {
VertexOutput o = (VertexOutput)0;
o.uv1 = v.texcoord1;
o.uv2 = v.texcoord2;
float4 color = v.vertexColor;
uint index = ceil(color.a * 15);
if (index < 15) {
color = _ColorReplace[index];
}
o.vertexColor = color; // v.vertexColor;
#ifdef LIGHTMAP_ON
o.ambientOrLightmapUV.xy = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
o.ambientOrLightmapUV.zw = 0;
#elif UNITY_SHOULD_SAMPLE_SH
#endif
#ifdef DYNAMICLIGHTMAP_ON
o.ambientOrLightmapUV.zw = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
#endif
o.normalDir = UnityObjectToWorldNormal(v.normal);
o.tangentDir = normalize( mul( unity_ObjectToWorld, float4( v.tangent.xyz, 0.0 ) ).xyz );
o.bitangentDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w);
o.posWorld = mul(unity_ObjectToWorld, v.vertex);
float3 lightColor = _LightColor0.rgb;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex );
UNITY_TRANSFER_FOG(o,o.pos);
TRANSFER_VERTEX_TO_FRAGMENT(o)
return o;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment