<commit_before>#include <iostream>
#include "material.h"
#include "ray.h"
#include "light.h"
#include "../ui/TraceUI.h"
extern TraceUI* traceUI;

#include "../fileio/bitmap.h"
#include "../fileio/pngimage.h"

using namespace std;
extern bool debugMode;

Material::~Material()
{
}

// Apply the phong model to this point on the surface of the object, returning
// the color of that point.
glm::dvec3 Material::shade(Scene *scene, const ray& r, const isect& i) const
{
	glm::dvec3 point = r.getPosition() + r.getDirection()*i.t;
	glm::dvec3 totalI = kd(i) + ka(i)*scene->ambient();

	for ( vector<Light*>::const_iterator it = scene->beginLights();
		  it != scene->endLights();
 		++it )
	{
		// Iteration two: Diffuse reflection
		Light* light = *it;
		glm::dvec3 lightDir = light->getDirection(point);

		glm::dvec3 Il = light->getColor();
		double lightCos = max(0.0, glm::dot(i.N, lightDir));

		if(debugMode)
			std::cout << "Light cos: " << lightCos << std::endl;

		totalI += kd(i)*Il*lightCos;

		glm::dvec3 ref = 2.0*glm::dot(i.N, lightDir)*i.N - lightDir;
		glm::dvec3 v = scene->getCamera().getEye() - point;
		totalI += ks(i)*Il*max(0.0, /*pow(*/glm::dot(ref, v)/*, shininess(i))*/);

		//if(debugMode)<commit_msg>Fixed bugs in Phong shader model<commit_after>#include <iostream>
#include "material.h"
#include "ray.h"
#include "light.h"
#include "../ui/TraceUI.h"
extern TraceUI* traceUI;

#include "../fileio/bitmap.h"
#include "../fileio/pngimage.h"

using namespace std;
extern bool debugMode;

Material::~Material()
{
}

// Apply the phong model to this point on the surface of the object, returning
// the color of that point.
glm::dvec3 Material::shade(Scene *scene, const ray& r, const isect& i) const
{
	glm::dvec3 point = r.getPosition() + r.getDirection()*i.t;
	glm::dvec3 totalI = ke(i) + ka(i)*scene->ambient();

	for ( vector<Light*>::const_iterator it = scene->beginLights();
		  it != scene->endLights();
 		++it )
	{
		// Iteration two: Diffuse reflection
		Light* light = *it;
		glm::dvec3 lightDir = light->getDirection(point);
		double nDotL = glm::dot(i.N, lightDir);

		// Special case when light is being hit from behind.
		if(nDotL < 0) continue;

		glm::dvec3 Il = light->getColor();
		double lightCos = max(0.0, nDotL);

		if(debugMode)
			std::cout << "Light cos: " << lightCos << std::endl;

		totalI += kd(i)*Il*lightCos;

		glm::dvec3 ref = glm::normalize(2.0*glm::dot(i.N, lightDir)*i.N - lightDir);
		glm::dvec3 v = glm::normalize(scene->getCamera().getEye() - point);
		totalI += ks(i)*Il*max(0.0, pow(glm::dot(ref, v), shininess(i)));

		//if(debugMode)
{'fraction_non_alphanumeric': 0.18752406623026568, 'fraction_numerical': 0.010396611474778591, 'mean_word_length': 4.2591093117408905, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 19, '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': '4855881', 'n_tokens_mistral': 1053, 'n_tokens_neox': 991, 'n_words': 237}