add metal fuzziness
This commit is contained in:
		
							parent
							
								
									c842fcf713
								
							
						
					
					
						commit
						a596058a0d
					
				
					 2 changed files with 8 additions and 6 deletions
				
			
		| 
						 | 
					@ -93,22 +93,24 @@ pub fn main() anyerror!void {
 | 
				
			||||||
    // World
 | 
					    // World
 | 
				
			||||||
    const materialGround = Material{
 | 
					    const materialGround = Material{
 | 
				
			||||||
        .lambertian = material.Lambertian{
 | 
					        .lambertian = material.Lambertian{
 | 
				
			||||||
            .color = Color{ .x = 0.8, .y = 0.8, .z = 0.0 }
 | 
					            .color = Color{ .x = 0.8, .y = 0.8, .z = 0.0 },
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    const materialCenter = Material{
 | 
					    const materialCenter = Material{
 | 
				
			||||||
        .lambertian = material.Lambertian{
 | 
					        .lambertian = material.Lambertian{
 | 
				
			||||||
            .color = Color{ .x = 0.7, .y = 0.3, .z = 0.3 }
 | 
					            .color = Color{ .x = 0.7, .y = 0.3, .z = 0.3 },
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    const materialLeft = Material{
 | 
					    const materialLeft = Material{
 | 
				
			||||||
        .metal = material.Metal{
 | 
					        .metal = material.Metal{
 | 
				
			||||||
            .color = Color{ .x = 0.8, .y = 0.8, .z = 0.8 }
 | 
					            .color = Color{ .x = 0.8, .y = 0.8, .z = 0.8 },
 | 
				
			||||||
 | 
					            .fuzz = 0.3,
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    const materialRight = Material{
 | 
					    const materialRight = Material{
 | 
				
			||||||
        .metal = material.Metal{
 | 
					        .metal = material.Metal{
 | 
				
			||||||
            .color = Color{ .x = 0.8, .y = 0.6, .z = 0.2 }
 | 
					            .color = Color{ .x = 0.8, .y = 0.6, .z = 0.2 },
 | 
				
			||||||
 | 
					            .fuzz = 1.0,
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -29,11 +29,11 @@ pub const Lambertian = struct {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub const Metal = struct {
 | 
					pub const Metal = struct {
 | 
				
			||||||
    color: Color,
 | 
					    color: Color,
 | 
				
			||||||
    // fuzzy: f32,
 | 
					    fuzz: f32,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn scatter(self: Metal, ray: Ray, hit: HitRecord, rng: *Random) ?ScatteredRay {
 | 
					    pub fn scatter(self: Metal, ray: Ray, hit: HitRecord, rng: *Random) ?ScatteredRay {
 | 
				
			||||||
        const reflected = ray.direction.unit().reflect(hit.normal);
 | 
					        const reflected = ray.direction.unit().reflect(hit.normal);
 | 
				
			||||||
        const scattered = Ray{ .origin = hit.p, .direction = reflected };
 | 
					        const scattered = Ray{ .origin = hit.p, .direction = reflected.add(vec3.random_in_unit_sphere(rng).mul_s(self.fuzz)) };
 | 
				
			||||||
        if (scattered.direction.dot(hit.normal) <= 0) {
 | 
					        if (scattered.direction.dot(hit.normal) <= 0) {
 | 
				
			||||||
            return null;
 | 
					            return null;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue