Skip to content

Commit

Permalink
Fixes to phong_glsl example
Browse files Browse the repository at this point in the history
  • Loading branch information
Checkmate50 committed Oct 19, 2020
1 parent b340fc3 commit 90eb5d5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ dist/
# Data
data/
.ipynb_checkpoints

# PDFs
*.pdf
15 changes: 8 additions & 7 deletions examples/phong_glsl/fragment.lgl
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ void main() {
// Example phong model with errors
else {
mat3 modelMatrix = mat3(uModel);
// vec3 worldPos = modelMatrix * vPosition;
// vec3 worldNorm = modelMatrix * vNormal;
//vec3 worldPos = modelMatrix * vPosition;
//vec3 worldNorm = modelMatrix * vNormal;

vec3 worldPos = vec3(uModel * vec4(vPosition, 1.));
vec3 worldNorm = vec3(uModel * vec4(vNormal, 0.));
//vec3 worldPos = vec3(uModel * vec4(vPosition, 1.));
//vec3 worldNorm = vec3(uModel * vec4(vNormal, 1.));
// Uncomment for failing example
// vec3 worldPos = vPosition;
// vec3 worldNorm = vNormal;
vec3 worldPos = vPosition;
vec3 worldNorm = vNormal;

vec3 lightDir = normalize(uLight - worldPos);
float lightWorldDot = dot(lightDir, worldNorm);
Expand All @@ -58,6 +58,7 @@ void main() {
vec3 reflectDir = vec3(uView*vec4(reflect(-lightDir, worldNorm), 0.));

float specular = pow(max(dot(normalize(-camPos), reflectDir), 0.), 32.);
gl_FragColor = vec4(ambient + diffuse * diffColor + specular * specColor, 1.0);
//gl_FragColor = vec4(ambient + diffuse * diffColor + specular * specColor, 1.0);
gl_FragColor = vec4(ambient + diffuse * diffColor, 1.0);
}
}
11 changes: 6 additions & 5 deletions examples/phong_glsl/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function main() {
);

const fs : any = require('fs');
// let caiman = fs.readFileSync(__dirname + './../resources/OBJ/caiman.obj', 'utf8');
let caiman = fs.readFileSync(__dirname + './../resources/OBJ/caiman.obj', 'utf8');

// Uniform and attribute locations.
let loc_uProjection = lgl.uniformLoc(gl, program, 'uProjection');
Expand All @@ -27,15 +27,16 @@ function main() {
let loc_uRef = lgl.uniformLoc(gl, program, 'uRef');

// We'll draw a teapot.
let mesh = lgl.getBunny(gl);
// let mesh = lgl.load_obj (gl, caiman);
//let mesh = lgl.getBunny(gl);
let mesh = lgl.load_obj (gl, caiman);

// Initialize the model position.
let model = mat4.create();
let ref_model = mat4.create();
mat4.rotateY(model, model, 3.14)

// Position the light source for the lighting effect.
let light = vec3.fromValues(20., -10.5, 40.);
let light = vec3.fromValues(0., 2.5, 10.);

// Set up user movement commands
let rotateFlag = true;
Expand All @@ -62,7 +63,7 @@ function main() {
mat4.rotateY(model, model, -.1);
}
}
mat4.translate(model, model, [0., -10.5, 17.]);
//mat4.translate(model, model, [0., -10.5, 17.]);

function render(view: mat4, projection: mat4) {
// Rotate the model a little bit on each frame.
Expand Down
2 changes: 1 addition & 1 deletion examples/phong_glsl/vertex.lgl
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ uniform mat4 uModel;
void main() {
vNormal = aNormal;
vPosition = aPosition;
vec4 gl_Position = uProjection * uView * uModel * vec4(aPosition, 1.);
gl_Position = uProjection * uView * uModel * vec4(aPosition, 1.);
}

0 comments on commit 90eb5d5

Please sign in to comment.