[Scummvm-git-logs] scummvm master -> 9456c322b4880704dd2a4cba3add1916fe04ace3

peterkohaut noreply at scummvm.org
Wed Dec 2 13:10:36 UTC 2026


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .

Summary:
aa483a5707 TINYGL: Interpolate the fog factor of clipped triangles
9456c322b4 TINYGL: Clamp the fog factor per pixel


Commit: aa483a5707d193bbd07224d0895fede5bd776a69
    https://github.com/scummvm/scummvm/commit/aa483a5707d193bbd07224d0895fede5bd776a69
Author: Peter Kohaut (peter.kohaut at gmail.com)
Date: 2026-12-02T14:05:20+01:00

Commit Message:
TINYGL: Interpolate the fog factor of clipped triangles

Clipping triangles creates new vertices and TinyGL correctly
interpolates their texcoords and color. It did not interpolate the fog
factor, causing incorrect fog calculation on clipped triangles.

Found while working on ROTH engine for Normality (not upstream yet)

Assisted-by: Claude:claude-opus-5-5

Changed paths:
    graphics/tinygl/clip.cpp


diff --git a/graphics/tinygl/clip.cpp b/graphics/tinygl/clip.cpp
index 8dfc7b7ecb4..c113be9d35f 100644
--- a/graphics/tinygl/clip.cpp
+++ b/graphics/tinygl/clip.cpp
@@ -255,6 +255,9 @@ static inline void updateTmp(GLContext *c, GLVertex *q, GLVertex *p0, GLVertex *
 		q->tex_coord.Y = (p0->tex_coord.Y + (p1->tex_coord.Y - p0->tex_coord.Y) * t);
 	}
 
+	if (c->fog_enabled)
+		q->fog_factor = p0->fog_factor + (p1->fog_factor - p0->fog_factor) * t;
+
 	q->clip_code = gl_clipcode(q->pc.X, q->pc.Y, q->pc.Z, q->pc.W);
 	if (q->clip_code == 0)
 		c->gl_transform_to_viewport(q);


Commit: 9456c322b4880704dd2a4cba3add1916fe04ace3
    https://github.com/scummvm/scummvm/commit/9456c322b4880704dd2a4cba3add1916fe04ace3
Author: Peter Kohaut (peter.kohaut at gmail.com)
Date: 2026-12-02T14:05:56+01:00

Commit Message:
TINYGL: Clamp the fog factor per pixel

The fog factor can go out of range along edges of thin triangles.
Make it signed and clamp it per pixel in addition to per vertex.

Found while working on ROTH engine for Normality (not upstream yet)

Assisted-by: Claude:claude-opus-5-5

Changed paths:
    graphics/tinygl/zbuffer.h
    graphics/tinygl/ztriangle.cpp


diff --git a/graphics/tinygl/zbuffer.h b/graphics/tinygl/zbuffer.h
index cdd94ef0018..ceef2eb34ab 100644
--- a/graphics/tinygl/zbuffer.h
+++ b/graphics/tinygl/zbuffer.h
@@ -363,7 +363,7 @@ private:
 	void putPixelNoTexture(int fbOffset, uint *pz, byte *ps, int _a,
 	                       int x, int y, uint &z, int &r, int &g, int &b, int &a,
 	                       int &dzdx, int &drdx, int &dgdx, int &dbdx, int dadx,
-	                       uint &fog, int fog_r, int fog_g, int fog_b, int &dfdx,
+	                       int &fog, int fog_r, int fog_g, int fog_b, int &dfdx,
 						   bool kStippleEnabled);
 
 	enum class ColorMode {
@@ -379,7 +379,7 @@ private:
 	                     int x, int y, uint &z, int &t, int &s,
 	                     int &r, int &g, int &b, int &a,
 	                     int &dzdx, int &dsdx, int &dtdx, int &drdx, int &dgdx, int &dbdx, int dadx,
-	                     uint &fog, int fog_r, int fog_g, int fog_b, int &dfdx);
+	                     int &fog, int fog_r, int fog_g, int fog_b, int &dfdx);
 
 	template <bool kDepthWrite, bool kEnableScissor, bool kStencilEnabled, bool kDepthTestEnabled>
 	void putPixelDepth(uint *pz, byte *ps, int _a, int x, int y, uint &z, int &dzdx,
@@ -435,7 +435,7 @@ private:
 	}
 
 	template <bool kEnableAlphaTest, bool kBlendingEnabled, bool kDepthWrite, bool kFogMode>
-	FORCEINLINE void writePixel(int pixel, byte aSrc, byte rSrc, byte gSrc, byte bSrc, uint z, uint fog, byte fog_r, byte fog_g, byte fog_b) {
+	FORCEINLINE void writePixel(int pixel, byte aSrc, byte rSrc, byte gSrc, byte bSrc, uint z, int fog, byte fog_r, byte fog_g, byte fog_b) {
 		if (kEnableAlphaTest) {
 			if (!checkAlphaTest(aSrc))
 				return;
@@ -446,6 +446,7 @@ private:
 		}
 
 		if (kFogMode) {
+			fog = CLIP(fog, 0, 1 << ZB_FOG_BITS);
 			int oneMinusFog = (1 << ZB_FOG_BITS) - fog;
 			int finalR = (rSrc * fog + fog_r * oneMinusFog) >> ZB_FOG_BITS;
 			int finalG = (gSrc * fog + fog_g * oneMinusFog) >> ZB_FOG_BITS;
diff --git a/graphics/tinygl/ztriangle.cpp b/graphics/tinygl/ztriangle.cpp
index eb70733dc8d..9cde5e24c45 100644
--- a/graphics/tinygl/ztriangle.cpp
+++ b/graphics/tinygl/ztriangle.cpp
@@ -54,7 +54,7 @@ template <bool kDepthWrite, bool kSmoothMode, bool kFogMode, bool kEnableAlphaTe
 void FrameBuffer::putPixelNoTexture(int fbOffset, uint *pz, byte *ps, int _a,
                                     int x, int y, uint &z, int &r, int &g, int &b, int &a,
                                     int &dzdx, int &drdx, int &dgdx, int &dbdx, int dadx,
-                                    uint &fog, int fog_r, int fog_g, int fog_b, int &dfdx,
+                                    int &fog, int fog_r, int fog_g, int fog_b, int &dfdx,
                                     bool stippleEnabled) {
 	bool useStippleColor = false;
 	if (kEnableScissor && scissorPixel(x + _a, y)) {
@@ -118,7 +118,7 @@ void FrameBuffer::putPixelTexture(int fbOffset, const TexelBuffer *texture,
                                   int x, int y, uint &z, int &t, int &s,
                                   int &r, int &g, int &b, int &a,
                                   int &dzdx, int &dsdx, int &dtdx, int &drdx, int &dgdx, int &dbdx, int dadx,
-                                  uint &fog, int fog_r, int fog_g, int fog_b, int &dfdx) {
+                                  int &fog, int fog_r, int fog_g, int fog_b, int &dfdx) {
 	if (kEnableScissor && scissorPixel(x + _a, y)) {
 		goto end;
 	}
@@ -531,8 +531,8 @@ void FrameBuffer::fillTriangle(ZBufferPoint *p0, ZBufferPoint *p1, ZBufferPoint
 				uint *pz = nullptr;
 				byte *ps = nullptr;
 				int pp;
-				uint z = 0, fog;
-				int r, g, b, a;
+				uint z = 0;
+				int r, g, b, a, fog;
 				int n = (x2 >> 16) - x1;
 				pp = pp1 + x1;
 				r = r1;
@@ -585,8 +585,8 @@ void FrameBuffer::fillTriangle(ZBufferPoint *p0, ZBufferPoint *p1, ZBufferPoint
 				uint *pz = nullptr;
 				byte *ps = nullptr;
 				int s, t;
-				uint z = 0, fog;
-				int r, g, b, a;
+				uint z = 0;
+				int r, g, b, a, fog;
 				int n, pp;
 				float sz, tz, fz, zinv;
 				int dsdx, dtdx;




More information about the Scummvm-git-logs mailing list