mesh.kong 979 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #[set(everything)]
  2. const constants: {
  3. WVP: float4x4;
  4. };
  5. #[set(everything)]
  6. const sampler_linear: sampler;
  7. #[set(everything)]
  8. const my_texture: tex2d;
  9. struct vert_in {
  10. pos: float4;
  11. nor: float2;
  12. tex: float2;
  13. }
  14. struct vert_out {
  15. pos: float4;
  16. nor: float3;
  17. tex: float2;
  18. }
  19. fun mesh_vert(input: vert_in): vert_out {
  20. var output: vert_out;
  21. output.nor = float3(input.nor.xy, input.pos.w);
  22. output.tex = input.tex;
  23. output.pos = constants.WVP * float4(input.pos.xyz, 1.0);
  24. return output;
  25. }
  26. fun mesh_frag(input: vert_out): float4 {
  27. var l: float3 = float3(0.5, 0.0, 0.5);
  28. var base_color: float3 = float3(1.0, 1.0, 1.0); // sample(my_texture, sampler_linear, input.tex).rgb;
  29. var ambient: float3 = base_color * 0.5;
  30. var n: float3 = normalize(input.nor);
  31. var dotnl: float = max(dot(n, l), 0.0);
  32. var diffuse: float3 = dotnl * base_color;
  33. return float4(ambient + diffuse, 1.0);
  34. }
  35. #[pipe]
  36. struct pipe {
  37. vertex = mesh_vert;
  38. fragment = mesh_frag;
  39. }