这是indexloc提供的服务,不要输入任何密码
Skip to content
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
39 changes: 39 additions & 0 deletions assets/shaders/alphamask.common.frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#version 120

//alpha masking shader
//
//applies an alpha mask texture to a base texture,
//then draws the masked texture.

//the base and mask texture, base is the plain terrain tile
uniform sampler2D texture;
uniform sampler2D mask_texture;

//disable blending and show the mask instead
uniform bool show_mask;

//get those interpolated texture position from vertexshader
varying vec2 base_tex_position;
varying vec2 mask_tex_position;


void main()
{
//get the texel from the uniform texture.
vec4 base_pixel = texture2D(texture, base_tex_position);
vec4 mask_pixel = texture2D(mask_texture, mask_tex_position);

float factor = 1.0 - mask_pixel.x;

vec4 blended_pixel = vec4(base_pixel.r, base_pixel.g, base_pixel.b, base_pixel.a - factor);

//force to pink
//blended_pixel = vec4(255.0/255.0, 20.0/255.0, 147.0/255.0, 1.0);
if (show_mask) {
gl_FragColor = mask_pixel;
} else {
gl_FragColor = blended_pixel;
}

gl_FragDepth = 0;
}
25 changes: 25 additions & 0 deletions assets/shaders/alphamask.common.vert.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//vertex shader for applying an alpha mask to a texture
#version 120

//modelview*projection matrix
uniform mat4 mvp_matrix;

//the position of this vertex
attribute vec4 vertex_position;

//send the texture coordinates to the fragmentshader
attribute vec2 tex_coordinates;
attribute vec2 mask_tex_coordinates;

//send the texture coordinates to the fragmentshader
varying vec2 base_tex_position;
varying vec2 mask_tex_position;

void main(void) {
//transform the position with the mvp matrix
gl_Position = gl_ModelViewProjectionMatrix * vertex_position;

//set the fixpoints for the tex coordinates at this vertex
mask_tex_position = mask_tex_coordinates;
base_tex_position = tex_coordinates;
}
1 change: 1 addition & 0 deletions assets/shaders/maptexture.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ varying vec2 tex_position;
void main (void) {
//this sets the fragment color to the corresponding texel.
gl_FragColor = texture2D(texture, tex_position);
gl_FragDepth = 0;
}
4 changes: 4 additions & 0 deletions assets/shaders/maptexture.vert.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ attribute vec4 vertex_position;
//the texture coordinates assigned to this vertex
attribute vec2 tex_coordinates;

attribute float player_number;

//interpolated texture coordinates sent to fragment shader
varying vec2 tex_position;
varying float vplayer_number;

void main(void) {
//transform the vertex coordinates
gl_Position = gl_ModelViewProjectionMatrix * vertex_position;

//pass the fix points for texture coordinates set at this vertex
tex_position = tex_coordinates;
vplayer_number = player_number;
}
65 changes: 18 additions & 47 deletions assets/shaders/teamcolors.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
//the unmodified texture itself
uniform sampler2D texture;

//the desired player number the final resulting colors
uniform int player_number;

//the alpha value which marks colors to be replaced
uniform float alpha_marker;

Expand All @@ -21,59 +18,33 @@ uniform vec4 player_color[64];
//interpolated texture coordinates sent from vertex shader
varying vec2 tex_position;

//the desired player number the final resulting colors
varying float vplayer_number;
varying float vz_order;

//create epsilon environment for float comparison
const float epsilon = 0.001;

//do the lookup in the player color table
//for a playernumber (red, blue, etc)
//get the subcolor (brightness variations)
vec4 get_color(int playernum, int subcolor) {
return player_color[((playernum-1) * 8) + subcolor];
}

//compare color c1 to a reference color
bool is_color(vec4 c1, vec4 reference) {
if (all(greaterThanEqual(c1, reference - epsilon)) && all(lessThanEqual(c1, reference + epsilon))) {
return true;
}
else {
return false;
}
}
const vec3 vepsilon = vec3(epsilon, epsilon, epsilon);


void main() {
//get the texel from the uniform texture.
vec4 pixel = texture2D(texture, tex_position);

//check if this texel has an alpha marker, so we can replace it's rgb values.
if (pixel[3] >= alpha_marker - epsilon && pixel[3] <= alpha_marker + epsilon) {

//set alpha to 1 for the comparison
pixel[3] = 1.0;

//don't replace the colors if it's already player 1 (blue)
//as the media convert scripts generates blue-player sprites
if (player_number != 1) {
bool found = false;

//try to find the base color, there are 8 of them.
for(int i = 0; i <= 7; i++) {
if (is_color(pixel, player_color[i])) {
//base color found, now replace it with the same color
//but player_number tinted.
pixel = get_color(player_number, i);
found = true;
break;
}
}
if (!found) {
//unknown base color gets pink muhahaha
pixel = vec4(255.0/255.0, 20.0/255.0, 147.0/255.0, 1.0);
}
if ( abs(pixel.a - alpha_marker) > epsilon )
{
//Even replace player 1's colours as we then remove a branch
for(int i = 0; i <= 7; i++) {
if ( all(lessThanEqual(abs(pixel.rgb - player_color[i].rgb), vepsilon)) )
{
pixel = player_color[int( ((vplayer_number-1) * 8) + i )];
//pixel = vec4(1, 1, 1, 1);
break;
}
}
}
//else the texel had no marker so we can just draw it without player coloring

gl_FragColor = pixel;
}
gl_FragDepth = 0.2;
//gl_FragDepth = floor(gl_FragColor.a) * 0.2;
}
1 change: 1 addition & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ add_subdirectory("console")
add_subdirectory("coord")
add_subdirectory("job")
add_subdirectory("pathfinding")
add_subdirectory("renderer")
add_subdirectory("shader")
add_subdirectory("util")
add_subdirectory("datastructure")
Expand Down
8 changes: 7 additions & 1 deletion cpp/game_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "util/strings.h"
#include "util/timer.h"

#include "renderer/renderer.h"

namespace openage {

/*
Expand Down Expand Up @@ -235,6 +237,8 @@ GameMain::GameMain(Engine *engine)
// shader initialisation
// read shader source codes and create shader objects for wrapping them.

graphics::Renderer::create(data_dir, &asset_dir);

char *texture_vert_code;
util::read_whole_file(&texture_vert_code, data_dir->join("shaders/maptexture.vert.glsl"));
auto plaintexture_vert = new shader::Shader(GL_VERTEX_SHADER, texture_vert_code);
Expand Down Expand Up @@ -551,11 +555,13 @@ bool GameMain::on_draw() {
Engine &engine = Engine::get();

// draw gaben, our great and holy protector, bringer of the half-life 3.
gaben->draw(coord::camgame {0, 0});
//gaben->draw(coord::camgame {0, 0});

// draw terrain
terrain->draw(&engine);

graphics::Renderer::get().render();

return true;
}

Expand Down
3 changes: 3 additions & 0 deletions cpp/renderer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_sources(${PROJECT_NAME}
renderer.cpp
)
Loading