Skip to content

Instantly share code, notes, and snippets.

@aras-p
Created August 6, 2013 19:23
Show Gist options
  • Save aras-p/6167714 to your computer and use it in GitHub Desktop.
Save aras-p/6167714 to your computer and use it in GitHub Desktop.
ARB_texture_swizzle "emulation" for D3D
uniform float4 weightsR; // default 1,0,0,0
uniform float4 weightsG; // default 0,1,0,0
uniform float4 weightsB; // default 0,0,1,0
uniform float4 weightsA; // default 0,0,0,1
float4 swizzledTex2D (sampler2D smp, float2 uv)
{
float4 smp = tex2D (mysampler, myuv);
float4 res;
res.r = dot(smp,weightsR);
res.g = dot(smp,weightsG);
res.b = dot(smp,weightsB);
res.a = dot(smp,weightsA);
return res;
}
// for example to splat just R channel of a texture into all four channels, set up
// weightsR..A to all be (1,0,0,0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment