plane_shader.wgsl 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Vertex shader
  2. struct CameraUniform {
  3. view_proj: mat4x4<f32>
  4. }
  5. @group(0) @binding(0)
  6. var<uniform> camera: CameraUniform;
  7. struct VertexInput {
  8. @location(0) position: vec3<f32>,
  9. @location(1) color: vec3<f32>,
  10. @location(2) uv: vec2<f32>,
  11. };
  12. struct VertexOutput {
  13. @builtin(position) clip_position: vec4<f32>,
  14. @location(0) color: vec3<f32>,
  15. };
  16. @group(1) @binding(0)
  17. var t_diffuse: texture_2d<f32>;
  18. @group(1) @binding(1)
  19. var s_diffuse: sampler;
  20. @group(2) @binding(0)
  21. var h_diffuse: texture_2d<f32>;
  22. @group(2) @binding(1)
  23. var hs_diffuse: sampler;
  24. @vertex
  25. fn vs_main(
  26. model: VertexInput,
  27. ) -> VertexOutput {
  28. //let normalized_uv_coordinates = model.uv * vec2<f32>(textureDimensions(t_diffuse));
  29. let normalized_uv_coordinates = model.uv * vec2<f32>(textureDimensions(h_diffuse));
  30. //let height_added = textureLoad(t_diffuse,vec2<u32>(normalized_uv_coordinates),0);
  31. let height_added = textureLoad(h_diffuse,vec2<u32>(normalized_uv_coordinates),0);
  32. let grayscale_height_added = height_added.x;
  33. var out: VertexOutput;
  34. out.color = model.color;
  35. out.clip_position = camera.view_proj * vec4<f32>(model.position.x,model.position.y, model.position.z + ( grayscale_height_added), 1.0);
  36. return out;
  37. }
  38. // Fragment shader
  39. @fragment
  40. fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
  41. return vec4<f32>(0.0,0.0,1.0, 1.0);
  42. }