Add 2d drawing shader with custom alpha
This commit is contained in:
parent
ce1c188b1a
commit
f787832772
10
data/shaders/texturedquad_custom_alpha.frag
Normal file
10
data/shaders/texturedquad_custom_alpha.frag
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
uniform sampler2D tex;
|
||||||
|
uniform float custom_alpha;
|
||||||
|
|
||||||
|
in vec2 uv;
|
||||||
|
out vec4 FragColor;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
FragColor = texture(tex, uv) * custom_alpha;
|
||||||
|
}
|
@ -58,7 +58,7 @@ public:
|
|||||||
}; // UniformColoredTextureRectShader
|
}; // UniformColoredTextureRectShader
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
class TextureRectShader : public TextureShader<TextureRectShader, 1,
|
class TextureRectShader : public TextureShader<TextureRectShader, 1,
|
||||||
core::vector2df, core::vector2df,
|
core::vector2df, core::vector2df,
|
||||||
core::vector2df, core::vector2df,
|
core::vector2df, core::vector2df,
|
||||||
float>
|
float>
|
||||||
@ -74,6 +74,24 @@ public:
|
|||||||
} // TextureRectShader
|
} // TextureRectShader
|
||||||
}; // TextureRectShader
|
}; // TextureRectShader
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
class TextureRectCustomAlphaShader : public TextureShader<TextureRectCustomAlphaShader, 1,
|
||||||
|
core::vector2df, core::vector2df,
|
||||||
|
core::vector2df, core::vector2df,
|
||||||
|
float, float>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TextureRectCustomAlphaShader()
|
||||||
|
{
|
||||||
|
loadProgram(OBJECT, GL_VERTEX_SHADER, "texturedquad.vert",
|
||||||
|
GL_FRAGMENT_SHADER, "texturedquad_custom_alpha.frag");
|
||||||
|
assignUniforms("center", "size", "texcenter", "texsize", "rotation",
|
||||||
|
"custom_alpha");
|
||||||
|
|
||||||
|
assignSamplerNames(0, "tex", ST_BILINEAR_CLAMPED_FILTERED);
|
||||||
|
} // TextureRectCustomAlphaShader
|
||||||
|
}; // TextureRectCustomAlphaShader
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
class ColoredRectShader : public Shader<ColoredRectShader, core::vector2df,
|
class ColoredRectShader : public Shader<ColoredRectShader, core::vector2df,
|
||||||
core::vector2df, video::SColor>
|
core::vector2df, video::SColor>
|
||||||
@ -521,6 +539,61 @@ void draw2DImage(const video::ITexture* texture,
|
|||||||
glGetError();
|
glGetError();
|
||||||
} // draw2DImage
|
} // draw2DImage
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
void draw2DImageCustomAlpha(const irr::video::ITexture* texture,
|
||||||
|
const irr::core::rect<irr::s32>& destRect,
|
||||||
|
const irr::core::rect<irr::s32>& sourceRect,
|
||||||
|
const irr::core::rect<irr::s32>* clipRect,
|
||||||
|
float rotation, float custom_alpha)
|
||||||
|
{
|
||||||
|
if (!CVS->isGLSL())
|
||||||
|
return;
|
||||||
|
|
||||||
|
float width, height, center_pos_x, center_pos_y, tex_width, tex_height;
|
||||||
|
float tex_center_pos_x, tex_center_pos_y;
|
||||||
|
|
||||||
|
getSize(texture->getSize().Width, texture->getSize().Height,
|
||||||
|
texture->isRenderTarget(), destRect, sourceRect, width, height,
|
||||||
|
center_pos_x, center_pos_y, tex_width, tex_height,
|
||||||
|
tex_center_pos_x, tex_center_pos_y);
|
||||||
|
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
if (clipRect)
|
||||||
|
{
|
||||||
|
if (!clipRect->isValid())
|
||||||
|
return;
|
||||||
|
|
||||||
|
glEnable(GL_SCISSOR_TEST);
|
||||||
|
const core::dimension2d<u32>& render_target_size =
|
||||||
|
irr_driver->getActualScreenSize();
|
||||||
|
glScissor(clipRect->UpperLeftCorner.X,
|
||||||
|
(s32)render_target_size.Height - clipRect->LowerRightCorner.Y +
|
||||||
|
irr_driver->getDevice()->getMovedHeight(),
|
||||||
|
clipRect->getWidth(), clipRect->getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
TextureRectCustomAlphaShader::getInstance()->use();
|
||||||
|
glBindVertexArray(SharedGPUObjects::getUI_VAO());
|
||||||
|
|
||||||
|
TextureRectCustomAlphaShader::getInstance()->setTextureUnits(texture->getOpenGLTextureName());
|
||||||
|
TextureRectCustomAlphaShader::getInstance()->setUniforms(
|
||||||
|
core::vector2df(center_pos_x, center_pos_y),
|
||||||
|
core::vector2df(width, height),
|
||||||
|
core::vector2df(tex_center_pos_x, tex_center_pos_y),
|
||||||
|
core::vector2df(tex_width, tex_height), rotation, custom_alpha);
|
||||||
|
|
||||||
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||||
|
glBindVertexArray(0);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
|
||||||
|
if (clipRect)
|
||||||
|
glDisable(GL_SCISSOR_TEST);
|
||||||
|
glUseProgram(0);
|
||||||
|
|
||||||
|
glGetError();
|
||||||
|
} // draw2DImage
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
void draw2DImage(const video::ITexture* texture,
|
void draw2DImage(const video::ITexture* texture,
|
||||||
const core::rect<float>& destRect,
|
const core::rect<float>& destRect,
|
||||||
|
@ -59,6 +59,12 @@ void draw2DImage(const irr::video::ITexture* texture,
|
|||||||
bool useAlphaChannelOfTexture, bool draw_translucently = false,
|
bool useAlphaChannelOfTexture, bool draw_translucently = false,
|
||||||
float rotation = 0.0f);
|
float rotation = 0.0f);
|
||||||
|
|
||||||
|
void draw2DImageCustomAlpha(const irr::video::ITexture* texture,
|
||||||
|
const irr::core::rect<irr::s32>& destRect,
|
||||||
|
const irr::core::rect<irr::s32>& sourceRect,
|
||||||
|
const irr::core::rect<irr::s32>* clipRect,
|
||||||
|
float rotation, float custom_alpha);
|
||||||
|
|
||||||
void draw2DImage(const irr::video::ITexture* texture,
|
void draw2DImage(const irr::video::ITexture* texture,
|
||||||
const irr::core::rect<float>& destRect,
|
const irr::core::rect<float>& destRect,
|
||||||
const irr::core::rect<irr::s32>& sourceRect,
|
const irr::core::rect<irr::s32>& sourceRect,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user