add textures

This commit is contained in:
Zack Buhman 2025-05-24 11:18:15 -05:00
parent bc882eec96
commit fe9634ceb3
41 changed files with 17044 additions and 843 deletions

View File

@ -45,14 +45,32 @@ model/%/collision.h: model/%/collision.obj
model/%/model.h: model/%/model.obj
python ../model_generator2/generate_cpp.py $< $* > $@
%.ppm: %.png
magick -depth 8 $< $@
%.vq: %.ppm
../dreamcast/gen/k_means/k_means_vq $< $@
VQ_ASSETS = \
textures/brick_floor_diff_1k.vq \
textures/red_plaster_weathered_diff_512p.vq \
textures/wooden_gate_diff_1k.vq \
textures/brick_wall_10_diff_512p.vq \
textures/weathered_planks_diff_1k.vq \
textures/yellow_plaster_02_diff_512p.vq \
textures/rebar_reinforced_concrete_diff_512.vq \
textures/white_plaster_rough_02_diff_512p.vq \
textures/yellow_plaster_diff_512p.vq
ASSETS = \
model/haunted_mansion/collision.h \
model/haunted_mansion/model.h \
model/cone/model.h \
model/cube/model.h
asset-vq-gen: $(VQ_ASSETS)
asset-gen: $(ASSETS)
asset-clean:
rm -f $(ASSETS)
.PHONY: asset-gen asset-clean
.PHONY: asset-gen asset-vq-gen asset-clean

View File

@ -1,3 +1,15 @@
HAUNTED_MANSION_TEX = \
textures/brick_floor_diff_1k.vq.o \
textures/brick_wall_10_diff_512p.vq.o \
textures/rebar_reinforced_concrete_diff_512.vq.o \
textures/red_plaster_weathered_diff_512p.vq.o \
textures/weathered_planks_diff_1k.vq.o \
textures/white_plaster_rough_02_diff_512p.vq.o \
textures/wooden_gate_diff_1k.vq.o \
textures/yellow_plaster_02_diff_512p.vq.o \
textures/yellow_plaster_diff_512p.vq.o \
textures/generic.vq.o
HAUNTED_MANSION_OBJ = \
$(LIB)/holly/core.o \
$(LIB)/holly/region_array.o \
@ -6,4 +18,5 @@ HAUNTED_MANSION_OBJ = \
$(LIB)/holly/video_output.o \
$(LIB)/sh7091/serial.o \
$(LIB)/maple/maple.o \
src/haunted_mansion.o
src/haunted_mansion.o \
$(HAUNTED_MANSION_TEX)

15087
model/haunted_mansion/scene.h Normal file

File diff suppressed because it is too large Load Diff

93
src/collision.cpp Normal file
View File

@ -0,0 +1,93 @@
vec2 line_intersection(vec2 a1, vec2 a2,
vec2 b1, vec2 b2)
{
float x1 = a1.x;
float y1 = a1.y;
float x2 = a2.x;
float y2 = a2.y;
float x3 = b1.x;
float y3 = b1.y;
float x4 = b2.x;
float y4 = b2.y;
float x1x2 = x1 - x2;
float x1x3 = x1 - x3;
float x3x4 = x3 - x4;
float y1y2 = y1 - y2;
float y1y3 = y1 - y3;
float y3y4 = y3 - y4;
float div = 1.0f / (x1x2 * y3y4 - y1y2 * x3x4);
float t = (x1x3 * y3y4 - y1y3 * x3x4) * div;
float u = -(x1x2 * y1y3 - y1y2 * x1x3) * div;
return {t, u};
}
bool collided[256] = {};
bool line_has_collision(vec3 a1, vec3 a2, const mat4x4& model_trans, const mat4x4& screen)
{
mat4x4 trans = screen * model_trans;
const struct model * model = &haunted_mansion_collision_model;
const struct object * object = model->object[0];
for (int i = 0; i < object->line_count; i++) {
const union line * line = &object->line[i];
vec3 b1 = trans * model->position[line->a];
vec3 b2 = trans * model->position[line->b];
vec2 tu = line_intersection({a1.x, a1.z},
{a2.x, a2.z},
{b1.x, b1.z},
{b2.x, b2.z});
if (tu.x >= 0.0f && tu.x <= 1.0f && tu.y >= 0.0f && tu.y <= 1.0f) {
collided[i] = true;
return true;
}
}
return false;
}
float last_dx = 0;
float last_dy = 0;
void render_collision(ta_parameter_writer& writer, const mat4x4& model_trans, const mat4x4& screen)
{
mat4x4 trans = screen * model_trans;
const uint32_t base_color = 0xffffffff;
const struct model * model = &haunted_mansion_collision_model;
const struct object * object = model->object[0];
int line_count = object->line_count;
for (int i = 0; i < line_count; i++) {
const union line * line = &object->line[i];
vec3 a = trans * model->position[line->a];
vec3 b = trans * model->position[line->b];
render_line(writer,
screen_transform((vec3){a.x, -a.z, 4.f}),
screen_transform((vec3){b.x, -b.z, 4.f}),
collided[i] ? 0xffff0000 : base_color);
}
vec3 a = {last_dx * -4, -last_dy * -4, 4};
vec3 b = {last_dx * 0.5f, -last_dy * 0.5f, 4};
//if (a.z > 0) {
render_line(writer,
screen_transform(a),
screen_transform(b),
0xff00ff00);
//}
}

File diff suppressed because it is too large Load Diff

84
src/ta.hpp Normal file
View File

@ -0,0 +1,84 @@
void global_polygon_textured(ta_parameter_writer& writer,
uint32_t list,
const mesh_material * material)
{
uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume
| list
| obj_control::col_type::intensity_mode_1
| obj_control::gouraud
| obj_control::shadow
| obj_control::texture
;
uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::greater
| isp_tsp_instruction_word::culling_mode::no_culling;
uint32_t tsp_instruction_word = tsp_instruction_word::src_alpha_instr::one
| tsp_instruction_word::dst_alpha_instr::zero
| tsp_instruction_word::texture_shading_instruction::decal
| tsp_instruction_word::fog_control::no_fog
| tsp_instruction_word::texture_u_size::from_int(material->width)
| tsp_instruction_word::texture_v_size::from_int(material->height);
;
uint32_t texture_address = texture_memory_alloc.texture.start + material->offset;
uint32_t texture_control_word = texture_control_word::pixel_format::_565
| texture_control_word::scan_order::twiddled
| texture_control_word::vq_compressed
| texture_control_word::texture_address(texture_address / 8)
;
float a = 1.0f;
float r = 1.0f;
float g = 1.0f;
float b = 1.0f;
writer.append<ta_global_parameter::polygon_type_1>() =
ta_global_parameter::polygon_type_1(parameter_control_word,
isp_tsp_instruction_word,
tsp_instruction_word,
texture_control_word,
a,
r,
g,
b
);
}
void global_polygon_untextured(ta_parameter_writer& writer,
uint32_t list)
{
uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume
| list
| obj_control::col_type::intensity_mode_1
| obj_control::gouraud
| obj_control::shadow
;
uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::greater
| isp_tsp_instruction_word::culling_mode::no_culling;
uint32_t tsp_instruction_word = tsp_instruction_word::src_alpha_instr::one
| tsp_instruction_word::dst_alpha_instr::zero
| tsp_instruction_word::texture_shading_instruction::decal
| tsp_instruction_word::fog_control::no_fog
;
uint32_t texture_control_word = 0;
float a = 1.0f;
float r = 1.0f;
float g = 1.0f;
float b = 1.0f;
writer.append<ta_global_parameter::polygon_type_1>() =
ta_global_parameter::polygon_type_1(parameter_control_word,
isp_tsp_instruction_word,
tsp_instruction_word,
texture_control_word,
a,
r,
g,
b
);
}

245
src/transform.hpp Normal file
View File

@ -0,0 +1,245 @@
static inline float inverse_length(vec3 v)
{
float f = dot(v, v);
return (1.0f / (__builtin_sqrtf(f)));
}
static inline float light_intensity(vec3 light_vec, vec3 n)
{
float n_dot_l = dot(n, light_vec);
float intensity = 0.5f;
if (n_dot_l > 0) {
intensity += 0.5f * n_dot_l * (inverse_length(n) * inverse_length(light_vec));
if (intensity > 1.0f)
intensity = 1.0f;
}
return intensity;
}
static inline void render_tri(ta_parameter_writer& writer,
vec3 ap,
vec3 bp,
vec3 cp,
vec2 at,
vec2 bt,
vec2 ct,
float ai,
float bi,
float ci)
{
writer.append<ta_vertex_parameter::polygon_type_7>() =
ta_vertex_parameter::polygon_type_7(polygon_vertex_parameter_control_word(false),
ap.x, ap.y, ap.z,
at.x, at.y,
ai, 0);
writer.append<ta_vertex_parameter::polygon_type_7>() =
ta_vertex_parameter::polygon_type_7(polygon_vertex_parameter_control_word(false),
bp.x, bp.y, bp.z,
bt.x, bt.y,
bi, 0);
writer.append<ta_vertex_parameter::polygon_type_7>() =
ta_vertex_parameter::polygon_type_7(polygon_vertex_parameter_control_word(true),
cp.x, cp.y, cp.z,
ct.x, ct.y,
ci, 0);
}
static inline void render_quad(ta_parameter_writer& writer,
vec3 ap,
vec3 bp,
vec3 cp,
vec3 dp,
vec2 at,
vec2 bt,
vec2 ct,
vec2 dt,
float ai,
float bi,
float ci,
float di)
{
writer.append<ta_vertex_parameter::polygon_type_7>() =
ta_vertex_parameter::polygon_type_7(polygon_vertex_parameter_control_word(false),
ap.x, ap.y, ap.z,
at.x, at.y,
ai, 0);
writer.append<ta_vertex_parameter::polygon_type_7>() =
ta_vertex_parameter::polygon_type_7(polygon_vertex_parameter_control_word(false),
bp.x, bp.y, bp.z,
bt.x, bt.y,
bi, 0);
writer.append<ta_vertex_parameter::polygon_type_7>() =
ta_vertex_parameter::polygon_type_7(polygon_vertex_parameter_control_word(false),
dp.x, dp.y, dp.z,
dt.x, dt.y,
di, 0);
writer.append<ta_vertex_parameter::polygon_type_7>() =
ta_vertex_parameter::polygon_type_7(polygon_vertex_parameter_control_word(true),
cp.x, cp.y, cp.z,
ct.x, ct.y,
ci, 0);
}
static inline vec3 screen_transform(vec3 v)
{
float dim = 480 / 2.0;
return {
v.x / (1.f * v.z) * dim + 640 / 2.0f,
v.y / (1.f * v.z) * dim + 480 / 2.0f,
1 / v.z,
};
}
static inline void render_clip_tri(ta_parameter_writer& writer,
vec3 light_vec,
vec3 ap,
vec3 bp,
vec3 cp,
vec3 an,
vec3 bn,
vec3 cn,
vec2 at,
vec2 bt,
vec2 ct)
{
const vec3 plane_point = {0.f, 0.f, 1.f};
const vec3 plane_normal = {0.f, 0.f, 1.f};
vec3 preclip_position[] = {ap, bp, cp};
vec3 preclip_normal[] = {an, bn, cn};
vec2 preclip_texture[] = {at, bt, ct};
vec3 clip_position[4];
vec3 clip_normal[4];
vec2 clip_texture[4];
int output_length = geometry::clip_polygon_3<3>(clip_position,
clip_normal,
clip_texture,
plane_point,
plane_normal,
preclip_position,
preclip_normal,
preclip_texture);
{
float ai;
float bi;
float ci;
float di;
vec3 ap;
vec3 bp;
vec3 cp;
vec3 dp;
if (output_length >= 3) {
// 012
ap = screen_transform(clip_position[0]);
bp = screen_transform(clip_position[1]);
cp = screen_transform(clip_position[2]);
ai = light_intensity(light_vec, clip_normal[0]);
bi = light_intensity(light_vec, clip_normal[1]);
ci = light_intensity(light_vec, clip_normal[2]);
render_tri(writer,
ap,
bp,
cp,
clip_texture[0],
clip_texture[1],
clip_texture[2],
ai,
bi,
ci);
}
if (output_length >= 4) {
// 023
dp = screen_transform(clip_position[3]);
di = light_intensity(light_vec, clip_normal[3]);
render_tri(writer,
ap,
cp,
dp,
clip_texture[0],
clip_texture[2],
clip_texture[3],
ai,
ci,
di);
}
}
}
static inline void render_polygon(ta_parameter_writer& writer,
const vec3 light_vec,
const int polygon_ix,
const polygon * polygon,
const vec3 * position,
const vec3 * normal,
const vec2 * texture)
{
vec3 ap = position[polygon->a];
vec3 bp = position[polygon->b];
vec3 cp = position[polygon->c];
vec3 dp = position[polygon->d];
if (ap.z < 0 && bp.z < 0 && cp.z < 0 && dp.z < 0) {
return;
}
vec3 an = normal[polygon_ix];
vec3 bn = an;
vec3 cn = an;
vec3 dn = an;
vec2 at = texture[polygon->uv_index + 0];
vec2 bt = texture[polygon->uv_index + 1];
vec2 ct = texture[polygon->uv_index + 2];
vec2 dt = texture[polygon->uv_index + 3];
/*
at.y = 1.0 - at.y;
bt.y = 1.0 - bt.y;
ct.y = 1.0 - ct.y;
dt.y = 1.0 - dt.y;
*/
if (ap.z < 0 || bp.z < 0 || cp.z < 0 || dp.z < 0) {
// abd
// dbc
render_clip_tri(writer,
light_vec,
ap, bp, dp,
an, bn, dn,
at, bt, dt);
render_clip_tri(writer,
light_vec,
dp, bp, cp,
dn, bn, cn,
dt, bt, ct);
} else {
float ai = light_intensity(light_vec, an);
float bi = light_intensity(light_vec, bn);
float ci = light_intensity(light_vec, cn);
float di = light_intensity(light_vec, dn);
render_quad(writer,
screen_transform(ap),
screen_transform(bp),
screen_transform(cp),
screen_transform(dp),
at, bt, ct, dt,
ai, bi, ci, di);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 MiB

Binary file not shown.

View File

@ -0,0 +1,15 @@
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
extern uint32_t _binary_textures_brick_floor_diff_1k_vq_start __asm("_binary_textures_brick_floor_diff_1k_vq_start");
extern uint32_t _binary_textures_brick_floor_diff_1k_vq_end __asm("_binary_textures_brick_floor_diff_1k_vq_end");
extern uint32_t _binary_textures_brick_floor_diff_1k_vq_size __asm("_binary_textures_brick_floor_diff_1k_vq_size");
#ifdef __cplusplus
}
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 516 KiB

Binary file not shown.

View File

@ -0,0 +1,15 @@
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
extern uint32_t _binary_textures_brick_wall_10_diff_512p_vq_start __asm("_binary_textures_brick_wall_10_diff_512p_vq_start");
extern uint32_t _binary_textures_brick_wall_10_diff_512p_vq_end __asm("_binary_textures_brick_wall_10_diff_512p_vq_end");
extern uint32_t _binary_textures_brick_wall_10_diff_512p_vq_size __asm("_binary_textures_brick_wall_10_diff_512p_vq_size");
#ifdef __cplusplus
}
#endif

BIN
textures/generic.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

5
textures/generic.ppm Normal file

File diff suppressed because one or more lines are too long

BIN
textures/generic.vq Normal file

Binary file not shown.

15
textures/generic.vq.h Normal file
View File

@ -0,0 +1,15 @@
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
extern uint32_t _binary_textures_generic_vq_start __asm("_binary_textures_generic_vq_start");
extern uint32_t _binary_textures_generic_vq_end __asm("_binary_textures_generic_vq_end");
extern uint32_t _binary_textures_generic_vq_size __asm("_binary_textures_generic_vq_size");
#ifdef __cplusplus
}
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 506 KiB

Binary file not shown.

View File

@ -0,0 +1,15 @@
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
extern uint32_t _binary_textures_rebar_reinforced_concrete_diff_512_vq_start __asm("_binary_textures_rebar_reinforced_concrete_diff_512_vq_start");
extern uint32_t _binary_textures_rebar_reinforced_concrete_diff_512_vq_end __asm("_binary_textures_rebar_reinforced_concrete_diff_512_vq_end");
extern uint32_t _binary_textures_rebar_reinforced_concrete_diff_512_vq_size __asm("_binary_textures_rebar_reinforced_concrete_diff_512_vq_size");
#ifdef __cplusplus
}
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 493 KiB

Binary file not shown.

View File

@ -0,0 +1,15 @@
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
extern uint32_t _binary_textures_red_plaster_weathered_diff_512p_vq_start __asm("_binary_textures_red_plaster_weathered_diff_512p_vq_start");
extern uint32_t _binary_textures_red_plaster_weathered_diff_512p_vq_end __asm("_binary_textures_red_plaster_weathered_diff_512p_vq_end");
extern uint32_t _binary_textures_red_plaster_weathered_diff_512p_vq_size __asm("_binary_textures_red_plaster_weathered_diff_512p_vq_size");
#ifdef __cplusplus
}
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 MiB

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -0,0 +1,15 @@
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
extern uint32_t _binary_textures_weathered_planks_diff_1k_vq_start __asm("_binary_textures_weathered_planks_diff_1k_vq_start");
extern uint32_t _binary_textures_weathered_planks_diff_1k_vq_end __asm("_binary_textures_weathered_planks_diff_1k_vq_end");
extern uint32_t _binary_textures_weathered_planks_diff_1k_vq_size __asm("_binary_textures_weathered_planks_diff_1k_vq_size");
#ifdef __cplusplus
}
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 674 KiB

Binary file not shown.

View File

@ -0,0 +1,15 @@
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
extern uint32_t _binary_textures_white_plaster_rough_02_diff_512p_vq_start __asm("_binary_textures_white_plaster_rough_02_diff_512p_vq_start");
extern uint32_t _binary_textures_white_plaster_rough_02_diff_512p_vq_end __asm("_binary_textures_white_plaster_rough_02_diff_512p_vq_end");
extern uint32_t _binary_textures_white_plaster_rough_02_diff_512p_vq_size __asm("_binary_textures_white_plaster_rough_02_diff_512p_vq_size");
#ifdef __cplusplus
}
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 MiB

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -0,0 +1,15 @@
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
extern uint32_t _binary_textures_wooden_gate_diff_1k_vq_start __asm("_binary_textures_wooden_gate_diff_1k_vq_start");
extern uint32_t _binary_textures_wooden_gate_diff_1k_vq_end __asm("_binary_textures_wooden_gate_diff_1k_vq_end");
extern uint32_t _binary_textures_wooden_gate_diff_1k_vq_size __asm("_binary_textures_wooden_gate_diff_1k_vq_size");
#ifdef __cplusplus
}
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 453 KiB

Binary file not shown.

View File

@ -0,0 +1,15 @@
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
extern uint32_t _binary_textures_yellow_plaster_02_diff_512p_vq_start __asm("_binary_textures_yellow_plaster_02_diff_512p_vq_start");
extern uint32_t _binary_textures_yellow_plaster_02_diff_512p_vq_end __asm("_binary_textures_yellow_plaster_02_diff_512p_vq_end");
extern uint32_t _binary_textures_yellow_plaster_02_diff_512p_vq_size __asm("_binary_textures_yellow_plaster_02_diff_512p_vq_size");
#ifdef __cplusplus
}
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 352 KiB

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -0,0 +1,15 @@
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
extern uint32_t _binary_textures_yellow_plaster_diff_512p_vq_start __asm("_binary_textures_yellow_plaster_diff_512p_vq_start");
extern uint32_t _binary_textures_yellow_plaster_diff_512p_vq_end __asm("_binary_textures_yellow_plaster_diff_512p_vq_end");
extern uint32_t _binary_textures_yellow_plaster_diff_512p_vq_size __asm("_binary_textures_yellow_plaster_diff_512p_vq_size");
#ifdef __cplusplus
}
#endif