32bitlogo: improve topology, display wireframe and textured
This commit is contained in:
parent
2b96cea9fc
commit
5eaadbb1c9
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@ -129,7 +129,7 @@ void core_param_init()
|
|||||||
{
|
{
|
||||||
uint32_t region_array_start = texture_memory_alloc.region_array.start;
|
uint32_t region_array_start = texture_memory_alloc.region_array.start;
|
||||||
uint32_t isp_tsp_parameters_start = texture_memory_alloc.isp_tsp_parameters.start;
|
uint32_t isp_tsp_parameters_start = texture_memory_alloc.isp_tsp_parameters.start;
|
||||||
uint32_t background_start = texture_memory_alloc.framebuffer[0].start;
|
uint32_t background_start = texture_memory_alloc.background[0].start;
|
||||||
|
|
||||||
holly.REGION_BASE = region_array_start;
|
holly.REGION_BASE = region_array_start;
|
||||||
holly.PARAM_BASE = isp_tsp_parameters_start;
|
holly.PARAM_BASE = isp_tsp_parameters_start;
|
||||||
|
@ -16,14 +16,48 @@ static vec3 screen_transform(const vec3& v)
|
|||||||
return {v.x, v.y, 1.0f / v.z};
|
return {v.x, v.y, 1.0f / v.z};
|
||||||
}
|
}
|
||||||
|
|
||||||
static void render_mesh(ta_parameter_writer& writer, const mesh& mesh, const mat4x4& trans)
|
static inline float light_intensity(vec3 n, vec3 l)
|
||||||
{
|
{
|
||||||
const int base_color = 0xffffff;
|
float ambient = 0.2f;
|
||||||
|
float diffuse_strength = 0.7f;
|
||||||
|
|
||||||
|
float n_dot_l = dot(n, l);
|
||||||
|
float diffuse = 0;
|
||||||
|
if (n_dot_l > 0)
|
||||||
|
diffuse = diffuse_strength * n_dot_l * (inverse_length(n) * inverse_length(l));
|
||||||
|
|
||||||
|
return ambient + diffuse;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 light_vec = (vec3){-1, -1, -1} - (vec3){0, 0, 0};
|
||||||
|
|
||||||
|
static void render_mesh(ta_parameter_writer& writer, const mesh& mesh, const mat4x4& trans, bool wireframe)
|
||||||
|
{
|
||||||
|
if (wireframe) {
|
||||||
|
global_polygon_untextured(writer,
|
||||||
|
para_control::list_type::opaque,
|
||||||
|
tsp_instruction_word::dst_alpha_instr::zero);
|
||||||
|
} else {
|
||||||
|
uint32_t texture_size = tsp_instruction_word::texture_u_size::from_int(8)
|
||||||
|
| tsp_instruction_word::texture_v_size::from_int(8);
|
||||||
|
|
||||||
|
global_polygon_intensity(writer,
|
||||||
|
para_control::list_type::opaque,
|
||||||
|
texture::offset::logo,
|
||||||
|
texture_size,
|
||||||
|
texture_control_word::pixel_format::_565);
|
||||||
|
}
|
||||||
|
|
||||||
vec3 position_cache[mesh.position_length];
|
vec3 position_cache[mesh.position_length];
|
||||||
for (int i = 0; i < mesh.position_length; i++) {
|
for (int i = 0; i < mesh.position_length; i++) {
|
||||||
position_cache[i] = screen_transform(trans * mesh.position[i]);
|
position_cache[i] = screen_transform(trans * mesh.position[i]);
|
||||||
}
|
}
|
||||||
|
vec3 normal_cache[mesh.polygons_length];
|
||||||
|
for (int i = 0; i < mesh.polygons_length; i++) {
|
||||||
|
normal_cache[i] = normal_multiply(trans, mesh.polygon_normal[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
const int green = 0x00ff00;
|
||||||
|
|
||||||
for (int i = 0; i < mesh.polygons_length; i++) {
|
for (int i = 0; i < mesh.polygons_length; i++) {
|
||||||
const polygon& p = mesh.polygons[i];
|
const polygon& p = mesh.polygons[i];
|
||||||
@ -31,16 +65,40 @@ static void render_mesh(ta_parameter_writer& writer, const mesh& mesh, const mat
|
|||||||
vec3 ap = position_cache[p.a];
|
vec3 ap = position_cache[p.a];
|
||||||
vec3 bp = position_cache[p.b];
|
vec3 bp = position_cache[p.b];
|
||||||
vec3 cp = position_cache[p.c];
|
vec3 cp = position_cache[p.c];
|
||||||
|
vec3 dp = position_cache[p.d];
|
||||||
|
|
||||||
|
if (wireframe) {
|
||||||
|
line_type_0(writer, ap, bp, green);
|
||||||
|
line_type_0(writer, bp, cp, green);
|
||||||
|
if (p.d == -1) {
|
||||||
|
line_type_0(writer, cp, ap, green);
|
||||||
|
} else {
|
||||||
|
line_type_0(writer, cp, dp, green);
|
||||||
|
line_type_0(writer, dp, ap, green);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
vec2 at = mesh.uv_layers[0][p.uv_index + 0];
|
vec2 at = mesh.uv_layers[0][p.uv_index + 0];
|
||||||
vec2 bt = mesh.uv_layers[0][p.uv_index + 1];
|
vec2 bt = mesh.uv_layers[0][p.uv_index + 1];
|
||||||
vec2 ct = mesh.uv_layers[0][p.uv_index + 2];
|
vec2 ct = mesh.uv_layers[0][p.uv_index + 2];
|
||||||
|
vec2 dt = mesh.uv_layers[0][p.uv_index + 3];
|
||||||
|
|
||||||
tri_type_3(writer,
|
float intensity = light_intensity(normal_cache[i], light_vec);
|
||||||
|
|
||||||
|
if (p.d == -1) {
|
||||||
|
tri_type_7(writer,
|
||||||
ap, at,
|
ap, at,
|
||||||
bp, bt,
|
bp, bt,
|
||||||
cp, ct,
|
cp, ct,
|
||||||
base_color);
|
intensity);
|
||||||
|
} else {
|
||||||
|
quad_type_7(writer,
|
||||||
|
ap, at,
|
||||||
|
bp, bt,
|
||||||
|
cp, ct,
|
||||||
|
dp, dt,
|
||||||
|
intensity);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,6 +126,7 @@ namespace scene::logo {
|
|||||||
struct keyframe {
|
struct keyframe {
|
||||||
float rx;
|
float rx;
|
||||||
float ry;
|
float ry;
|
||||||
|
float s;
|
||||||
float duration;
|
float duration;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -75,11 +134,13 @@ namespace scene::logo {
|
|||||||
{
|
{
|
||||||
.rx = 0,
|
.rx = 0,
|
||||||
.ry = 0,
|
.ry = 0,
|
||||||
|
.s = 0.1,
|
||||||
.duration = 1.0 / (5 * 60),
|
.duration = 1.0 / (5 * 60),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.rx = pi / 4,
|
.rx = pi / 4,
|
||||||
.ry = pi + pi / 4,
|
.ry = pi + pi / 4,
|
||||||
|
.s = 0.7,
|
||||||
.duration = 1.0 / (10 * 60),
|
.duration = 1.0 / (10 * 60),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -100,25 +161,18 @@ namespace scene::logo {
|
|||||||
|
|
||||||
float drx = b.rx - a.rx;
|
float drx = b.rx - a.rx;
|
||||||
float dry = b.ry - a.ry;
|
float dry = b.ry - a.ry;
|
||||||
|
float drs = b.s - a.s;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
.rx = a.rx + drx * ratio,
|
.rx = a.rx + drx * ratio,
|
||||||
.ry = a.ry + dry * ratio,
|
.ry = a.ry + dry * ratio,
|
||||||
|
.s = a.s + drs * ratio,
|
||||||
.duration = a.duration,
|
.duration = a.duration,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void transfer(ta_parameter_writer& writer)
|
void transfer(ta_parameter_writer& writer)
|
||||||
{
|
{
|
||||||
uint32_t texture_size = tsp_instruction_word::texture_u_size::from_int(8)
|
|
||||||
| tsp_instruction_word::texture_v_size::from_int(8);
|
|
||||||
|
|
||||||
global_polygon_textured(writer,
|
|
||||||
para_control::list_type::opaque,
|
|
||||||
texture::offset::logo,
|
|
||||||
texture_size,
|
|
||||||
texture_control_word::pixel_format::_565);
|
|
||||||
|
|
||||||
vec3 t = {framebuffer.px_width / 2.f, framebuffer.px_height / 2.f, 0};
|
vec3 t = {framebuffer.px_width / 2.f, framebuffer.px_height / 2.f, 0};
|
||||||
float s = framebuffer.px_height / 3.f;
|
float s = framebuffer.px_height / 3.f;
|
||||||
|
|
||||||
@ -130,11 +184,14 @@ namespace scene::logo {
|
|||||||
* translate((vec3){0, 0, 10})
|
* translate((vec3){0, 0, 10})
|
||||||
//* rotate_x(pi / 8)
|
//* rotate_x(pi / 8)
|
||||||
//* rotate_y(pi + pi/8)
|
//* rotate_y(pi + pi/8)
|
||||||
|
* scale(k.s)
|
||||||
* rotate_x(k.rx)
|
* rotate_x(k.rx)
|
||||||
* rotate_y(k.ry)
|
* rotate_y(k.ry)
|
||||||
* scale((vec3){-1, -1, 1});
|
* scale((vec3){-1, -1, 1});
|
||||||
|
|
||||||
render_mesh(writer, mesh_logo, trans);
|
render_mesh(writer, mesh_thirty_two, trans, tick < (6 * 60));
|
||||||
|
render_mesh(writer, mesh_bit, trans, tick < (7 * 60));
|
||||||
|
render_mesh(writer, mesh_jam, trans, tick < (8 * 60));
|
||||||
|
|
||||||
writer.append<ta_global_parameter::end_of_list>() =
|
writer.append<ta_global_parameter::end_of_list>() =
|
||||||
ta_global_parameter::end_of_list(para_control::para_type::end_of_list);
|
ta_global_parameter::end_of_list(para_control::para_type::end_of_list);
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
#include "holly/texture_memory_alloc9.hpp"
|
#include "holly/texture_memory_alloc9.hpp"
|
||||||
#include "math/float_types.hpp"
|
#include "math/float_types.hpp"
|
||||||
|
|
||||||
|
#include "math/math.hpp"
|
||||||
|
|
||||||
static inline void global_polygon_textured(ta_parameter_writer& writer,
|
static inline void global_polygon_textured(ta_parameter_writer& writer,
|
||||||
uint32_t list_type,
|
uint32_t list_type,
|
||||||
uint32_t texture_offset,
|
uint32_t texture_offset,
|
||||||
@ -44,6 +46,40 @@ static inline void global_polygon_textured(ta_parameter_writer& writer,
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void global_polygon_intensity(ta_parameter_writer& writer,
|
||||||
|
uint32_t list_type,
|
||||||
|
uint32_t texture_offset,
|
||||||
|
uint32_t texture_size,
|
||||||
|
uint32_t pixel_format)
|
||||||
|
{
|
||||||
|
const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume
|
||||||
|
| list_type
|
||||||
|
| obj_control::col_type::packed_color
|
||||||
|
| obj_control::texture
|
||||||
|
| obj_control::col_type::intensity_mode_1
|
||||||
|
;
|
||||||
|
|
||||||
|
const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::greater_or_equal
|
||||||
|
| isp_tsp_instruction_word::culling_mode::no_culling;
|
||||||
|
|
||||||
|
const uint32_t tsp_instruction_word = tsp_instruction_word::texture_shading_instruction::modulate
|
||||||
|
| tsp_instruction_word::src_alpha_instr::one
|
||||||
|
| tsp_instruction_word::dst_alpha_instr::zero
|
||||||
|
| tsp_instruction_word::fog_control::no_fog
|
||||||
|
| texture_size;
|
||||||
|
|
||||||
|
const uint32_t texture_address = texture_memory_alloc.texture.start + texture_offset;
|
||||||
|
const uint32_t texture_control_word = pixel_format
|
||||||
|
| texture_control_word::scan_order::twiddled
|
||||||
|
| texture_control_word::texture_address(texture_address / 8);
|
||||||
|
|
||||||
|
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,
|
||||||
|
1, 1, 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
static inline void global_polygon_untextured(ta_parameter_writer& writer, uint32_t list_type, uint32_t dst_alpha)
|
static inline void global_polygon_untextured(ta_parameter_writer& writer, uint32_t list_type, uint32_t dst_alpha)
|
||||||
{
|
{
|
||||||
@ -109,29 +145,61 @@ static inline void quad_type_3(ta_parameter_writer& writer,
|
|||||||
base_color, 0);
|
base_color, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void tri_type_3(ta_parameter_writer& writer,
|
static inline void tri_type_7(ta_parameter_writer& writer,
|
||||||
const vec3& ap, const vec2& at,
|
const vec3& ap, const vec2& at,
|
||||||
const vec3& bp, const vec2& bt,
|
const vec3& bp, const vec2& bt,
|
||||||
const vec3& cp, const vec2& ct,
|
const vec3& cp, const vec2& ct,
|
||||||
int base_color)
|
float intensity)
|
||||||
{
|
{
|
||||||
writer.append<ta_vertex_parameter::polygon_type_3>() =
|
writer.append<ta_vertex_parameter::polygon_type_7>() =
|
||||||
ta_vertex_parameter::polygon_type_3(polygon_vertex_parameter_control_word(false),
|
ta_vertex_parameter::polygon_type_7(polygon_vertex_parameter_control_word(false),
|
||||||
ap.x, ap.y, ap.z,
|
ap.x, ap.y, ap.z,
|
||||||
at.x, at.y,
|
at.x, at.y,
|
||||||
base_color, 0);
|
intensity, 0);
|
||||||
|
|
||||||
writer.append<ta_vertex_parameter::polygon_type_3>() =
|
writer.append<ta_vertex_parameter::polygon_type_7>() =
|
||||||
ta_vertex_parameter::polygon_type_3(polygon_vertex_parameter_control_word(false),
|
ta_vertex_parameter::polygon_type_7(polygon_vertex_parameter_control_word(false),
|
||||||
bp.x, bp.y, bp.z,
|
bp.x, bp.y, bp.z,
|
||||||
bt.x, bt.y,
|
bt.x, bt.y,
|
||||||
base_color, 0);
|
intensity, 0);
|
||||||
|
|
||||||
writer.append<ta_vertex_parameter::polygon_type_3>() =
|
writer.append<ta_vertex_parameter::polygon_type_7>() =
|
||||||
ta_vertex_parameter::polygon_type_3(polygon_vertex_parameter_control_word(true),
|
ta_vertex_parameter::polygon_type_7(polygon_vertex_parameter_control_word(true),
|
||||||
cp.x, cp.y, cp.z,
|
cp.x, cp.y, cp.z,
|
||||||
ct.x, ct.y,
|
ct.x, ct.y,
|
||||||
base_color, 0);
|
intensity, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void quad_type_7(ta_parameter_writer& writer,
|
||||||
|
const vec3& ap, const vec2& at,
|
||||||
|
const vec3& bp, const vec2& bt,
|
||||||
|
const vec3& cp, const vec2& ct,
|
||||||
|
const vec3& dp, const vec2& dt,
|
||||||
|
float intensity)
|
||||||
|
{
|
||||||
|
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,
|
||||||
|
intensity, 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,
|
||||||
|
intensity, 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,
|
||||||
|
intensity, 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,
|
||||||
|
intensity, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void quad_type_0(ta_parameter_writer& writer,
|
static inline void quad_type_0(ta_parameter_writer& writer,
|
||||||
@ -161,3 +229,29 @@ static inline void quad_type_0(ta_parameter_writer& writer,
|
|||||||
cp.x, cp.y, cp.z,
|
cp.x, cp.y, cp.z,
|
||||||
base_color);
|
base_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define _fsrra(n) (1.0f / (sqrt<float>(n)))
|
||||||
|
|
||||||
|
static inline void line_type_0(ta_parameter_writer& writer,
|
||||||
|
const vec3& p1,
|
||||||
|
const vec3& p2,
|
||||||
|
int base_color)
|
||||||
|
{
|
||||||
|
float dy = p2.y - p1.y;
|
||||||
|
float dx = p2.x - p1.x;
|
||||||
|
float d = _fsrra(dx * dx + dy * dy) * 0.7f;
|
||||||
|
float dy1 = dy * d;
|
||||||
|
float dx1 = dx * d;
|
||||||
|
|
||||||
|
vec3 ap = { p1.x + dy1, p1.y + -dx1, p1.z };
|
||||||
|
vec3 bp = { p1.x + -dy1, p1.y + dx1, p1.z };
|
||||||
|
vec3 cp = { p2.x + -dy1, p2.y + dx1, p2.z };
|
||||||
|
vec3 dp = { p2.x + dy1, p2.y + -dx1, p2.z };
|
||||||
|
|
||||||
|
quad_type_0(writer,
|
||||||
|
ap,
|
||||||
|
bp,
|
||||||
|
cp,
|
||||||
|
dp,
|
||||||
|
base_color);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user