Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Homework submission #5

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
252 changes: 138 additions & 114 deletions README.md

Large diffs are not rendered by default.

Binary file added renders/ScreenShotProjectRunning.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added renders/pathtracerRefractionReflection787.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
476 changes: 247 additions & 229 deletions scenes/sampleScene.txt

Large diffs are not rendered by default.

73 changes: 65 additions & 8 deletions src/interactions.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ __host__ __device__ glm::vec3 calculateRandomDirectionInHemisphere(glm::vec3 nor

//TODO (OPTIONAL): IMPLEMENT THIS FUNCTION
__host__ __device__ glm::vec3 calculateTransmission(glm::vec3 absorptionCoefficient, float distance) {
return glm::vec3(0,0,0);

glm::vec3 transmitted;

return transmitted;

}

//TODO (OPTIONAL): IMPLEMENT THIS FUNCTION
Expand All @@ -40,22 +44,61 @@ __host__ __device__ bool calculateScatterAndAbsorption(ray& r, float& depth, Ab

//TODO (OPTIONAL): IMPLEMENT THIS FUNCTION
__host__ __device__ glm::vec3 calculateTransmissionDirection(glm::vec3 normal, glm::vec3 incident, float incidentIOR, float transmittedIOR) {
return glm::vec3(0,0,0);
/* float cosAngle = glm::dot( normal, incident);
float n = incidentIOR / transmittedIOR;
float secondTerm = 1.0f - n * n * (1.0f - cosAngle * cosAngle);

if (secondTerm >= 0.0f)
{
return (n * incident) - (n * cosAngle + sqrtf( secondTerm )) * normal;
}

return glm::vec3(0);*/

float cosAngle = glm::dot(normal, incident);

float n = incidentIOR / transmittedIOR;

float secondTerm = 1 - pow(n, 2) * (1 - pow(cosAngle, 2));
if (secondTerm < 0)
return glm::vec3(0);
float cosAngle2 = sqrt(secondTerm);

if (cosAngle > 0) {
return glm::normalize(normal*(n*cosAngle - cosAngle2) + incident*n);
} else {
return glm::normalize(normal*(-n*cosAngle + cosAngle2) + incident*n);
}



}

//TODO (OPTIONAL): IMPLEMENT THIS FUNCTION
__host__ __device__ glm::vec3 calculateReflectionDirection(glm::vec3 normal, glm::vec3 incident) {
//nothing fancy here
return glm::vec3(0,0,0);
return incident - 2.0f * glm::dot(normal, incident) * normal ;
}

//TODO (OPTIONAL): IMPLEMENT THIS FUNCTION
__host__ __device__ Fresnel calculateFresnel(glm::vec3 normal, glm::vec3 incident, float incidentIOR, float transmittedIOR, glm::vec3 reflectionDirection, glm::vec3 transmissionDirection) {
Fresnel fresnel;
Fresnel fresnel;

if (incidentIOR <= 0 && transmittedIOR <= 0 ) {
fresnel.reflectionCoefficient = 1;
fresnel.transmissionCoefficient = 0;
return fresnel;
}else{
float cosThetaI = glm::dot(normal, incident);
float sinIncidence = sqrt(1-pow(cosThetaI,2));
float cosThetaT = sqrt(1-pow(((incidentIOR/transmittedIOR)*sinIncidence),2));
float RsP = pow( (incidentIOR * cosThetaI - transmittedIOR * cosThetaT) / (incidentIOR * cosThetaI + transmittedIOR * cosThetaT) , 2);
float RpP = pow( (incidentIOR * cosThetaT - transmittedIOR * cosThetaI) / (incidentIOR * cosThetaT + transmittedIOR * cosThetaI) , 2);
fresnel.reflectionCoefficient = (RsP + RpP) / 2.0;
fresnel.transmissionCoefficient = 1 - fresnel.reflectionCoefficient;
return fresnel;
}

fresnel.reflectionCoefficient = 1;
fresnel.transmissionCoefficient = 0;
return fresnel;
}

//LOOK: This function demonstrates cosine weighted random direction generation in a sphere!
Expand Down Expand Up @@ -90,7 +133,21 @@ __host__ __device__ glm::vec3 calculateRandomDirectionInHemisphere(glm::vec3 nor
//Now that you know how cosine weighted direction generation works, try implementing non-cosine (uniform) weighted random direction generation.
//This should be much easier than if you had to implement calculateRandomDirectionInHemisphere.
__host__ __device__ glm::vec3 getRandomDirectionInSphere(float xi1, float xi2) {
return glm::vec3(0,0,0);



float theta = TWO_PI * xi1;
float phi = acos(2*xi2 -1);

float x = cos(theta) * sin(phi);
float y = sin(theta) * sin(phi);
float z = cos(phi);

return glm::vec3(x,y,z);




}

//TODO (PARTIALLY OPTIONAL): IMPLEMENT THIS FUNCTION
Expand Down
Loading