diff --git a/A6/README.txt b/A6/README.txt new file mode 100644 index 0000000..1bd43df --- /dev/null +++ b/A6/README.txt @@ -0,0 +1 @@ +This mesh was initially created using Cosmic Blobs software developed by Dassault Systemes SolidWorks Corp. diff --git a/A6/resources/frag.glsl b/A6/resources/frag.glsl new file mode 100644 index 0000000..ff05fa8 --- /dev/null +++ b/A6/resources/frag.glsl @@ -0,0 +1,37 @@ +#version 120 + +uniform mat4 MVL; +uniform vec3 lightPos1; +uniform vec3 lightPos2; +uniform vec3 ka; +uniform vec3 kd; +uniform vec3 ks; +uniform float s; +uniform float i1; +uniform float i2; + +varying vec3 color; // passed from the vertex shader +varying vec4 p; +varying vec4 n; + +void main() +{ + vec4 normal = normalize(n); + vec3 norm = vec3(normal.x, normal.y, normal.z); + + vec4 npos = normalize(p); + vec3 pos = vec3(npos.x, npos.y, npos.z); + + vec3 lightnorm = vec3(MVL[3].x, MVL[3].y, MVL[3].z); + + vec3 light = lightnorm - vec3(p.x, p.y, p.z); + vec3 lnorm = normalize(vec3(light.x,light.y,light.z)); + float temp = dot(lnorm, norm); + vec3 cd = kd*max(0, temp); + + vec3 h = normalize(lnorm - pos); + vec3 cs = ks*pow(max(0, dot(h, norm)), s); + + vec4 c = vec4(ka.r + cd.r + cs.r, ka.g + cd.g + cs.g, ka.b + cd.b + cs.b, 1.0); + gl_FragColor = c; +} diff --git a/A6/resources/vert.glsl b/A6/resources/vert.glsl new file mode 100644 index 0000000..ab647c8 --- /dev/null +++ b/A6/resources/vert.glsl @@ -0,0 +1,24 @@ +#version 120 + +uniform mat4 P; +uniform mat4 MV; +uniform mat4 MVL; +uniform vec3 lightPos1; +uniform vec3 lightPos2; +uniform float i1; +uniform float i2; + +attribute vec4 aPos; // in object space +attribute vec3 aNor; // in object space + +varying vec3 color; // Pass to fragment shader +varying vec4 p; +varying vec4 n; + +void main() +{ + gl_Position = P * MV * aPos; + p = MV * aPos; + n = MV * vec4(aNor, 0.0); + color = vec3(0.5, 0.5, 0.5); +} diff --git a/A6/src/main.cpp b/A6/src/main.cpp index 942504e..4f61ce9 100644 --- a/A6/src/main.cpp +++ b/A6/src/main.cpp @@ -90,7 +90,7 @@ void loadScene(const string &meshFile, const string &attachmentFile) // For drawing the grid, etc. progSimple = make_shared(); - progSimple->setShaderNames(RESOURCE_DIR + "simple_vert.glsl", RESOURCE_DIR + "simple_frag.glsl"); + progSimple->setShaderNames(RESOURCE_DIR + "vert.glsl", RESOURCE_DIR + "frag.glsl"); progSimple->setVerbose(true); // For skinned shape, CPU/GPU