Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Effects.cpp for consistent behavior when rendering special patterns #1216

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*.sln.docstates
.idea/
.vscode/
.vs

# Build results

Expand Down
26 changes: 26 additions & 0 deletions src/client/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,32 @@ void Creature::drawInformation(const Point& point, bool useGray, const Rect& par
}
}

// Get the player outfit texture
TexturePtr Creature::getOutfitTexture()
{
int exactSize;
if (m_outfit.getCategory() == ThingCategoryCreature)
exactSize = getExactSize();
else
exactSize = g_things.rawGetThingType(m_outfit.getAuxId(), m_outfit.getCategory())->getExactSize();

int frameSize;
frameSize = std::max<int>(exactSize * 0.75f, 2 * Otc::TILE_PIXELS * 0.75f); // Define the frame size

if (g_graphics.canUseFBO()) {
// Create a temporary frame buffer
const FrameBufferPtr& outfitBuffer = g_framebuffers.getTemporaryFrameBuffer();
outfitBuffer->resize(Size(frameSize, frameSize)); // Set the frame buffer size to frameSize (square)
outfitBuffer->bind(); // Draw operations are binded to this framebuffer from now
g_painter->setAlphaWriting(true);
g_painter->clear(Color::alpha);
internalDrawOutfit(Point(frameSize - Otc::TILE_PIXELS, frameSize - Otc::TILE_PIXELS) + getDisplacement(), 1, false, true, getDirection()); // Call the internal outfit draw
outfitBuffer->release(); // Release the frame buffer, it's not receiving next draw calls
return outfitBuffer->getTexture(); // Return the resulting texture
}
return nullptr;
}

void Creature::turn(Otc::Direction direction)
{
// if is not walking change the direction right away
Expand Down
1 change: 1 addition & 0 deletions src/client/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Creature : public Thing
void internalDrawOutfit(Point dest, float scaleFactor, bool animateWalk, bool animateIdle, Otc::Direction direction, LightView *lightView = nullptr);
void drawOutfit(const Rect& destRect, bool resize);
void drawInformation(const Point& point, bool useGray, const Rect& parentRect, int drawFlags);
TexturePtr getOutfitTexture(); // Method for receiving the player outfit texture

void setId(uint32 id) { m_id = id; }
void setName(const std::string& name);
Expand Down
10 changes: 4 additions & 6 deletions src/client/effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,11 @@ void Effect::drawEffect(const Point& dest, float scaleFactor, bool animate, int
}
}

int xPattern = offsetX % getNumPatternX();
if(xPattern < 0)
xPattern += getNumPatternX();
int xPattern = unsigned(offsetX) % getNumPatternX();
xPattern = 1 - xPattern - getNumPatternX();
if (xPattern < 0) xPattern += getNumPatternX();

int yPattern = offsetY % getNumPatternY();
if(yPattern < 0)
yPattern += getNumPatternY();
int yPattern = unsigned(offsetY) % getNumPatternY();

rawGetThingType()->draw(dest, scaleFactor, 0, xPattern, yPattern, 0, animationPhase, lightView);
}
Expand Down
2 changes: 2 additions & 0 deletions src/client/mapview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <framework/core/eventdispatcher.h>
#include <framework/core/application.h>
#include <framework/core/resourcemanager.h>
#include "game.h"


enum {
Expand Down Expand Up @@ -186,6 +187,7 @@ void MapView::draw(const Rect& rect)
m_shader->setUniformValue(ShaderManager::MAP_CENTER_COORD, center.x / (float)framebufferRect.width(), 1.0f - center.y / (float)framebufferRect.height());
m_shader->setUniformValue(ShaderManager::MAP_GLOBAL_COORD, globalCoord.x / (float)framebufferRect.height(), globalCoord.y / (float)framebufferRect.height());
m_shader->setUniformValue(ShaderManager::MAP_ZOOM, scaleFactor);
m_shader->setUniformValue(ShaderManager::PLAYER_DIRECTION, g_game.getLocalPlayer()->getDirection()); // Set the player direction uniform
g_painter->setShaderProgram(m_shader);
}

Expand Down
1 change: 1 addition & 0 deletions src/client/shadermanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ void ShaderManager::setupMapShader(const PainterShaderProgramPtr& shader)
shader->bindUniformLocation(MAP_CENTER_COORD, "u_MapCenterCoord");
shader->bindUniformLocation(MAP_GLOBAL_COORD, "u_MapGlobalCoord");
shader->bindUniformLocation(MAP_ZOOM, "u_MapZoom");
shader->bindUniformLocation(PLAYER_DIRECTION, "u_PlayerLookDirection"); // Binding player look direction uniform to the shader manager
}

PainterShaderProgramPtr ShaderManager::getShader(const std::string& name)
Expand Down
3 changes: 2 additions & 1 deletion src/client/shadermanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class ShaderManager
ITEM_ID_UNIFORM = 10,
MAP_CENTER_COORD = 10,
MAP_GLOBAL_COORD = 11,
MAP_ZOOM = 12
MAP_ZOOM = 12,
PLAYER_DIRECTION = 13, // Added player direction to the list of default shader uniforms
};

void init();
Expand Down
25 changes: 25 additions & 0 deletions src/framework/graphics/paintershaderprogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "graphics.h"
#include <framework/core/clock.h>
#include <framework/platform/platformwindow.h>
#include <client/game.h>

PainterShaderProgram::PainterShaderProgram()
{
Expand Down Expand Up @@ -163,6 +164,30 @@ void PainterShaderProgram::addMultiTexture(const std::string& file)
m_multiTextures.push_back(texture);
}

// Add player outfit texture to the shader uniforms
void PainterShaderProgram::addPlayerOutfitMultiTexture()
{
if (m_multiTextures.size() > 3)
g_logger.error("cannot add more multi textures to shader, the max is 3");

TexturePtr texture = g_game.getLocalPlayer()->getOutfitTexture(); // Get player outfit texture
if (!texture)
return;

texture->setSmooth(false);
texture->setRepeat(false);

if (m_playerOutfitIndex == INT_MAX)
{
m_playerOutfitIndex = m_multiTextures.size();
m_multiTextures.push_back(texture);
return;
}
else {
m_multiTextures.at(m_playerOutfitIndex) = texture;
}
}

void PainterShaderProgram::bindMultiTextures()
{
if(m_multiTextures.empty())
Expand Down
4 changes: 3 additions & 1 deletion src/framework/graphics/paintershaderprogram.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class PainterShaderProgram : public ShaderProgram
void updateTime();

void addMultiTexture(const std::string& file);
void addPlayerOutfitMultiTexture();
void bindMultiTextures();

private:
Expand All @@ -76,7 +77,8 @@ class PainterShaderProgram : public ShaderProgram
Matrix3 m_textureMatrix;
Size m_resolution;
float m_time;
std::vector<TexturePtr> m_multiTextures;
int m_playerOutfitIndex = INT_MAX;
std::vector<TexturePtr> m_multiTextures; // Control variables (a shader should have only one player outfit uniform, yet, it needs to be updated very often)
};

#endif
1 change: 1 addition & 0 deletions src/framework/luafunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ void Application::registerLuaFunctions()
g_lua.registerClass<ShaderProgram>();
g_lua.registerClass<PainterShaderProgram>();
g_lua.bindClassMemberFunction<PainterShaderProgram>("addMultiTexture", &PainterShaderProgram::addMultiTexture);
g_lua.bindClassMemberFunction<PainterShaderProgram>("addPlayerOutfitMultiTexture", &PainterShaderProgram::addPlayerOutfitMultiTexture); // Expose addPlayerOutfitMultiTexture to lua api

// ParticleEffect
g_lua.registerClass<ParticleEffectType>();
Expand Down
4 changes: 2 additions & 2 deletions vc14/otclient.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
# Visual Studio Version 17
VisualStudioVersion = 17.9.34723.18
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "otclient", "otclient.vcxproj", "{17A8F78F-1FFB-4128-A3B3-59CC6C19D89A}"
EndProject
Expand Down
10 changes: 5 additions & 5 deletions vc14/otclient.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down Expand Up @@ -472,4 +472,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
2 changes: 1 addition & 1 deletion vc14/settings.props
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<OTCLIENT_LIBDEPS_D>
glew32d.lib;
zlibd.lib;
zstdd.lib;
zstd.lib;
physfs.lib;
openal32.lib;
lua51.lib;
Expand Down