diff options
| -rw-r--r-- | include/swgfx.h | 2 | ||||
| -rw-r--r-- | src/swgfx.c | 7 |
2 files changed, 3 insertions, 6 deletions
diff --git a/include/swgfx.h b/include/swgfx.h index d527f02..f849ba5 100644 --- a/include/swgfx.h +++ b/include/swgfx.h | |||
| @@ -31,7 +31,7 @@ typedef float R; | |||
| 31 | typedef struct sgVec2i { int x, y; } sgVec2i; | 31 | typedef struct sgVec2i { int x, y; } sgVec2i; |
| 32 | typedef struct sgVec2 { R x, y; } sgVec2; | 32 | typedef struct sgVec2 { R x, y; } sgVec2; |
| 33 | typedef struct sgVec3 { union { struct { R r, g, b; }; struct { R x, y, z; }; }; } sgVec3; | 33 | typedef struct sgVec3 { union { struct { R r, g, b; }; struct { R x, y, z; }; }; } sgVec3; |
| 34 | typedef struct sgVec4 { union { struct { R r, g, b, a; }; struct { R x, y, z, w; }; }; } sgVec4; | 34 | typedef struct sgVec4 { union { struct { R r, g, b, a; }; struct { R x, y, z, w; }; struct { sgVec3 rgb; R _; }; }; } sgVec4; |
| 35 | 35 | ||
| 36 | typedef sgVec3 sgNormal; | 36 | typedef sgVec3 sgNormal; |
| 37 | 37 | ||
diff --git a/src/swgfx.c b/src/swgfx.c index 33b453d..1901057 100644 --- a/src/swgfx.c +++ b/src/swgfx.c | |||
| @@ -1011,7 +1011,7 @@ void sgAmbient(swgfx* gfx, sgColour3 ambient) { | |||
| 1011 | if (depth != DepthClearValue) { | 1011 | if (depth != DepthClearValue) { |
| 1012 | const sgColour3* albedo = &gfx->albedo[i]; | 1012 | const sgColour3* albedo = &gfx->albedo[i]; |
| 1013 | sgColour4* colour = &gfx->colour[i]; | 1013 | sgColour4* colour = &gfx->colour[i]; |
| 1014 | *colour = Vec4FromVec3(mul3(*albedo, ambient), 1.f); | 1014 | colour->rgb = add3(colour->rgb, mul3(*albedo, ambient)); |
| 1015 | } | 1015 | } |
| 1016 | } | 1016 | } |
| 1017 | } | 1017 | } |
| @@ -1027,10 +1027,7 @@ void sgDirectional(swgfx* gfx, sgColour3 lightColour, sgVec3 direction) { | |||
| 1027 | const sgVec3* normal = &gfx->normals[i]; | 1027 | const sgVec3* normal = &gfx->normals[i]; |
| 1028 | const R NdotL = fmaxf(0.f, dot3(*normal, L)); | 1028 | const R NdotL = fmaxf(0.f, dot3(*normal, L)); |
| 1029 | sgColour4* colour = &gfx->colour[i]; | 1029 | sgColour4* colour = &gfx->colour[i]; |
| 1030 | // TODO: Here and in sgAmbient() we need to accumulate colour, so this | 1030 | colour->rgb = add3(colour->rgb, scale3(mul3(*albedo, lightColour), NdotL)); |
| 1031 | // should be +=. But colour also needs to be sgVec4, not sgPixel. We | ||
| 1032 | // should transform sgVec4 to sgPixel colour on sgPresent() instead. | ||
| 1033 | *colour = Vec4FromVec3(scale3(mul3(*albedo, lightColour), NdotL), 1.f); | ||
| 1034 | } | 1031 | } |
| 1035 | } | 1032 | } |
| 1036 | } | 1033 | } |
