Skip to content

Commit 2c422f3

Browse files
committed
implementa transparencia em textura
1 parent 18ff813 commit 2c422f3

File tree

6 files changed

+32
-8
lines changed

6 files changed

+32
-8
lines changed

docs/api.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,8 @@ The argument table format
744744
texture_id = number, the texture id
745745
rotation = number, -- rotation in degrees, optional
746746
color = {x = number, y = number, z = number }, -- color, vec3 format, optional
747-
color_weight = number, -- color weight in relation to texture, should vary between 0.0 and 1.0
747+
color_weight = number, -- color weight in relation to texture, should vary between 0.0 and 1.0, optional
748+
transparency = number, -- transparency multiplier, should vary between 0.0 and 1.0, optional
748749
}
749750
```
750751

release1.0.1/BoxEngine.exe

512 Bytes
Binary file not shown.

release1.0.1/docs/api.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,8 @@ The argument table format
744744
texture_id = number, the texture id
745745
rotation = number, -- rotation in degrees, optional
746746
color = {x = number, y = number, z = number }, -- color, vec3 format, optional
747-
color_weight = number, -- color weight in relation to texture, should vary between 0.0 and 1.0
747+
color_weight = number, -- color weight in relation to texture, should vary between 0.0 and 1.0, optional
748+
transparency = number, -- transparency multiplier, should vary between 0.0 and 1.0, optional
748749
}
749750
```
750751

src/Engine/Project/Connections/Drawing/DrawingConnection.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ namespace Connection {
453453
{
454454
glm::vec2 position, size;
455455
glm::vec3 color = { 0, 0, 0 };
456-
float rotation = 0, colorWeight = 0;
456+
float rotation = 0, colorWeight = 0, transparency = 1;
457457
unsigned int textureId;
458458

459459
if (!LuaUtils::GetTable(L, 1, "position", position))
@@ -468,11 +468,12 @@ namespace Connection {
468468
LuaUtils::GetTable(L, 1, "rotation", rotation);
469469
LuaUtils::GetTable(L, 1, "color", color);
470470
LuaUtils::GetTable(L, 1, "color_weight", colorWeight);
471+
LuaUtils::GetTable(L, 1, "transparency", transparency);
471472

472473
auto texture = TextureConnection::Get()->Get(textureId);
473474

474475
if(texture != nullptr)
475-
Drawing::TextureRenderer::Draw(texture, position, size, color, rotation, colorWeight);
476+
Drawing::TextureRenderer::Draw(texture, position, size, color, rotation, colorWeight, transparency);
476477
}
477478
else return luaL_error(L, "expecting argument 1 to be a table");
478479

src/Modules/Drawing/TextureRenderer.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@ namespace BoxEngine {
55
namespace Modules {
66
namespace Drawing {
77

8-
void TextureRenderer::Draw(const GPU::TexturePtr texture, const glm::vec2& position, const glm::vec2& size, const glm::vec3& color, const float rotation, const float colorWeight)
8+
void TextureRenderer::Draw(
9+
const GPU::TexturePtr texture,
10+
const glm::vec2& position,
11+
const glm::vec2& size,
12+
const glm::vec3& color,
13+
const float rotation,
14+
const float colorWeight,
15+
const float transparency
16+
)
917
{
1018
const Camera::Camera2DPtr cam = Camera::Camera2D::GetCurrentCamera();
1119

@@ -53,6 +61,7 @@ namespace Drawing {
5361
instance.shaderMultisampled->SetInt("image", 0);
5462
instance.shaderMultisampled->SetVec3("texColor", color);
5563
instance.shaderMultisampled->SetFloat("colorWeight", colorWeight);
64+
instance.shaderMultisampled->SetFloat("transparency", transparency);
5665
instance.shaderMultisampled->SetXY("texSize", texture->GetSize().x, texture->GetSize().y);
5766
instance.shaderMultisampled->SetInt("samples", texture->GetNumberOfSamples());
5867
}
@@ -63,6 +72,7 @@ namespace Drawing {
6372
instance.shader->SetMat4("model", model);
6473
instance.shader->SetVec3("color", color);
6574
instance.shader->SetFloat("colorWeight", colorWeight);
75+
instance.shader->SetFloat("transparency", transparency);
6676
instance.shader->SetMat4("projection", cam->GetOrthoMatrix());
6777
instance.shader->SetInt("image", 0);
6878
}
@@ -100,10 +110,11 @@ namespace Drawing {
100110
"uniform vec3 color;\n"
101111
"uniform sampler2D image;\n"
102112
"uniform float colorWeight;\n"
113+
"uniform float transparency;\n"
103114
"void main()\n"
104115
"{\n"
105116
" vec4 texFrag = texture(image, uv);\n"
106-
" outColor = vec4((texFrag.xyz * (1 - colorWeight)) + (color*colorWeight), texFrag.w);\n"
117+
" outColor = vec4((texFrag.xyz * (1 - colorWeight)) + (color*colorWeight), texFrag.w * transparency);\n"
107118
"}"
108119
};
109120

@@ -115,6 +126,7 @@ namespace Drawing {
115126
"uniform vec3 texColor;\n"
116127
"uniform sampler2DMS image;\n"
117128
"uniform float colorWeight;\n"
129+
"uniform float transparency;\n"
118130
"uniform vec2 texSize;\n"
119131
"uniform int samples;\n"
120132

@@ -126,7 +138,7 @@ namespace Drawing {
126138
" color += texelFetch(image, ivec2(uv.x*texSize.x, uv.y*texSize.y), i);\n"
127139
" }\n"
128140
" color = (color/samples);\n"
129-
" outColor = vec4((color.xyz * (1 - colorWeight)) + (texColor*colorWeight), color.w);\n"
141+
" outColor = vec4((color.xyz * (1 - colorWeight)) + (texColor*colorWeight), color.w * transparency);\n"
130142
"}"
131143
};
132144

src/Modules/Drawing/TextureRenderer.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@ namespace Drawing {
1717

1818
GPU::VertexPtr mesh;
1919
public:
20-
static void Draw(const GPU::TexturePtr texture, const glm::vec2& position, const glm::vec2& size, const glm::vec3& color, const float rotation, const float colorWeight = 0);
20+
static void Draw(
21+
const GPU::TexturePtr texture,
22+
const glm::vec2& position,
23+
const glm::vec2& size,
24+
const glm::vec3& color,
25+
const float rotation,
26+
const float colorWeight = 0,
27+
const float transparency = 1
28+
);
29+
2130
private:
2231
TextureRenderer() {};
2332

0 commit comments

Comments
 (0)