Skip to content

Instantly share code, notes, and snippets.

@Gavin-Williams
Created December 3, 2014 21:59
Show Gist options
  • Save Gavin-Williams/b453690eaa0f84c614e0 to your computer and use it in GitHub Desktop.
Save Gavin-Williams/b453690eaa0f84c614e0 to your computer and use it in GitHub Desktop.
Shader with implicit truncation of vector type warnings.
class ComputeColorTextureIndexed : ComputeColor
{
stage Texture2DArray TextureArray; // This will be available as 'ComputeColorTextureIndexed.TextureArray'
stage Texture2D VisibilityMap;
stage uint Ticks;
// stream values - available through pipeline stages
stage stream float3 Position : POSITION0;
stage stream float3 Normal : NORMAL;
stage stream float2 TexCoord : TEXCOORD0;
stage stream float TexIndex : TEXINDEX;
override float4 Compute()
{
//return float4(streams.Position.x/16,streams.Position.y/16,streams.Position.z/16,1);
uint v = VisibilityMap.Load(int3(streams.Position.xy,0));
// if the tile is not visible and has not been seen then return black
if (v == 0)
return float4(0, 0, 0, 1);
// sample geometry diffuse color
float4 diffuseColor = TextureArray.Sample(Texturing.Sampler, float3(streams.TexCoord, streams.TexIndex));
// if the tile is not visible but has been seen then use a darker diffuse shader
if (v < Ticks)
{
float4 aLighting = float4(0.1, 0.1, 0.1, 1);
return diffuseColor * aLighting;
}
// the tile is visible - return full color
return diffuseColor;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment