ref: 91a8470be56c6cf88bb699e79ba84c86a6f8412d
parent: 33193541245de50154eff776c05ecb3d0a5f7307
author: David <gek@katherine>
date: Mon Feb 22 05:48:37 EST 2021
Fix fix
--- a/README.md
+++ b/README.md
@@ -59,9 +59,6 @@
Blending:
![model loading demo](blend.gif)
-Specular lighting:
-![model loading demo](specular.gif)
-
TinyGL 0.8 (c) 1997-2021 Fabrice Bellard, C-Chads, Gek (see License, it's free software)
--- a/SDL_Examples/gears.c
+++ b/SDL_Examples/gears.c
@@ -223,6 +223,7 @@
void initScene() {
// static GLfloat pos[4] = {0.408248290463863, 0.408248290463863, 0.816496580927726, 0.0 }; //Light at infinity.
static GLfloat pos[4] = {5, 5, 10, 0.0}; // Light at infinity.
+ //static GLfloat pos[4] = {5, 5, -10, 0.0}; // Light at infinity.
static GLfloat red[4] = {1.0, 0.0, 0.0, 0.0};
static GLfloat green[4] = {0.0, 1.0, 0.0, 0.0};
--- a/include/zbuffer.h
+++ b/include/zbuffer.h
@@ -14,6 +14,9 @@
#define ZB_POINT_Z_FRAC_BITS 14
//a "1" in bit FRAC_BITS+1 (starting at zero) = 1.
+//This is a complicated as hell fixed point math standard.
+
+//go to zfeatures.h to find out how this stuff is decided
#define ZB_POINT_S_MIN ( (1<<ZB_POINT_S_FRAC_BITS) )
#define ZB_POINT_S_MAX ( (1<<(1+TGL_FEATURE_TEXTURE_POW2+ZB_POINT_S_FRAC_BITS))-ZB_POINT_S_MIN )
#define ZB_POINT_T_MIN ( (1<<ZB_POINT_T_FRAC_BITS) )
@@ -23,26 +26,18 @@
#define ZB_S_MASK ((TGL_FEATURE_TEXTURE_DIM-1)<<(ZB_POINT_S_FRAC_BITS+1))
#define ZB_T_MASK ((TGL_FEATURE_TEXTURE_DIM-1)<<(ZB_POINT_T_FRAC_BITS+1))
//PSZSH is 5 at 32 bit, or 4 at 16 bit.
-//Basically what's happening here is this:
-//0x3FC000 is 255<<14
-///0x3FC00000 is 255<<22
-//22-14 = 8 (The number of )
-//a single factor of 2 separates 32 bit and 16 bit rendering, and this is reflected here.
-//Twice as many bytes need to be skipped in 32 bit rendering mode.
-//If you chose
#if ZB_POINT_T_FRAC_BITS == (ZB_POINT_S_FRAC_BITS + TGL_FEATURE_TEXTURE_POW2)
#define ST_TO_TEXTURE_BYTE_OFFSET(s,t) ( ((s & ZB_S_MASK) | (t & ZB_T_MASK)) >> (ZB_POINT_S_VALUE-PSZSH))
#else
#define ST_TO_TEXTURE_BYTE_OFFSET(s,t) ( ((s & ZB_S_MASK)>>(ZB_POINT_S_VALUE-PSZSH)) | ((t & ZB_T_MASK)>>(ZB_POINT_T_VALUE-PSZSH)) )
#endif
-/*
-#define ZB_POINT_RED_MIN ( (1<<10) )
-#define ZB_POINT_RED_MAX ( (1<<16)-(1<<10) )
-#define ZB_POINT_GREEN_MIN ( (1<<9) )
-#define ZB_POINT_GREEN_MAX ( (1<<16)-(1<<9) )
-#define ZB_POINT_BLUE_MIN ( (1<<10) )
-#define ZB_POINT_BLUE_MAX ( (1<<16)-(1<<10) )
-*/
+
+//This is how textures are sampled. if you want to do some sort of fancy texture filtering,
+//you do it here.
+#define TEXTURE_SAMPLE(texture, s, t) \
+ (*(PIXEL*)( (GLbyte*)texture + \
+ ST_TO_TEXTURE_BYTE_OFFSET(s,t) \
+ ))
/* display modes */
#define ZB_MODE_5R6G5B 1 /* true color 16 bits */
#define ZB_MODE_INDEX 2 /* color index 8 bits */
--- a/src/light.c
+++ b/src/light.c
@@ -336,10 +336,11 @@
s.Y = d.Y - vcoord.X;
s.Z = d.Z - vcoord.X;
} else {
+ //BLINN-PHONG SHADING: We're doing lighting calculations in Eye coordinates, this is ViewDir + LightDir
s.X = d.X; //+0.0
s.Y = d.Y; //+0.0
- s.Z = d.Z - 1.0; //BLINN-PHONG SHADING: We're doing lighting calculations in Eye coordinates, this is ViewDir + LightDir
- //s.Z = d.Z + 1.0; //This is what bellard's code did, which I think is wrong.
+ //s.Z = d.Z - 1.0;
+ s.Z = d.Z + 1.0; //Verified that this is... "supposed" to be the right thing...
//s.Z = d.Z;
}
//dot_spec is dot(surfaceNormal, H)
--- a/src/ztriangle.c
+++ b/src/ztriangle.c
@@ -350,10 +350,7 @@
#if 1 // IF 1
-#define TEXTURE_SAMPLE(texture, s, t) \
- (*(PIXEL*)( (GLbyte*)texture + \
- ST_TO_TEXTURE_BYTE_OFFSET(s,t) \
- ))
+
#define DRAW_LINE_TRI_TEXTURED() \
{ \