RenderVS.hlsl 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // RUN: %dxc -E main -T vs_6_0 %s | FileCheck %s
  2. // CHECK: bufferLoad
  3. // CHECK: storeOutput
  4. //--------------------------------------------------------------------------------------
  5. // File: Render.hlsl
  6. //
  7. // The shaders for rendering tessellated mesh and base mesh
  8. //
  9. // Copyright (c) Microsoft Corporation. All rights reserved.
  10. //--------------------------------------------------------------------------------------
  11. cbuffer cbPerObject : register( b0 )
  12. {
  13. row_major matrix g_mWorldViewProjection : packoffset( c0 );
  14. }
  15. // The tessellated vertex structure
  16. struct TessedVertex
  17. {
  18. uint BaseTriID; // Which triangle of the base mesh this tessellated vertex belongs to?
  19. float2 bc; // Barycentric coordinates with regard to the base triangle
  20. };
  21. Buffer<float4> g_base_vb_buffer : register(t0); // Base mesh vertex buffer
  22. StructuredBuffer<TessedVertex> g_TessedVertices : register(t1); // Tessellated mesh vertex buffer
  23. float4 bary_centric(float4 v1, float4 v2, float4 v3, float2 bc)
  24. {
  25. return (1 - bc.x - bc.y) * v1 + bc.x * v2 + bc.y * v3;
  26. }
  27. float4 main( uint vertid : SV_VertexID ) : SV_POSITION
  28. {
  29. TessedVertex input = g_TessedVertices[vertid];
  30. // Get the positions of the three vertices of the base triangle
  31. float4 v[3];
  32. [unroll]
  33. for (int i = 0; i < 3; ++ i)
  34. {
  35. uint vert_id = input.BaseTriID * 3 + i;
  36. v[i] = g_base_vb_buffer[vert_id];
  37. }
  38. // Calculate the position of this tessellated vertex from barycentric coordinates and then project it
  39. return mul(bary_centric(v[0], v[1], v[2], input.bc), g_mWorldViewProjection);
  40. }