Skip to content

Commit

Permalink
Improved facing ratio shader
Browse files Browse the repository at this point in the history
  • Loading branch information
ozy committed May 17, 2019
1 parent 23a320b commit a42e855
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,8 @@ void facingRatioShader (int px, int py, V3f rayDir, Job* job){
uint8_t (*framebuf)[job->frameh][job->framew][3] = (uint8_t (*)[job->frameh][job->framew][3])job->frameBuf;
Hit hit;
if (rayIntersectsObject(camRay, *job->obj, &hit)){
V3f col = V3fCrossProd(hit.hitNormal, V3fMul(rayDir, (V3f){-1,-1,-1}));
col = V3fMul ((V3f){255,255,255}, col);
float shade = V3fLen(col);
// Use col x,y,z for r,g,b respectively to render colorfully
// or the vector length for all to shade grayscale
float shade = V3fDotProd(hit.hitNormal, V3fMul(rayDir, (V3f){-1,-1,-1})) * 255.0 ;
shade = fmax(0.0,shade);
(*framebuf)[py][px][0] = shade;
(*framebuf)[py][px][1] = shade;
(*framebuf)[py][px][2] = shade;
Expand Down

0 comments on commit a42e855

Please sign in to comment.