mirror of
				https://github.com/hannobraun/Fornjot
				synced 2025-10-31 04:08:17 +00:00 
			
		
		
		
	Draw vertices as circles
This commit is contained in:
		
							parent
							
								
									01a12b5c88
								
							
						
					
					
						commit
						0b2e3ecbcf
					
				| @ -32,7 +32,11 @@ impl Geometry { | |||||||
|             for vertex in [a, b, c, c, b, d] { |             for vertex in [a, b, c, c, b, d] { | ||||||
|                 let index = vertices.len() as u32; |                 let index = vertices.len() as u32; | ||||||
| 
 | 
 | ||||||
|                 let vertex = VerticesVertex { position: vertex }; |                 let vertex = VerticesVertex { | ||||||
|  |                     position: vertex, | ||||||
|  |                     center: p.coords.components.map(|s| s.value() as f32), | ||||||
|  |                     radius: s as f32, | ||||||
|  |                 }; | ||||||
| 
 | 
 | ||||||
|                 vertices.push(vertex); |                 vertices.push(vertex); | ||||||
|                 indices.push(index); |                 indices.push(index); | ||||||
|  | |||||||
| @ -134,10 +134,14 @@ impl Vertex for TrianglesVertex { | |||||||
| #[repr(C)] | #[repr(C)] | ||||||
| pub struct VerticesVertex { | pub struct VerticesVertex { | ||||||
|     pub position: [f32; 3], |     pub position: [f32; 3], | ||||||
|  |     pub center: [f32; 3], | ||||||
|  |     pub radius: f32, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl Vertex for VerticesVertex { | impl Vertex for VerticesVertex { | ||||||
|     const ATTRIBUTES: &[wgpu::VertexAttribute] = &wgpu::vertex_attr_array![ |     const ATTRIBUTES: &[wgpu::VertexAttribute] = &wgpu::vertex_attr_array![ | ||||||
|         0 => Float32x3, |         0 => Float32x3, | ||||||
|  |         1 => Float32x3, | ||||||
|  |         2 => Float32, | ||||||
|     ]; |     ]; | ||||||
| } | } | ||||||
|  | |||||||
| @ -8,22 +8,36 @@ var<uniform> uniforms: Uniforms; | |||||||
| 
 | 
 | ||||||
| struct VertexInput { | struct VertexInput { | ||||||
|     @location(0) position: vec3<f32>, |     @location(0) position: vec3<f32>, | ||||||
|  |     @location(1) center: vec3<f32>, | ||||||
|  |     @location(2) radius: f32, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| struct VertexOutput { | struct VertexOutput { | ||||||
|     @builtin(position) position: vec4<f32>, |     @builtin(position) position: vec4<f32>, | ||||||
|  |     @location(0) point: vec3<f32>, | ||||||
|  |     @location(1) center: vec3<f32>, | ||||||
|  |     @location(2) radius: f32, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @vertex | @vertex | ||||||
| fn vertex(in: VertexInput) -> VertexOutput { | fn vertex(in: VertexInput) -> VertexOutput { | ||||||
|     var out: VertexOutput; |     var out: VertexOutput; | ||||||
|  | 
 | ||||||
|     out.position = uniforms.transform * vec4(in.position, 1.0); |     out.position = uniforms.transform * vec4(in.position, 1.0); | ||||||
| 
 | 
 | ||||||
|  |     out.point = in.position; | ||||||
|  |     out.center = in.center; | ||||||
|  |     out.radius = in.radius; | ||||||
|  | 
 | ||||||
|     return out; |     return out; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @fragment | @fragment | ||||||
| fn fragment(in: VertexOutput) -> @location(0) vec4<f32> { | fn fragment(in: VertexOutput) -> @location(0) vec4<f32> { | ||||||
|  |     if length(in.center - in.point) > in.radius { | ||||||
|  |         discard; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     var color = vec4(0.5, 0.5, 0.5, 1.0); |     var color = vec4(0.5, 0.5, 0.5, 1.0); | ||||||
|     return color; |     return color; | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user