Compare commits
No commits in common. "a6a437faee7fad37a427216fc67b8b82548f4758" and "ab5110875174a5ad0cea0fcb2a67e7fcd369b1dd" have entirely different histories.
a6a437faee
...
ab51108751
51
blender.py
51
blender.py
@ -66,8 +66,6 @@ def render_mesh(f, name, mesh):
|
||||
f.write(f"const mesh {name} = {{\n")
|
||||
f.write(f" .position = {name}_position,\n")
|
||||
f.write(f" .position_length = (sizeof ({name}_position)) / (sizeof ({name}_position[0])),\n")
|
||||
f.write(f" .normal = {name}_normal,\n")
|
||||
f.write(f" .normal_length = (sizeof ({name}_normal)) / (sizeof ({name}_normal[0])),\n")
|
||||
f.write(f" .polygon_normal = {name}_polygon_normal,\n")
|
||||
f.write(f" .polygon_normal_length = (sizeof ({name}_polygon_normal)) / (sizeof ({name}_polygon_normal[0])),\n")
|
||||
f.write(f" .polygons = {name}_polygons,\n")
|
||||
@ -79,22 +77,11 @@ def render_mesh(f, name, mesh):
|
||||
def translate_name(name):
|
||||
return name.replace(".", "_").replace("-", "_")
|
||||
|
||||
def mesh_objects(objects):
|
||||
for object in objects:
|
||||
if object.type == "MESH":
|
||||
yield object
|
||||
def export_scene(f):
|
||||
meshes = set()
|
||||
|
||||
def mesh_meshes(objects):
|
||||
mesh_names = set()
|
||||
for object in mesh_objects(objects):
|
||||
mesh = object.data
|
||||
if mesh.name in mesh_names:
|
||||
continue
|
||||
mesh_names.add(mesh.name)
|
||||
yield mesh
|
||||
|
||||
def export_meshes(f):
|
||||
for mesh in mesh_meshes(bpy.context.scene.objects):
|
||||
for object in bpy.context.scene.objects:
|
||||
#mesh = c.to_mesh()
|
||||
#mesh.vertex_normals
|
||||
#mesh.vertex_colors
|
||||
#mesh.vertices
|
||||
@ -103,12 +90,17 @@ def export_meshes(f):
|
||||
#mesh.polygon_normals
|
||||
#mesh.name
|
||||
|
||||
mesh = object.to_mesh()
|
||||
if mesh.name in meshes:
|
||||
continue
|
||||
meshes.add(mesh.name)
|
||||
|
||||
mesh_name = "mesh_" + translate_name(mesh.name)
|
||||
|
||||
render_mesh_vertices(f, mesh_name, mesh.vertices)
|
||||
for layer_name, layer in mesh.uv_layers.items():
|
||||
render_uv_map(f, mesh_name, layer_name, layer.uv)
|
||||
render_vertex_normals(f, mesh_name, mesh.vertices)
|
||||
#render_vertex_normals(f, mesh_name, mesh.vertices)
|
||||
render_polygon_normals(f, mesh_name, mesh.polygon_normals)
|
||||
render_polygons(f, mesh_name, mesh.polygons)
|
||||
|
||||
@ -122,14 +114,8 @@ def export_meshes(f):
|
||||
# v.normal
|
||||
# v.index
|
||||
|
||||
def mesh_objects_sorted(objects):
|
||||
def key(o):
|
||||
return (o.data.name, o.name)
|
||||
return sorted(mesh_objects(objects), key=key)
|
||||
|
||||
def export_objects(f):
|
||||
f.write("const struct object objects[] = {\n")
|
||||
for object in mesh_objects_sorted(bpy.context.scene.objects):
|
||||
for object in bpy.context.scene.objects:
|
||||
#object.rotation_mode = 'AXIS_ANGLE'
|
||||
#object.name
|
||||
#object.rotation_axis_angle
|
||||
@ -145,20 +131,19 @@ def export_objects(f):
|
||||
f.write(" ")
|
||||
f.write(f" .mesh = &{obj_mesh_name},\n")
|
||||
|
||||
location, rotation, scale = object.matrix_world.decompose()
|
||||
f.write(" ")
|
||||
render_scale(f, scale)
|
||||
render_scale(f, object.scale)
|
||||
f.write(" ")
|
||||
render_rotation_quaternion(f, rotation)
|
||||
old_mode = object.rotation_mode
|
||||
object.rotation_mode = 'QUATERNION'
|
||||
#render_rotation_axis_angle(f, object.rotation_axis_angle)
|
||||
render_rotation_quaternion(f, object.rotation_quaternion)
|
||||
object.rotation_mode = old_mode
|
||||
f.write(" ")
|
||||
render_location(f, location)
|
||||
render_location(f, object.location)
|
||||
|
||||
f.write(" },\n")
|
||||
f.write("};\n\n")
|
||||
|
||||
def export_scene(f):
|
||||
export_meshes(f)
|
||||
export_objects(f)
|
||||
|
||||
with open("/home/bilbo/output.h", "w") as f:
|
||||
export_scene(f)
|
||||
|
1039
example/bloom.cpp
1039
example/bloom.cpp
File diff suppressed because it is too large
Load Diff
@ -1250,7 +1250,6 @@ void render_matrix(ta_parameter_writer& writer, const mat4x4& trans)
|
||||
offset += format_float(&s[offset], trans[row][3], 7);
|
||||
|
||||
font_bitmap::transform_string(writer,
|
||||
texture_memory_alloc.texture.start,
|
||||
8, 16, // texture
|
||||
8, 16, // glyph
|
||||
16 + 2 * 8, // position x
|
||||
@ -1273,7 +1272,6 @@ void render_sphere_position(ta_parameter_writer& writer)
|
||||
offset += format_float(&s[offset], sphere_position[2], 7);
|
||||
|
||||
font_bitmap::transform_string(writer,
|
||||
texture_memory_alloc.texture.start,
|
||||
8, 16, // texture
|
||||
8, 16, // glyph
|
||||
16 + 2 * 8, // position x
|
||||
@ -1298,7 +1296,6 @@ void render_zero_position(ta_parameter_writer& writer, const mat4x4& screen_tran
|
||||
offset += format_float(&s[offset], pos[2], 7);
|
||||
|
||||
font_bitmap::transform_string(writer,
|
||||
texture_memory_alloc.texture.start,
|
||||
8, 16, // texture
|
||||
8, 16, // glyph
|
||||
16 + 2 * 8, // position x
|
||||
@ -1337,7 +1334,6 @@ void render_ix(ta_parameter_writer& writer, int row, char * s, int ix)
|
||||
}
|
||||
|
||||
font_bitmap::transform_string(writer,
|
||||
texture_memory_alloc.texture.start,
|
||||
8, 16, // texture
|
||||
8, 16, // glyph
|
||||
16 + 50 * 8, // position x
|
||||
@ -1378,7 +1374,6 @@ void render_num(ta_parameter_writer& writer, int row, char * s, int num, int off
|
||||
offset += unparse_base10_unsigned(&s[offset], num, 5, ' ');
|
||||
|
||||
font_bitmap::transform_string(writer,
|
||||
texture_memory_alloc.texture.start,
|
||||
8, 16, // texture
|
||||
8, 16, // glyph
|
||||
16 + 50 * 8, // position x
|
||||
@ -2092,7 +2087,6 @@ void transfer_font()
|
||||
uint32_t offset = font_bitmap::inflate(1, // pitch
|
||||
8, // width
|
||||
16, // height
|
||||
texture_memory_alloc.texture.start,
|
||||
8, // texture_width
|
||||
16, // texture_height
|
||||
src);
|
||||
@ -2548,7 +2542,7 @@ int main()
|
||||
ta_polygon_converter_writeback(writer.buf, writer.offset);
|
||||
ta_polygon_converter_transfer(writer.buf, writer.offset);
|
||||
|
||||
while (next_frame == 0);
|
||||
while (next_frame)
|
||||
next_frame = 0;
|
||||
}
|
||||
}
|
||||
|
@ -647,7 +647,7 @@ int main()
|
||||
ta_polygon_converter_writeback(writer.buf, writer.offset);
|
||||
ta_polygon_converter_transfer(writer.buf, writer.offset);
|
||||
|
||||
while (next_frame == 0);
|
||||
while (next_frame)
|
||||
next_frame = 0;
|
||||
}
|
||||
}
|
||||
|
@ -82,8 +82,7 @@ MACAW_MULTIPASS_OBJ = \
|
||||
holly/region_array.o \
|
||||
holly/background.o \
|
||||
holly/ta_fifo_polygon_converter.o \
|
||||
texture/macaw/macaw.data.o \
|
||||
sh7091/serial.o
|
||||
texture/macaw/macaw.data.o
|
||||
|
||||
example/macaw_multipass.elf: LDSCRIPT = $(LIB)/main.lds
|
||||
example/macaw_multipass.elf: $(START_OBJ) $(MACAW_MULTIPASS_OBJ)
|
||||
@ -1085,24 +1084,3 @@ MD5_OBJ = \
|
||||
|
||||
example/md5.elf: LDSCRIPT = $(LIB)/main.lds
|
||||
example/md5.elf: $(START_OBJ) $(MD5_OBJ)
|
||||
|
||||
BLOOM_OBJ = \
|
||||
example/bloom.o \
|
||||
holly/core.o \
|
||||
holly/region_array.o \
|
||||
holly/background.o \
|
||||
holly/ta_fifo_polygon_converter.o \
|
||||
holly/video_output.o \
|
||||
sh7091/serial.o \
|
||||
maple/maple.o \
|
||||
sh7091/c_serial.o \
|
||||
printf/printf.o \
|
||||
printf/unparse.o \
|
||||
printf/parse.o \
|
||||
gauss.o \
|
||||
model/bloom_scene/wood.data.o \
|
||||
model/bloom_scene/container2.data.o \
|
||||
$(LIBGCC)
|
||||
|
||||
example/bloom.elf: LDSCRIPT = $(LIB)/main.lds
|
||||
example/bloom.elf: $(START_OBJ) $(BLOOM_OBJ)
|
||||
|
@ -40,11 +40,13 @@ constexpr uint32_t strip_length = (sizeof (strip_vertices)) / (sizeof (struct ve
|
||||
static float theta = 0;
|
||||
constexpr float half_degree = 0.01745329f / 2.f;
|
||||
|
||||
void transform(ta_parameter_writer& writer,
|
||||
uint32_t transform(uint32_t * ta_parameter_buf,
|
||||
const vertex * strip_vertices,
|
||||
const uint32_t strip_length,
|
||||
const uint32_t render_pass)
|
||||
{
|
||||
auto parameter = ta_parameter_writer(ta_parameter_buf);
|
||||
|
||||
const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::greater
|
||||
| isp_tsp_instruction_word::culling_mode::no_culling;
|
||||
|
||||
@ -66,7 +68,7 @@ void transform(ta_parameter_writer& writer,
|
||||
| texture_control_word::scan_order::non_twiddled
|
||||
| texture_control_word::texture_address(texture_address / 8);
|
||||
|
||||
writer.append<ta_global_parameter::polygon_type_0>() =
|
||||
parameter.append<ta_global_parameter::polygon_type_0>() =
|
||||
ta_global_parameter::polygon_type_0(parameter_control_word,
|
||||
isp_tsp_instruction_word,
|
||||
tsp_instruction_word,
|
||||
@ -88,7 +90,7 @@ void transform(ta_parameter_writer& writer,
|
||||
|
||||
const uint32_t texture_control_word = 0;
|
||||
|
||||
writer.append<ta_global_parameter::polygon_type_0>() =
|
||||
parameter.append<ta_global_parameter::polygon_type_0>() =
|
||||
ta_global_parameter::polygon_type_0(parameter_control_word,
|
||||
isp_tsp_instruction_word,
|
||||
tsp_instruction_word,
|
||||
@ -115,7 +117,7 @@ void transform(ta_parameter_writer& writer,
|
||||
y += 240.f;
|
||||
z = 1.f / (z + 10.f);
|
||||
|
||||
writer.append<ta_vertex_parameter::polygon_type_3>() =
|
||||
parameter.append<ta_vertex_parameter::polygon_type_3>() =
|
||||
ta_vertex_parameter::polygon_type_3(polygon_vertex_parameter_control_word(end_of_strip),
|
||||
x, y, z,
|
||||
strip_vertices[i].u,
|
||||
@ -125,7 +127,9 @@ void transform(ta_parameter_writer& writer,
|
||||
);
|
||||
}
|
||||
|
||||
writer.append<ta_global_parameter::end_of_list>() = ta_global_parameter::end_of_list(para_control::para_type::end_of_list);
|
||||
parameter.append<ta_global_parameter::end_of_list>() = ta_global_parameter::end_of_list(para_control::para_type::end_of_list);
|
||||
|
||||
return parameter.offset;
|
||||
}
|
||||
|
||||
void init_texture_memory(const struct opb_size * opb_size, uint32_t render_passes)
|
||||
@ -140,7 +144,7 @@ void init_texture_memory(const struct opb_size * opb_size, uint32_t render_passe
|
||||
background_parameter(0xff00ff00);
|
||||
}
|
||||
|
||||
uint32_t ta_parameter_buf[((32 * (strip_length + 2)) + 32) / 4] __attribute__((aligned(32)));
|
||||
uint32_t _ta_parameter_buf[((32 * (strip_length + 2)) + 32) / 4];
|
||||
|
||||
void copy_macaw_texture()
|
||||
{
|
||||
@ -162,6 +166,10 @@ void main()
|
||||
video_output::set_mode_vga();
|
||||
copy_macaw_texture();
|
||||
|
||||
// The address of `ta_parameter_buf` must be a multiple of 32 bytes.
|
||||
// This is mandatory for ch2-dma to the ta fifo polygon converter.
|
||||
uint32_t * ta_parameter_buf = align_32byte(_ta_parameter_buf);
|
||||
|
||||
constexpr uint32_t ta_alloc[2] =
|
||||
{ ta_alloc_ctrl::pt_opb::no_list
|
||||
| ta_alloc_ctrl::tm_opb::no_list
|
||||
@ -202,8 +210,7 @@ void main()
|
||||
constexpr uint32_t tiles = (640 / 32) * (480 / 32);
|
||||
|
||||
uint32_t frame_ix = 0;
|
||||
|
||||
ta_parameter_writer writer = ta_parameter_writer(ta_parameter_buf, (sizeof (ta_parameter_buf)));
|
||||
uint32_t ta_parameter_size;
|
||||
|
||||
while (true) {
|
||||
// first render pass
|
||||
@ -211,19 +218,15 @@ void main()
|
||||
ta_alloc[0],
|
||||
640 / 32,
|
||||
480 / 32);
|
||||
writer.offset = 0;
|
||||
transform(writer, strip_vertices, strip_length, 0);
|
||||
ta_polygon_converter_writeback(writer.buf, writer.offset);
|
||||
ta_polygon_converter_transfer(writer.buf, writer.offset);
|
||||
ta_parameter_size = transform(ta_parameter_buf, strip_vertices, strip_length, 0);
|
||||
ta_polygon_converter_transfer(ta_parameter_buf, ta_parameter_size);
|
||||
ta_wait_opaque_list();
|
||||
|
||||
// second render pass
|
||||
ta_polygon_converter_cont(opb_size[0].total() * tiles,
|
||||
ta_alloc[1]);
|
||||
writer.offset = 0;
|
||||
transform(writer, strip_vertices, strip_length, 1);
|
||||
ta_polygon_converter_writeback(writer.buf, writer.offset);
|
||||
ta_polygon_converter_transfer(writer.buf, writer.offset);
|
||||
ta_parameter_size = transform(ta_parameter_buf, strip_vertices, strip_length, 1);
|
||||
ta_polygon_converter_transfer(ta_parameter_buf, ta_parameter_size);
|
||||
ta_wait_translucent_list();
|
||||
|
||||
core_start_render(frame_ix);
|
||||
|
@ -215,7 +215,11 @@ void vbr600()
|
||||
void global_polygon_type_0(ta_parameter_writer& writer,
|
||||
uint32_t para_control_obj_control,
|
||||
uint32_t tsp_instruction_word,
|
||||
uint32_t texture_control_word
|
||||
uint32_t texture_control_word,
|
||||
const float a = 1.0f,
|
||||
const float r = 1.0f,
|
||||
const float g = 1.0f,
|
||||
const float b = 1.0f
|
||||
)
|
||||
{
|
||||
const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume
|
||||
|
74
gauss.cpp
74
gauss.cpp
@ -1,74 +0,0 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "math/vec3.hpp"
|
||||
|
||||
using vec3 = vec<3, float>;
|
||||
|
||||
constexpr int dim = 5;
|
||||
constexpr int dim2 = dim / 2;
|
||||
constexpr int width = 128;
|
||||
constexpr int height = 96;
|
||||
|
||||
constexpr float mat[dim][dim] = {
|
||||
{0.014218, 0.027920, 0.034963, 0.027920, 0.014218},
|
||||
{0.027920, 0.054827, 0.068657, 0.054827, 0.027920},
|
||||
{0.034963, 0.068657, 0.085976, 0.068657, 0.034963},
|
||||
{0.027920, 0.054827, 0.068657, 0.054827, 0.027920},
|
||||
{0.014218, 0.027920, 0.034963, 0.027920, 0.014218},
|
||||
};
|
||||
|
||||
inline constexpr int clamp(int v, int max)
|
||||
{
|
||||
if (v > max)
|
||||
return max;
|
||||
if (v < 0)
|
||||
return 0;
|
||||
return v;
|
||||
}
|
||||
|
||||
inline constexpr vec3 gauss_pixel(vec3 const * const src, const int cx, const int cy)
|
||||
{
|
||||
vec3 acc = {0, 0, 0};
|
||||
|
||||
for (int dy = 0; dy < dim; dy++) {
|
||||
for (int dx = 0; dx < dim; dx++) {
|
||||
float i = mat[dy][dx];
|
||||
|
||||
int x = clamp((dx - dim2) + cx, width - 1);
|
||||
int y = clamp((dy - dim2) + cy, height - 1);
|
||||
int ix = y * width + x;
|
||||
|
||||
acc = acc + (src[ix] * i);
|
||||
}
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
|
||||
inline constexpr void gauss(vec3 const * const src, uint16_t * const dst)
|
||||
{
|
||||
for (int cy = 0; cy < height; cy++) {
|
||||
for (int cx = 0; cx < width; cx++) {
|
||||
vec3 v = gauss_pixel(src, cx, cy);
|
||||
int r = clamp(v.x, 31);
|
||||
int g = clamp(v.y, 63);
|
||||
int b = clamp(v.z, 31);
|
||||
uint16_t px = (r << 11) | (g << 5) | (b << 0);
|
||||
dst[cy * width + cx] = px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void gauss_rgb565(uint16_t const * const src, uint16_t * const dst)
|
||||
{
|
||||
static vec3 tmp[width * height];
|
||||
|
||||
for (int i = 0; i < width * height; i++) {
|
||||
uint16_t px = src[i];
|
||||
float r = (px >> 11) & 0b11111;
|
||||
float g = (px >> 5) & 0b111111;
|
||||
float b = (px >> 0) & 0b11111;
|
||||
tmp[i] = {r, g, b};
|
||||
}
|
||||
|
||||
gauss(tmp, dst);
|
||||
}
|
@ -89,8 +89,8 @@ void core_start_render2(uint32_t region_array_start,
|
||||
uint32_t isp_tsp_parameters_start,
|
||||
uint32_t background_start,
|
||||
uint32_t frame_address,
|
||||
uint32_t frame_width, // in pixels
|
||||
uint32_t dither)
|
||||
uint32_t frame_width // in pixels
|
||||
)
|
||||
{
|
||||
holly.REGION_BASE = region_array_start;
|
||||
holly.PARAM_BASE = isp_tsp_parameters_start;
|
||||
@ -101,7 +101,7 @@ void core_start_render2(uint32_t region_array_start,
|
||||
| isp_backgnd_t::skip(1);
|
||||
holly.ISP_BACKGND_D = _i(1.f/100000.f);
|
||||
|
||||
holly.FB_W_CTRL = dither | fb_w_ctrl::fb_packmode::_565_rgb_16bit;
|
||||
holly.FB_W_CTRL = fb_w_ctrl::fb_dither | fb_w_ctrl::fb_packmode::_565_rgb_16bit;
|
||||
constexpr uint32_t bytes_per_pixel = 2;
|
||||
holly.FB_W_LINESTRIDE = (frame_width * bytes_per_pixel) / 8;
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "holly/core_bits.hpp"
|
||||
|
||||
void core_init();
|
||||
|
||||
void core_start_render(uint32_t frame_address,
|
||||
@ -13,8 +11,7 @@ void core_start_render2(uint32_t region_array_start,
|
||||
uint32_t isp_tsp_parameters_start,
|
||||
uint32_t background_start,
|
||||
uint32_t frame_address,
|
||||
uint32_t frame_width, // in pixels
|
||||
uint32_t dither = fb_w_ctrl::fb_dither
|
||||
uint32_t frame_width // in pixels
|
||||
);
|
||||
|
||||
void core_start_render3(uint32_t region_array_start,
|
||||
|
@ -104,6 +104,7 @@ inline constexpr mat<4, 4, T> rotate_quaternion(vec<4, T> r)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
inline constexpr vec<3, T> normal_multiply(mat<4, 4, T> m, vec<3, T> n)
|
||||
{
|
||||
|
@ -5,8 +5,8 @@ struct polygon {
|
||||
struct mesh {
|
||||
const vec3 * position;
|
||||
const int position_length;
|
||||
const vec3 * normal;
|
||||
const int normal_length;
|
||||
//const vec3 * normal;
|
||||
//const int normal_length;
|
||||
const vec3 * polygon_normal;
|
||||
const int polygon_normal_length;
|
||||
const polygon * polygons;
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,15 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern uint32_t _binary_model_bloom_scene_container2_data_start __asm("_binary_model_bloom_scene_container2_data_start");
|
||||
extern uint32_t _binary_model_bloom_scene_container2_data_end __asm("_binary_model_bloom_scene_container2_data_end");
|
||||
extern uint32_t _binary_model_bloom_scene_container2_data_size __asm("_binary_model_bloom_scene_container2_data_size");
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
Binary file not shown.
Before Width: | Height: | Size: 435 KiB |
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@ -1,15 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern uint32_t _binary_model_bloom_scene_wood_data_start __asm("_binary_model_bloom_scene_wood_data_start");
|
||||
extern uint32_t _binary_model_bloom_scene_wood_data_end __asm("_binary_model_bloom_scene_wood_data_end");
|
||||
extern uint32_t _binary_model_bloom_scene_wood_data_size __asm("_binary_model_bloom_scene_wood_data_size");
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
Binary file not shown.
Before Width: | Height: | Size: 1.6 MiB |
Loading…
x
Reference in New Issue
Block a user