<commit_before>/* Computer Graphics and Game Technology, Assignment Ray-tracing
 *
 * Student name ....
 * Student email ...
 * Collegekaart ....
 * Date ............
 * Comments ........
 *
 *
 * (always fill in these fields before submitting!!)
 */

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "shaders.h"
#include "perlin.h"
#include "v3math.h"
#include "intersection.h"
#include "scene.h"
#include "quat.h"
#include "constants.h"

// shade_constant()
//
// Always return the same color. This shader does no real computations
// based on normal, light position, etc. As such, it merely creates
// a "silhouette" of an object.

vec3
shade_constant(intersection_point ip)
{
    return v3_create(1, 0, 0);
}

vec3
shade_matte(intersection_point ip)
{
    float lightContribution = 0;
    for(int i = 0; i < scene_num_lights; i++) {
        vec3 li = v3_normalize(v3_subtract(scene_lights[i].position, ip.p));
        
        lightContribution += scene_lights[i].intensity * fmaxf(0.0, v3_dotprod(ip.n, li));
    }
    lightContribution += scene_ambient_light;
    return v3_create(lightContribution, lightContribution, lightContribution);
}

vec3
shade_blinn_phong(intersection_point ip)
{
    return v3_create(1, 0, 0);
}

vec3
shade_reflection(intersection_point ip)
{
    return v3_create(1, 0, 0);
}

// Returns the shaded color for the given point to shade.
// Calls the relevant shading function based on the material index.
vec3
shade(intersection_point ip)<commit_msg>Adding shadows<commit_after>/* Computer Graphics and Game Technology, Assignment Ray-tracing
 *
 * Student name ....
 * Student email ...
 * Collegekaart ....
 * Date ............
 * Comments ........
 *
 *
 * (always fill in these fields before submitting!!)
 */

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "shaders.h"
#include "perlin.h"
#include "v3math.h"
#include "intersection.h"
#include "scene.h"
#include "quat.h"
#include "constants.h"

// shade_constant()
//
// Always return the same color. This shader does no real computations
// based on normal, light position, etc. As such, it merely creates
// a "silhouette" of an object.

vec3
shade_constant(intersection_point ip)
{
    return v3_create(1, 0, 0);
}

vec3
shade_matte(intersection_point ip)
{
    float lightContribution = 0;
    for(int i = 0; i < scene_num_lights; i++) {
        vec3 li = v3_normalize(v3_subtract(scene_lights[i].position, ip.p));
        
        if(!shadow_check(ip.i, li)){
            lightContribution += scene_lights[i].intensity * fmaxf(0.0, v3_dotprod(ip.n, li));
        }
    }
    lightContribution += scene_ambient_light;
    lightContribution = fminf(1.0, lightContribution);
    return v3_create(lightContribution, lightContribution, lightContribution);
}

vec3
shade_blinn_phong(intersection_point ip)
{
    return v3_create(1, 0, 0);
}

vec3
shade_reflection(intersection_point ip)
{
    return v3_create(1, 0, 0);
}

// Returns the shaded color for the given point to shade.
// Calls the relevant shading function based on the material index.
vec3
shade(intersection_point ip)
{'fraction_non_alphanumeric': 0.1323671497584541, 'fraction_numerical': 0.018035426731078906, 'mean_word_length': 3.587887740029542, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7412853', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1049, 'n_words': 287}