[Scummvm-git-logs] scummvm master -> b2207a548ea365ca994ad4277e443f010d1c7350

aquadran noreply at scummvm.org
Tue May 20 19:33:26 UTC 2025


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

Summary:
b2207a548e WINTERMUTE: Implemented simple shadow for shader renderer


Commit: b2207a548ea365ca994ad4277e443f010d1c7350
    https://github.com/scummvm/scummvm/commit/b2207a548ea365ca994ad4277e443f010d1c7350
Author: Paweł Kołodziejski (aquadran at gmail.com)
Date: 2025-05-20T21:33:22+02:00

Commit Message:
WINTERMUTE: Implemented simple shadow for shader renderer

Changed paths:
  A engines/wintermute/base/gfx/opengl/shaders/wme_simple_shadow.fragment
  A engines/wintermute/base/gfx/opengl/shaders/wme_simple_shadow.vertex
    dists/scummvm.rc
    engines/wintermute/base/gfx/opengl/base_render_opengl3d.h
    engines/wintermute/base/gfx/opengl/base_render_opengl3d_shader.cpp
    engines/wintermute/base/gfx/opengl/base_render_opengl3d_shader.h


diff --git a/dists/scummvm.rc b/dists/scummvm.rc
index 5074f03d701..c6e2e25cd2a 100644
--- a/dists/scummvm.rc
+++ b/dists/scummvm.rc
@@ -116,6 +116,8 @@ shaders/wme_shadow_mask.fragment        FILE    "engines/wintermute/base/gfx/ope
 shaders/wme_shadow_mask.vertex          FILE    "engines/wintermute/base/gfx/opengl/shaders/wme_shadow_mask.vertex"
 shaders/wme_shadow_volume.fragment      FILE    "engines/wintermute/base/gfx/opengl/shaders/wme_shadow_volume.fragment"
 shaders/wme_shadow_volume.vertex        FILE    "engines/wintermute/base/gfx/opengl/shaders/wme_shadow_volume.vertex"
+shaders/wme_simple_shadow.fragment      FILE    "engines/wintermute/base/gfx/opengl/shaders/wme_simple_shadow.fragment"
+shaders/wme_simple_shadow.vertex        FILE    "engines/wintermute/base/gfx/opengl/shaders/wme_simple_shadow.vertex"
 shaders/wme_sprite.fragment             FILE    "engines/wintermute/base/gfx/opengl/shaders/wme_sprite.fragment"
 shaders/wme_sprite.vertex               FILE    "engines/wintermute/base/gfx/opengl/shaders/wme_sprite.vertex"
 #endif
diff --git a/engines/wintermute/base/gfx/opengl/base_render_opengl3d.h b/engines/wintermute/base/gfx/opengl/base_render_opengl3d.h
index 7e3e7e504a1..7100c8dfead 100644
--- a/engines/wintermute/base/gfx/opengl/base_render_opengl3d.h
+++ b/engines/wintermute/base/gfx/opengl/base_render_opengl3d.h
@@ -62,14 +62,14 @@ class BaseRenderOpenGL3D : public BaseRenderer3D {
 	};
 
 	struct SimpleShadowVertex {
-		float u;
-		float v;
 		float nx;
 		float ny;
 		float nz;
 		float x;
 		float y;
 		float z;
+		float u;
+		float v;
 	};
 
 public:
@@ -163,7 +163,7 @@ public:
 private:
 	void displaySimpleShadow(BaseObject *object) override;
 
-	SimpleShadowVertex _simpleShadow[4]{};
+	SimpleShadowVertex _simpleShadow[4];
 	Common::Array<DXVector4> _lightPositions;
 	Common::Array<DXVector3> _lightDirections;
 	GLuint _filterTexture;
diff --git a/engines/wintermute/base/gfx/opengl/base_render_opengl3d_shader.cpp b/engines/wintermute/base/gfx/opengl/base_render_opengl3d_shader.cpp
index b33bd142c3f..49d80448b15 100644
--- a/engines/wintermute/base/gfx/opengl/base_render_opengl3d_shader.cpp
+++ b/engines/wintermute/base/gfx/opengl/base_render_opengl3d_shader.cpp
@@ -47,24 +47,61 @@ BaseRenderer3D *makeOpenGL3DShaderRenderer(BaseGame *inGame) {
 
 BaseRenderOpenGL3DShader::BaseRenderOpenGL3DShader(BaseGame *inGame) : BaseRenderer3D(inGame) {
 	setDefaultAmbientLightColor();
-	_spriteVBO = 0;
 	_alphaRef = 0;
 }
 
 BaseRenderOpenGL3DShader::~BaseRenderOpenGL3DShader() {
 	_camera = nullptr; // ref only
 	glDeleteBuffers(1, &_spriteVBO);
+	glDeleteBuffers(1, &_fadeVBO);
+	glDeleteBuffers(1, &_lineVBO);
+	glDeleteBuffers(1, &_simpleShadowVBO);
 }
 
 bool BaseRenderOpenGL3DShader::initRenderer(int width, int height, bool windowed) {
+	_simpleShadow[0].x = -1.0f;
+	_simpleShadow[0].y = 0.0f;
+	_simpleShadow[0].z = 1.0f;
+	_simpleShadow[0].nx = 0.0f;
+	_simpleShadow[0].ny = 1.0f;
+	_simpleShadow[0].nz = 0.0f;
+	_simpleShadow[0].u = 0.0f;
+	_simpleShadow[0].v = 1.0f;
+
+	_simpleShadow[1].x = -1.0f;
+	_simpleShadow[1].y = 0.0f;
+	_simpleShadow[1].z = -1.0f;
+	_simpleShadow[1].nx = 0.0f;
+	_simpleShadow[1].ny = 1.0f;
+	_simpleShadow[1].nz = 0.0f;
+	_simpleShadow[1].u = 1.0f;
+	_simpleShadow[1].v = 1.0f;
+
+	_simpleShadow[2].x = 1.0f;
+	_simpleShadow[2].y = 0.0f;
+	_simpleShadow[2].z = 1.0f;
+	_simpleShadow[2].nx = 0.0f;
+	_simpleShadow[2].ny = 1.0f;
+	_simpleShadow[2].nz = 0.0f;
+	_simpleShadow[2].u = 0.0f;
+	_simpleShadow[2].v = 0.0f;
+
+	_simpleShadow[3].x = 1.0f;
+	_simpleShadow[3].y = 0.0f;
+	_simpleShadow[3].z = -1.0f;
+	_simpleShadow[3].nx = 0.0f;
+	_simpleShadow[3].ny = 1.0f;
+	_simpleShadow[3].nz = 0.0f;
+	_simpleShadow[3].u = 1.0f;
+	_simpleShadow[3].v = 0.0f;
+
 	glGenBuffers(1, &_spriteVBO);
 	glBindBuffer(GL_ARRAY_BUFFER, _spriteVBO);
 	glBufferData(GL_ARRAY_BUFFER, 4 * sizeof(SpriteVertex), nullptr, GL_DYNAMIC_DRAW);
 	glBindBuffer(GL_ARRAY_BUFFER, 0);
 
-	static const char *spriteAttributes[] = {"position", "texcoord", "color", nullptr};
+	static const char *spriteAttributes[] = { "position", "texcoord", "color", nullptr };
 	_spriteShader = OpenGL::Shader::fromFiles("wme_sprite", spriteAttributes);
-
 	_spriteShader->enableVertexAttribute("position", _spriteVBO, 3, GL_FLOAT, false, sizeof(SpriteVertex), 0);
 	_spriteShader->enableVertexAttribute("texcoord", _spriteVBO, 2, GL_FLOAT, false, sizeof(SpriteVertex), 12);
 	_spriteShader->enableVertexAttribute("color", _spriteVBO, 4, GL_FLOAT, false, sizeof(SpriteVertex), 20);
@@ -72,6 +109,17 @@ bool BaseRenderOpenGL3DShader::initRenderer(int width, int height, bool windowed
 	static const char *geometryAttributes[] = { "position", "color", nullptr };
 	_geometryShader = OpenGL::Shader::fromFiles("wme_geometry", geometryAttributes);
 
+	glGenBuffers(1, &_simpleShadowVBO);
+	glBindBuffer(GL_ARRAY_BUFFER, _simpleShadowVBO);
+	glBufferData(GL_ARRAY_BUFFER, 4 * sizeof(SimpleShadowVertex), _simpleShadow, GL_STATIC_DRAW);
+	glBindBuffer(GL_ARRAY_BUFFER, 0);
+
+	static const char *simpleShadowAttributes[] = { "position", "normal", "texcoord", nullptr };
+	_simpleShadowShader = OpenGL::Shader::fromFiles("wme_simple_shadow", simpleShadowAttributes);
+	_simpleShadowShader->enableVertexAttribute("position", _simpleShadowVBO, 3, GL_FLOAT, false, sizeof(SimpleShadowVertex), 0);
+	_simpleShadowShader->enableVertexAttribute("normal", _simpleShadowVBO, 3, GL_FLOAT, false, sizeof(SimpleShadowVertex), 12);
+	_simpleShadowShader->enableVertexAttribute("texcoord", _simpleShadowVBO, 2, GL_FLOAT, false, sizeof(SimpleShadowVertex), 24);
+
 	static const char *shadowVolumeAttributes[] = { "position", nullptr };
 	_shadowVolumeShader = OpenGL::Shader::fromFiles("wme_shadow_volume", shadowVolumeAttributes);
 
@@ -82,7 +130,7 @@ bool BaseRenderOpenGL3DShader::initRenderer(int width, int height, bool windowed
 	DXMatrixIdentity(&m);
 	_transformStack.push_back(m);
 
-	static const char *XModelAttributes[] = {"position", "texcoord", "normal", nullptr};
+	static const char *XModelAttributes[] = { "position", "texcoord", "normal", nullptr };
 	_xmodelShader = OpenGL::Shader::fromFiles("wme_modelx", XModelAttributes);
 
 	setDefaultAmbientLightColor();
@@ -249,6 +297,12 @@ bool BaseRenderOpenGL3DShader::setup3D(Camera3D *camera, bool force) {
 	_geometryShader->setUniform("viewMatrix", viewMatrix);
 	_geometryShader->setUniform("projMatrix", projectionMatrix);
 
+	_simpleShadowShader->use();
+	_simpleShadowShader->setUniform("viewMatrix", viewMatrix);
+	_simpleShadowShader->setUniform("projMatrix", projectionMatrix);
+	_simpleShadowShader->setUniform1f("alphaRef", _alphaRef);
+	_simpleShadowShader->setUniform("alphaTest", true);
+
 	_shadowVolumeShader->use();
 	_shadowVolumeShader->setUniform("viewMatrix", viewMatrix);
 	_shadowVolumeShader->setUniform("projMatrix", projectionMatrix);
@@ -653,7 +707,39 @@ void BaseRenderOpenGL3DShader::displaySimpleShadow(BaseObject *object) {
 	if (!_ready || !object)
 		return;
 
-	// TODO: to be implemented
+	BaseSurface *shadowImage;
+	if (object->_shadowImage) {
+		shadowImage = object->_shadowImage;
+	} else {
+		shadowImage = _gameRef->_shadowImage;
+	}
+
+	if (!shadowImage) {
+		return;
+	}
+
+	DXMatrix scale, trans, rot, finalm;
+	DXMatrixScaling(&scale, object->_shadowSize * object->_scale3D, 1.0f, object->_shadowSize * object->_scale3D);
+	DXMatrixRotationY(&rot, degToRad(object->_angle));
+	DXMatrixTranslation(&trans, object->_posVector._x, object->_posVector._y, object->_posVector._z);
+	DXMatrixMultiply(&finalm, &scale, &rot);
+	DXMatrixMultiply(&finalm, &finalm, &trans);
+	setWorldTransform(finalm);
+
+	glFrontFace(GL_CCW);
+
+	glDepthMask(GL_FALSE);
+	glEnable(GL_TEXTURE_2D);
+	static_cast<BaseSurfaceOpenGL3D *>(shadowImage)->setTexture();
+
+	_simpleShadowShader->use();
+
+	glBindBuffer(GL_ARRAY_BUFFER, _simpleShadowVBO);
+
+	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+
+	glDisable(GL_TEXTURE_2D);
+	glDepthMask(GL_TRUE);
 }
 
 void BaseRenderOpenGL3DShader::setSpriteBlendMode(Graphics::TSpriteBlendMode blendMode, bool forceChange) {
@@ -874,6 +960,10 @@ bool BaseRenderOpenGL3DShader::setWorldTransform(const DXMatrix &transform) {
 	_xmodelShader->setUniform("modelMatrix", modelMatrix);
 	_xmodelShader->setUniform("normalMatrix", normalMatrix);
 
+	_simpleShadowShader->use();
+	_simpleShadowShader->setUniform("modelMatrix", modelMatrix);
+	_simpleShadowShader->setUniform("normalMatrix", normalMatrix);
+
 	_shadowVolumeShader->use();
 	_shadowVolumeShader->setUniform("modelMatrix", modelMatrix);
 
diff --git a/engines/wintermute/base/gfx/opengl/base_render_opengl3d_shader.h b/engines/wintermute/base/gfx/opengl/base_render_opengl3d_shader.h
index 2a2185e8e29..34fc68a3042 100644
--- a/engines/wintermute/base/gfx/opengl/base_render_opengl3d_shader.h
+++ b/engines/wintermute/base/gfx/opengl/base_render_opengl3d_shader.h
@@ -63,14 +63,14 @@ class BaseRenderOpenGL3DShader : public BaseRenderer3D {
 	};
 
 	struct SimpleShadowVertex {
-		float u;
-		float v;
-		float nx;
-		float ny;
-		float nz;
 		float x;
 		float y;
 		float z;
+		float nx;
+		float ny;
+		float nz;
+		float u;
+		float v;
 	};
 
 
@@ -166,6 +166,8 @@ public:
 private:
 	void displaySimpleShadow(BaseObject *object) override;
 
+	SimpleShadowVertex _simpleShadow[4];
+
 	DXMatrix _glProjectionMatrix;
 	float _alphaRef;
 
@@ -173,13 +175,15 @@ private:
 
 	Math::Vector4d _flatShadowColor;
 
-	GLuint _spriteVBO;
-	GLuint _fadeVBO;
-	GLuint _lineVBO;
+	GLuint _spriteVBO{};
+	GLuint _fadeVBO{};
+	GLuint _lineVBO{};
+	GLuint _simpleShadowVBO{};
 	OpenGL::Shader *_spriteShader{};
 	OpenGL::Shader *_fadeShader{};
 	OpenGL::Shader *_xmodelShader{};
 	OpenGL::Shader *_geometryShader{};
+	OpenGL::Shader *_simpleShadowShader{};
 	OpenGL::Shader *_shadowVolumeShader{};
 	OpenGL::Shader *_lineShader{};
 };
diff --git a/engines/wintermute/base/gfx/opengl/shaders/wme_simple_shadow.fragment b/engines/wintermute/base/gfx/opengl/shaders/wme_simple_shadow.fragment
new file mode 100644
index 00000000000..36f46ecc64c
--- /dev/null
+++ b/engines/wintermute/base/gfx/opengl/shaders/wme_simple_shadow.fragment
@@ -0,0 +1,15 @@
+in vec2 Texcoord;
+
+uniform sampler2D tex;
+uniform float alphaRef;
+uniform UBOOL alphaTest;
+
+OUTPUT
+
+void main() {
+	outColor = texture(tex, Texcoord);
+
+	if (UBOOL_TEST(alphaTest) && outColor.a < alphaRef) {
+		discard;
+	}
+}
diff --git a/engines/wintermute/base/gfx/opengl/shaders/wme_simple_shadow.vertex b/engines/wintermute/base/gfx/opengl/shaders/wme_simple_shadow.vertex
new file mode 100644
index 00000000000..12582fd9a1e
--- /dev/null
+++ b/engines/wintermute/base/gfx/opengl/shaders/wme_simple_shadow.vertex
@@ -0,0 +1,15 @@
+in vec3 position;
+in vec3 normal;
+in vec2 texcoord;
+
+out vec2 Texcoord;
+
+uniform highp mat4 modelMatrix;
+uniform highp mat4 normalMatrix;
+uniform highp mat4 viewMatrix;
+uniform highp mat4 projMatrix;
+
+void main() {
+	gl_Position = projMatrix * viewMatrix * modelMatrix * vec4(position, 1.0);
+	Texcoord = texcoord;
+}




More information about the Scummvm-git-logs mailing list