TextVS.hlsl 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // RUN: %dxc -E main -T vs_6_0 %s | FileCheck %s
  2. // CHECK: SV_VertexID
  3. //
  4. // Copyright (c) Microsoft. All rights reserved.
  5. // This code is licensed under the MIT License (MIT).
  6. // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
  7. // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
  8. // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
  9. // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
  10. //
  11. // Developed by Minigraph
  12. //
  13. // Author: James Stanard
  14. //
  15. #include "TextRS.hlsli"
  16. cbuffer cbFontParams : register( b0 )
  17. {
  18. float2 Scale; // Scale and offset for transforming coordinates
  19. float2 Offset;
  20. float2 InvTexDim; // Normalizes texture coordinates
  21. float TextSize; // Height of text in destination pixels
  22. float TextScale; // TextSize / FontHeight
  23. float DstBorder; // Extra space around a glyph measured in screen space coordinates
  24. uint SrcBorder; // Extra spacing around glyphs to avoid sampling neighboring glyphs
  25. }
  26. struct VS_INPUT
  27. {
  28. float2 ScreenPos : POSITION; // Upper-left position in screen pixel coordinates
  29. uint4 Glyph : TEXCOORD; // X, Y, Width, Height in texel space
  30. };
  31. struct VS_OUTPUT
  32. {
  33. float4 Pos : SV_POSITION; // Upper-left and lower-right coordinates in clip space
  34. float2 Tex : TEXCOORD0; // Upper-left and lower-right normalized UVs
  35. };
  36. [RootSignature(Text_RootSig)]
  37. VS_OUTPUT main( VS_INPUT input, uint VertID : SV_VertexID )
  38. {
  39. const float2 xy0 = input.ScreenPos - DstBorder;
  40. const float2 xy1 = input.ScreenPos + DstBorder + float2(TextScale * input.Glyph.z, TextSize);
  41. const uint2 uv0 = input.Glyph.xy - SrcBorder;
  42. const uint2 uv1 = input.Glyph.xy + SrcBorder + input.Glyph.zw;
  43. float2 uv = float2( VertID & 1, (VertID >> 1) & 1 );
  44. VS_OUTPUT output;
  45. output.Pos = float4( lerp(xy0, xy1, uv) * Scale + Offset, 0, 1 );
  46. output.Tex = lerp(uv0, uv1, uv) * InvTexDim;
  47. return output;
  48. }