Skip to content

Instantly share code, notes, and snippets.

@yorung
Created August 27, 2016 04:06
Show Gist options
  • Save yorung/9977349f04291b7c54de39dbd3795d00 to your computer and use it in GitHub Desktop.
Save yorung/9977349f04291b7c54de39dbd3795d00 to your computer and use it in GitHub Desktop.
[DX12] Define root signature in HLSL.
cbuffer perObject : register(b0)
{
row_major matrix invVP;
}
TextureCube texCube : register(t0);
SamplerState samplerState : register(s0);
struct VsToPs
{
float4 pos : SV_POSITION;
float3 dir : DIR;
};
#define RSDEF "CBV(b0), DescriptorTable(SRV(t0)), StaticSampler(s0)"
[RootSignature(RSDEF)]
VsToPs VSMain(uint id : SV_VertexID)
{
VsToPs ret;
ret.pos = float4(id & 2 ? 1 : -1, id & 1 ? -1 : 1, 1, 1);
ret.dir = normalize(mul(ret.pos, invVP)).xyz;
return ret;
}
[RootSignature(RSDEF)]
float4 PSMain(VsToPs inp) : SV_Target
{
return texCube.Sample(samplerState, inp.dir);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment