mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-02 20:43:32 +00:00
Add submerge and color modulation shader attributes.
This commit is contained in:
parent
623484b2be
commit
3a79fbbbd0
@ -1,14 +1,17 @@
|
||||
#version 120
|
||||
|
||||
varying vec4 color_mod;
|
||||
varying vec4 color_draw;
|
||||
varying vec2 pos;
|
||||
varying float submerge_amount;
|
||||
uniform sampler2D tex;
|
||||
|
||||
void main()
|
||||
{
|
||||
float rmod = color_mod.r > 0.5 ? color_mod.r - 1 : color_mod.r;
|
||||
/* float rmod = color_mod.r > 0.5 ? color_mod.r - 1 : color_mod.r;
|
||||
float gmod = color_mod.g > 0.5 ? color_mod.g - 1 : color_mod.g;
|
||||
float bmod = color_mod.b > 0.5 ? color_mod.b - 1 : color_mod.b;
|
||||
float amod = color_mod.a > 0.5 ? color_mod.a - 1 : color_mod.a;
|
||||
gl_FragColor = texture2D(tex, pos) + vec4(rmod, gmod, bmod, amod);
|
||||
gl_FragColor = texture2D(tex, pos) + vec4(rmod, gmod, bmod, amod);*/
|
||||
gl_FragColor = texture2D(tex, pos) + color_mod + color_draw;
|
||||
}
|
||||
|
@ -1,17 +1,24 @@
|
||||
#version 120
|
||||
|
||||
attribute vec4 color;
|
||||
// Required by SDL_gpu
|
||||
attribute vec4 draw_color;
|
||||
attribute vec3 vertex;
|
||||
attribute vec2 texture_pos;
|
||||
attribute vec4 color;
|
||||
attribute float submerge;
|
||||
|
||||
uniform mat4 model_view_proj;
|
||||
|
||||
varying vec4 color_mod;
|
||||
varying vec2 pos;
|
||||
varying float submerge_amount;
|
||||
varying vec4 color_draw;
|
||||
|
||||
void main()
|
||||
{
|
||||
pos = texture_pos;
|
||||
color_mod = color;
|
||||
color_draw = draw_color;
|
||||
submerge_amount = submerge;
|
||||
gl_Position = model_view_proj * vec4(vertex, 1.0);
|
||||
}
|
||||
|
@ -23,6 +23,8 @@ shader_program::shader_program(const std::string &vsrc, const std::string &fsrc)
|
||||
, vertex_object_(0)
|
||||
, fragment_object_(0)
|
||||
, block_()
|
||||
, attr_color_mod_(0)
|
||||
, attr_submerge_(0)
|
||||
, refcount_(new unsigned(1))
|
||||
{
|
||||
vertex_object_ = GPU_LoadShader(GPU_VERTEX_SHADER, vsrc.c_str());
|
||||
@ -39,12 +41,18 @@ shader_program::shader_program(const std::string &vsrc, const std::string &fsrc)
|
||||
if (!program_object_) {
|
||||
//TODO: report error
|
||||
}
|
||||
|
||||
attr_color_mod_ = GPU_GetAttributeLocation(program_object_, "color");
|
||||
set_color_mod(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
shader_program::shader_program()
|
||||
: program_object_(0)
|
||||
, vertex_object_(0)
|
||||
, fragment_object_(0)
|
||||
, block_()
|
||||
, attr_color_mod_(0)
|
||||
, attr_submerge_(0)
|
||||
, refcount_(new unsigned(1))
|
||||
{}
|
||||
|
||||
@ -63,6 +71,9 @@ shader_program::shader_program(const shader_program &prog)
|
||||
: program_object_(prog.program_object_)
|
||||
, vertex_object_(prog.vertex_object_)
|
||||
, fragment_object_(prog.fragment_object_)
|
||||
, block_(prog.block_)
|
||||
, attr_color_mod_(prog.attr_color_mod_)
|
||||
, attr_submerge_(prog.attr_submerge_)
|
||||
, refcount_(prog.refcount_)
|
||||
{
|
||||
(*refcount_)++;
|
||||
@ -81,7 +92,7 @@ const shader_program &shader_program::operator =(const shader_program &prog)
|
||||
void shader_program::activate()
|
||||
{
|
||||
block_ = GPU_LoadShaderBlock(program_object_, "vertex", "texture_pos",
|
||||
"color", "model_view_proj");
|
||||
"draw_color", "model_view_proj");
|
||||
GPU_ActivateShaderProgram(program_object_, &block_);
|
||||
}
|
||||
|
||||
@ -92,5 +103,21 @@ void shader_program::deactivate()
|
||||
}
|
||||
}
|
||||
|
||||
void shader_program::set_color_mod(int r, int g, int b, int a)
|
||||
{
|
||||
static float color_mod[4];
|
||||
color_mod[0] = float(r) / 255;
|
||||
color_mod[1] = float(g) / 255;
|
||||
color_mod[2] = float(b) / 255;
|
||||
color_mod[3] = float(a) / 255;
|
||||
|
||||
GPU_SetAttributefv(attr_color_mod_, 4, color_mod);
|
||||
}
|
||||
|
||||
void shader_program::set_submerge(float val)
|
||||
{
|
||||
GPU_SetAttributef(attr_submerge_, val);
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
@ -35,9 +35,13 @@ public:
|
||||
void activate();
|
||||
void deactivate();
|
||||
|
||||
void set_color_mod(int r, int g, int b, int a);
|
||||
void set_submerge(float val);
|
||||
|
||||
private:
|
||||
Uint32 program_object_, vertex_object_, fragment_object_;
|
||||
GPU_ShaderBlock block_;
|
||||
int attr_color_mod_, attr_submerge_;
|
||||
unsigned *refcount_;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user