Lambert shading!
This commit is contained in:
		
							parent
							
								
									1e39776145
								
							
						
					
					
						commit
						e76bf0f444
					
				
					 1 changed files with 16 additions and 6 deletions
				
			
		
							
								
								
									
										22
									
								
								src/scene.cc
									
										
									
									
									
								
							
							
						
						
									
										22
									
								
								src/scene.cc
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -94,10 +94,6 @@ void
 | 
			
		|||
Scene::render()
 | 
			
		||||
{
 | 
			
		||||
    pixels = new Color[width * height];
 | 
			
		||||
    if (pixels == NULL) {
 | 
			
		||||
        // TODO: Print an error.
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Ray primary_ray;
 | 
			
		||||
    Vector3 o, d;
 | 
			
		||||
| 
						 | 
				
			
			@ -173,6 +169,20 @@ Scene::trace_ray(const Ray &ray, const int depth)
 | 
			
		|||
        return Color::Black;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // TODO: Lighting.
 | 
			
		||||
    return intersected_shape->get_material().get_color();
 | 
			
		||||
    Color out_color = intersected_shape->get_material().get_color();
 | 
			
		||||
 | 
			
		||||
    Vector3 intersection = ray.parameterize(nearest_t);
 | 
			
		||||
    Vector3 normal = intersected_shape->compute_normal(intersection);
 | 
			
		||||
 | 
			
		||||
    for (Light *l : lights) {
 | 
			
		||||
        Vector3 light_direction = intersection - l->get_origin();
 | 
			
		||||
        light_direction.normalize();
 | 
			
		||||
 | 
			
		||||
        float ldotn = light_direction.dot(normal);
 | 
			
		||||
        out_color.red *= ((ldotn >= 0.0) ? ldotn : 0.0) * l->get_intensity();
 | 
			
		||||
        out_color.green *= ((ldotn >= 0.0) ? ldotn : 0.0) * l->get_intensity();
 | 
			
		||||
        out_color.blue *= ((ldotn >= 0.0) ? ldotn : 0.0) * l->get_intensity();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return out_color;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue