stage5: new PBR background

Co-authored-by: Andrei Alexeyev <akari@taisei-project.org>
This commit is contained in:
Lukas Weber 2021-04-13 20:33:20 +03:00 committed by Andrei Alexeyev
parent 85e3cf0bd8
commit 4e55d445f8
No known key found for this signature in database
GPG key ID: 72D26128040B9690
45 changed files with 226 additions and 100 deletions

Binary file not shown.

View file

@ -0,0 +1,7 @@
roughness_map = stage5/metal_roughness
ao_map = stage5/metal_ao
diffuse_color = 1 0.293 0.057
ambient_color = 0 0 0
metallic = 1

Binary file not shown.

View file

@ -0,0 +1 @@
anisotropy = 16

View file

@ -0,0 +1 @@
anisotropy = 16

View file

@ -0,0 +1,7 @@
diffuse_map = stage5/stairs_diffuse
normal_map = stage5/stairs_normal
roughness_map = stage5/stairs_roughness
ambient_map = stage5/stairs_ambient
ao_map = stage5/stairs_ao

View file

@ -0,0 +1 @@
anisotropy = 16

Binary file not shown.

View file

@ -0,0 +1 @@
anisotropy = 16

View file

@ -0,0 +1 @@
anisotropy = 16

View file

@ -0,0 +1 @@
anisotropy = 16

View file

@ -0,0 +1 @@
anisotropy = 16

View file

@ -0,0 +1,10 @@
diffuse_map = stage5/wall_diffuse
normal_map = stage5/wall_normal
roughness_map = stage5/wall_roughness
ambient_map = stage5/wall_ambient
ao_map = stage5/wall_ao
depth_map = stage5/wall_depth
depth_scale = 0.005

View file

@ -0,0 +1 @@
anisotropy = 16

Binary file not shown.

View file

@ -0,0 +1 @@
anisotropy = 16

Binary file not shown.

View file

@ -0,0 +1 @@
anisotropy = 16

View file

@ -0,0 +1 @@
anisotropy = 16

View file

@ -0,0 +1 @@
anisotropy = 16

View file

@ -0,0 +1 @@
anisotropy = 16

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -88,8 +88,6 @@ glsl_files = files(
'text_hud.frag.glsl',
'text_stagetext.frag.glsl',
'texture_post_load.frag.glsl',
'tower_light.frag.glsl',
'tower_light.vert.glsl',
'tower_wall.frag.glsl',
'tower_wall.vert.glsl',
'tunnel.frag.glsl',

View file

@ -1,12 +0,0 @@
#version 330 core
#include "interface/tower_light.glslh"
void main(void) {
vec4 texel = texture(tex, texCoord);
float light = (1.6+strength)*dot(normal*(vec3(0.1)+texel.xyz), normalize(l));
light = max(light, 0.0);
fragColor = vec4(vec3(texel + color*light)*(light+0.6)*1000.0/length(l),1.0);
}

View file

@ -1 +0,0 @@
objects = tower_light.vert tower_light.frag

View file

@ -1,11 +0,0 @@
#version 330 core
#include "lib/render_context.glslh"
#include "interface/tower_light.glslh"
void main(void) {
gl_Position = r_projectionMatrix * r_modelViewMatrix * vec4(position, 1.0);
texCoord = (r_textureMatrix * vec4(texCoordRawIn, 0.0, 1.0)).xy;
normal = normalIn;
l = lightvec - (r_modelViewMatrix*vec4(position,1.0)).xyz;
}

View file

@ -13,44 +13,97 @@
#include "global.h"
#include "stageutils.h"
#include "common_tasks.h"
MODERNIZE_THIS_FILE_AND_REMOVE_ME
void stage5_update(void) {
stage_3d_context.cam.aspect = STAGE3D_DEFAULT_ASPECT; // FIXME
stage_3d_context.cam.near = 100;
stage_3d_context.cam.far = 20000;
TASK(stage5_bg_update, NO_ARGS) {
Stage5DrawData *stage5_draw_data = stage5_get_draw_data();
TIMER(&global.timer);
float w = 0.005;
Camera3D *cam = &stage_3d_context.cam;
float vel = -0.015/3.7;
for(int i = 0;; i++) {
float r = stage5_draw_data->stairs.rad;
stage3d_update(&stage_3d_context);
cam->rot.v[2] = 180/M_PI*vel*i + stage5_draw_data->stairs.roffset;
cam->pos[0] = r*cos(vel*i);
cam->pos[1] = r*sin(vel*i);
stage5_draw_data->stairs.rotshift += stage5_draw_data->stairs.omega;
stage_3d_context.crot[0] += stage5_draw_data->stairs.omega*0.5;
stage5_draw_data->stairs.rad += stage5_draw_data->stairs.omega*20;
cam->pos[2] = stage5_draw_data->stairs.zoffset - 11.2/M_TAU*vel*i;
int rot_time = 6350;
stage5_draw_data->stairs.light_strength *= 0.975;
FROM_TO(rot_time, rot_time+50, 1) {
stage5_draw_data->stairs.omega -= 0.005;
if(rng_chance(0.007)) {
stage5_draw_data->stairs.light_strength = fmax(stage5_draw_data->stairs.light_strength, rng_range(5, 10));
}
YIELD;
}
FROM_TO(rot_time+200, rot_time+250, 1) {
stage5_draw_data->stairs.omega += 0.005;
}
stage_3d_context.cx[0] = stage5_draw_data->stairs.rad*cos(-w*global.frames);
stage_3d_context.cx[1] = stage5_draw_data->stairs.rad*sin(-w*global.frames);
stage_3d_context.cx[2] = -1700+w*3000/M_PI*global.frames;
stage_3d_context.crot[2] = stage5_draw_data->stairs.rotshift-180/M_PI*w*global.frames;
stage5_draw_data->stairs.light_strength *= 0.98;
if (frand() < 0.01) {
stage5_draw_data->stairs.light_strength = 5+5*frand();
}
stage3d_update(&stage_3d_context);
}
void stage5_bg_init_fullstage(void) {
Camera3D *cam = &stage_3d_context.cam;
cam->pos[0] = 0;
cam->pos[1] = 2.5;
cam->rot.v[0] = 80;
cam->fovy = STAGE3D_DEFAULT_FOVY*1.5;
INVOKE_TASK(stage5_bg_update);
}
void stage5_bg_init_spellpractice(void) {
Camera3D *cam = &stage_3d_context.cam;
cam->pos[0] = 0;
cam->pos[1] = 2.5;
cam->rot.v[0] = 45;
cam->fovy = STAGE3D_DEFAULT_FOVY*1.5;
Stage5DrawData *stage5_draw_data = stage5_get_draw_data();
stage5_draw_data->stairs.roffset = -90;
stage5_draw_data->stairs.zoffset = 5;
stage5_draw_data->stairs.rad = -3;
INVOKE_TASK(stage5_bg_update);
}
void stage5_bg_raise_lightning(void) {
Stage5DrawData *stage5_draw_data = stage5_get_draw_data();
INVOKE_TASK(common_easing_animate,
.value = &stage5_draw_data->stairs.light_pos,
.to = 120,
.duration = 200,
.ease = glm_ease_quad_out
);
INVOKE_TASK(common_easing_animate,
.value = &stage5_draw_data->stairs.light_strength,
.to = 5,
.duration = 200,
.ease = glm_ease_quad_inout
);
}
void stage5_bg_lower_camera(void) {
Stage5DrawData *stage5_draw_data = stage5_get_draw_data();
INVOKE_TASK(common_easing_animate,
.value = &stage5_draw_data->stairs.zoffset,
.to = 5,
.duration = 600,
.ease = glm_ease_quad_inout
);
INVOKE_TASK_DELAYED(60,common_easing_animate,
.value = &stage5_draw_data->stairs.rad,
.to = -3,
.duration = 600,
.ease = glm_ease_quad_inout
);
INVOKE_TASK_DELAYED(60, common_easing_animate,
.value = &stage_3d_context.cam.rot.v[0],
.to = 45,
.duration = 700,
.ease = glm_ease_quad_inout
);
INVOKE_TASK_DELAYED(120, common_easing_animate,
.value = &stage5_draw_data->stairs.roffset,
.to = -90,
.duration = 400,
.ease = glm_ease_quad_inout
);
}

View file

@ -11,4 +11,8 @@
#include "coroutine.h"
void stage5_update(void);
void stage5_bg_raise_lightning(void);
void stage5_bg_lower_camera(void);
void stage5_bg_init_fullstage(void);
void stage5_bg_init_spellpractice(void);

View file

@ -12,6 +12,8 @@
#include "global.h"
#include "stageutils.h"
#include "util/glm.h"
#include "resource/model.h"
MODERNIZE_THIS_FILE_AND_REMOVE_ME
@ -25,10 +27,17 @@ void stage5_drawsys_init(void) {
stage5_draw_data = calloc(1, sizeof(*stage5_draw_data));
stage3d_init(&stage_3d_context, 16);
stage_3d_context.crot[0] = 60;
stage5_draw_data->stairs.light_pos = -200;
stage5_draw_data->stairs.rotshift = 140;
stage5_draw_data->stairs.rad = 2800;
stage5_draw_data->stairs.rad = 3.7;
stage5_draw_data->stairs.zoffset = 3.2;
stage5_draw_data->stairs.roffset = -210;
pbr_load_model(&stage5_draw_data->models.metal, "stage5/metal", "stage5/metal");
pbr_load_model(&stage5_draw_data->models.stairs, "stage5/stairs", "stage5/stairs");
pbr_load_model(&stage5_draw_data->models.wall, "stage5/wall", "stage5/wall");
stage5_draw_data->env_map = res_texture("stage5/envmap");
}
void stage5_drawsys_shutdown(void) {
@ -39,28 +48,68 @@ void stage5_drawsys_shutdown(void) {
static uint stage5_stairs_pos(Stage3D *s3d, vec3 pos, float maxrange) {
vec3 p = {0, 0, 0};
vec3 r = {0, 0, 6000};
vec3 r = {0, 0, 11.2};
return linear3dpos(s3d, pos, maxrange, p, r);
}
static void stage5_bg_setup_pbr_lighting(Camera3D *cam) {
PointLight3D lights[] = {
{ { 1.2 * cam->pos[0], 1.2 * cam->pos[1], cam->pos[2] - 0.2 }, { 235*0.4, 104*0.4, 32*0.4 } },
{ { 0, 0, cam->pos[2] - 1}, { 0.2, 0, 13.2 } },
{ { 0, 0, cam->pos[2] - 6}, { 0.2, 0, 13.2 } },
{ { 0, 0, cam->pos[2] + 100}, { 1000, 1000, 1000 } },
// thunder lightning
{ 0, cam->pos[1], cam->pos[2] + stage5_draw_data->stairs.light_pos, { 5000, 8000, 100000 } },
};
float light_strength = stage5_draw_data->stairs.light_strength;
glm_vec3_scale(lights[3].radiance, 1+0.5*light_strength, lights[3].radiance);
glm_vec3_scale(lights[4].radiance, light_strength, lights[4].radiance);
camera3d_set_point_light_uniforms(cam, ARRAY_SIZE(lights), lights);
}
static void stage5_bg_setup_pbr_env(Camera3D *cam, PBREnvironment *env) {
stage5_bg_setup_pbr_lighting(cam);
glm_vec3_broadcast(1.0f + stage5_draw_data->stairs.light_strength, env->ambient_color);
env->environment_map = stage5_draw_data->env_map;
camera3d_apply_inverse_transforms(cam, env->cam_inverse_transform);
}
static void stage5_stairs_draw(vec3 pos) {
r_state_push();
r_mat_mv_push();
r_mat_mv_translate(pos[0], pos[1], pos[2]);
r_mat_mv_scale(300,300,300);
r_shader("tower_light");
r_uniform_sampler("tex", "stage5/tower");
r_uniform_vec3("lightvec", 0, 0, 0);
r_uniform_vec4("color", 0.1, 0.1, 0.5, 1);
r_uniform_float("strength", stage5_draw_data->stairs.light_strength);
r_draw_model("tower");
r_shader("pbr");
PBREnvironment env = { 0 };
stage5_bg_setup_pbr_env(&stage_3d_context.cam, &env);
pbr_draw_model(&stage5_draw_data->models.stairs, &env);
pbr_draw_model(&stage5_draw_data->models.wall, &env);
pbr_draw_model(&stage5_draw_data->models.metal, &env);
r_mat_mv_pop();
r_state_pop();
}
void stage5_draw(void) {
stage3d_draw(&stage_3d_context, 30000, 1, (Stage3DSegment[]) { stage5_stairs_draw, stage5_stairs_pos });
stage3d_draw(&stage_3d_context, 50, 1, (Stage3DSegment[]) { stage5_stairs_draw, stage5_stairs_pos });
}
static bool stage5_fog(Framebuffer *fb) {
r_shader("zbuf_fog");
r_uniform_sampler("depth", r_framebuffer_get_attachment(fb, FRAMEBUFFER_ATTACH_DEPTH));
r_uniform_vec4_rgba("fog_color", color_mul_scalar(RGB(0.3,0.1,0.8), 1.0));
r_uniform_float("start", 0.2);
r_uniform_float("end", 3.8);
r_uniform_float("exponent", 3.0);
r_uniform_float("sphereness", 0);
draw_framebuffer_tex(fb, VIEWPORT_W, VIEWPORT_H);
r_shader_standard();
return true;
}
void iku_spell_bg(Boss *b, int t) {
@ -85,3 +134,8 @@ void iku_spell_bg(Boss *b, int t) {
r_color4(opacity, opacity, opacity, opacity);
fill_viewport(0, 300, 1, "stage5/spell_lightning");
}
ShaderRule stage5_bg_effects[] = {
stage5_fog,
NULL
};

View file

@ -13,25 +13,13 @@
#include "stageutils.h"
typedef struct Stage5DrawData {
struct {
float exponent;
float brightness;
} fog;
struct {
float r;
float g;
float b;
float mixfactor;
} color;
struct {
float light_strength;
float light_pos;
float rotshift;
float omega;
float rad;
float zoffset;
float roffset;
} stairs;
struct {
@ -39,6 +27,8 @@ typedef struct Stage5DrawData {
PBRModel stairs;
PBRModel wall;
} models;
Texture *env_map;
} Stage5DrawData;
void stage5_drawsys_init(void);
@ -50,4 +40,3 @@ void iku_spell_bg(Boss *b, int t);
Stage5DrawData *stage5_get_draw_data(void);
extern ShaderRule stage5_bg_effects[];
extern ShaderRule stage5_postprocess[];

View file

@ -51,6 +51,7 @@ struct stage5_spells_s stage5_spells = {
static void stage5_start(void) {
stage5_drawsys_init();
stage5_bg_init_fullstage();
}
static void stage5_preload(void) {
@ -64,18 +65,28 @@ static void stage5_preload(void) {
"stage5/spell_bg",
"stage5/spell_clouds",
"stage5/spell_lightning",
"stage5/tower",
NULL);
preload_resources(RES_TEXTURE, RESF_DEFAULT,
"stage5/envmap",
NULL);
preload_resources(RES_MATERIAL, RESF_DEFAULT,
"stage5/metal",
"stage5/stairs",
"stage5/wall",
NULL);
preload_resources(RES_MODEL, RESF_DEFAULT,
"stage5/stairs",
"stage5/wall",
"stage5/metal",
NULL);
preload_resources(RES_SHADER_PROGRAM, RESF_DEFAULT,
"tower_light",
"pbr",
"zbuf_fog",
NULL);
preload_resources(RES_ANIM, RESF_DEFAULT,
"boss/iku",
"boss/iku_mid",
NULL);
preload_resources(RES_MODEL, RESF_DEFAULT,
"tower",
NULL);
preload_resources(RES_SFX, RESF_OPTIONAL,
"boom",
"laser1",
@ -88,7 +99,8 @@ static void stage5_end(void) {
}
static void stage5_spellpractice_start(void) {
stage5_start();
stage5_drawsys_init();
stage5_bg_init_spellpractice();
global.boss = stage5_spawn_iku(BOSS_DEFAULT_SPAWN_POS);
boss_add_attack_from_info(global.boss, global.stage->spell, true);
@ -97,16 +109,13 @@ static void stage5_spellpractice_start(void) {
stage_start_bgm("stage5boss");
}
ShaderRule stage5_shaders[] = { NULL };
StageProcs stage5_procs = {
.begin = stage5_start,
.preload = stage5_preload,
.end = stage5_end,
.draw = stage5_draw,
.update = stage5_update,
.event = stage5_events,
.shader_rules = stage5_shaders,
.shader_rules = stage5_bg_effects,
.spellpractice_procs = &stage5_spell_procs,
};
@ -115,6 +124,5 @@ StageProcs stage5_spell_procs = {
.preload = stage5_preload,
.end = stage5_end,
.draw = stage5_draw,
.update = stage5_update,
.shader_rules = stage5_shaders,
.shader_rules = stage5_bg_effects,
};

View file

@ -10,6 +10,7 @@
#include "timeline.h"
#include "stage5.h"
#include "background_anim.h"
#include "nonspells/nonspells.h"
#include "spells/spells.h"
@ -252,6 +253,8 @@ static Boss *stage5_spawn_midboss(void) {
boss_engage(b);
b->attacks->starttime = global.frames; // HACK: thwart attack delay
stage5_bg_raise_lightning();
return b;
}
@ -552,6 +555,10 @@ void stage5_events(void) {
create_enemy1c(VIEWPORT_W+200.0*I*afrand(0), 500, Swirl, stage5_miner, -3+2.0*I*afrand(1));
}
AT(6300) {
stage5_bg_lower_camera();
}
FROM_TO(6300, 6350, 50) {
create_enemy1c(VIEWPORT_W/4+VIEWPORT_W/2*!(_i&1), 2000, BigFairy, stage5_limiter, 2*I);
}