block shader: add "shine" effect

This wasn't difficult to implement, but I think doing a "real" lighting
calculation would give a better effect.
This commit is contained in:
Zack Buhman 2025-12-05 21:29:32 -06:00
parent 44cc1f8a6b
commit 29098a4eb9
4 changed files with 25 additions and 1 deletions

View File

@ -22,6 +22,7 @@ extern "C" {
uint uniform_normal_trans, uint uniform_normal_trans,
uint uniform_base_color, uint uniform_base_color,
uint uniform_light_pos, uint uniform_light_pos,
uint uniform_time,
struct game_state * state); struct game_state * state);
void render_balls(struct mesh ball_mesh, void render_balls(struct mesh ball_mesh,

View File

@ -162,6 +162,7 @@ int main()
uint block__uniform_normal_trans = glGetUniformLocation(block_program, "normal_trans"); uint block__uniform_normal_trans = glGetUniformLocation(block_program, "normal_trans");
uint block__uniform_base_color = glGetUniformLocation(block_program, "base_color"); uint block__uniform_base_color = glGetUniformLocation(block_program, "base_color");
uint block__uniform_light_pos = glGetUniformLocation(block_program, "light_pos"); uint block__uniform_light_pos = glGetUniformLocation(block_program, "light_pos");
uint block__uniform_time = glGetUniformLocation(block_program, "time");
// font // font
@ -332,6 +333,7 @@ int main()
block__uniform_normal_trans, block__uniform_normal_trans,
block__uniform_base_color, block__uniform_base_color,
block__uniform_light_pos, block__uniform_light_pos,
block__uniform_time,
&state); &state);
glDisable(GL_BLEND); glDisable(GL_BLEND);

View File

@ -100,6 +100,7 @@ void render_blocks(mesh block_mesh,
uint uniform_normal_trans, uint uniform_normal_trans,
uint uniform_base_color, uint uniform_base_color,
uint uniform_light_pos, uint uniform_light_pos,
uint uniform_time,
struct game_state * state) struct game_state * state)
{ {
light_pos_theta += 0.01; light_pos_theta += 0.01;
@ -136,6 +137,8 @@ void render_blocks(mesh block_mesh,
// render blocks // render blocks
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
glUniform1f(uniform_time, state->time);
mat4x4 a = aspect_mat(); mat4x4 a = aspect_mat();
vec3 light_pos = _light_pos(); vec3 light_pos = _light_pos();

View File

@ -3,6 +3,8 @@
uniform vec4 base_color; uniform vec4 base_color;
uniform vec3 light_pos; uniform vec3 light_pos;
uniform float time;
varying vec3 fp_position; varying vec3 fp_position;
varying vec2 fp_texture; varying vec2 fp_texture;
varying vec3 fp_normal; varying vec3 fp_normal;
@ -12,7 +14,23 @@ void main()
vec3 light_dir = normalize(light_pos - fp_position); vec3 light_dir = normalize(light_pos - fp_position);
float diffuse = max(dot(fp_normal, light_dir), 0.0); float diffuse = max(dot(fp_normal, light_dir), 0.0);
vec3 color = (diffuse + 0.5) * base_color.xyz; float g = fp_position.x + fp_position.y;
float gt = g * 8.0 + time * 10;
float d = sin(gt) / 8.0;
d = abs(d);
d = 0.05 / d;
float sgt = sin(gt / 10);
if (sgt < 0.9)
d = 0;
else
d = (sgt - 0.9) * 10;
//d = d * sin(time);
d = pow(d, 32);
vec3 color = (diffuse + 0.5) * (base_color.xyz + max(d * 0.5, 0));
gl_FragColor = vec4(color, base_color.w); gl_FragColor = vec4(color, base_color.w);
//gl_FragColor = vec4(d, 0, 0, base_color.w);
} }