cube.metal 633 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include <metal_stdlib>
  2. using namespace metal;
  3. struct VSOutput
  4. {
  5. float4 color [[user(locn0)]];
  6. float4 position [[position]];
  7. };
  8. #ifdef VERTEX
  9. struct UBO
  10. {
  11. float4x4 modelViewProj;
  12. };
  13. struct VSInput
  14. {
  15. float3 position [[attribute(0)]];
  16. float3 color [[attribute(1)]];
  17. };
  18. vertex VSOutput vs_main(VSInput input [[stage_in]], constant UBO& ubo [[buffer(0)]])
  19. {
  20. VSOutput output;
  21. output.color = float4(input.color, 1.0);
  22. output.position = ubo.modelViewProj * float4(input.position, 1.0);
  23. return output;
  24. }
  25. #else
  26. fragment float4 fs_main(VSOutput input [[stage_in]])
  27. {
  28. return input.color;
  29. }
  30. #endif