example: add bloom
This commit is contained in:
parent
5c27b107f3
commit
a6a437faee
51
blender.py
51
blender.py
@ -66,6 +66,8 @@ 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")
|
||||
@ -77,11 +79,22 @@ def render_mesh(f, name, mesh):
|
||||
def translate_name(name):
|
||||
return name.replace(".", "_").replace("-", "_")
|
||||
|
||||
def export_scene(f):
|
||||
meshes = set()
|
||||
def mesh_objects(objects):
|
||||
for object in objects:
|
||||
if object.type == "MESH":
|
||||
yield object
|
||||
|
||||
for object in bpy.context.scene.objects:
|
||||
#mesh = c.to_mesh()
|
||||
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):
|
||||
#mesh.vertex_normals
|
||||
#mesh.vertex_colors
|
||||
#mesh.vertices
|
||||
@ -90,17 +103,12 @@ def export_scene(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)
|
||||
|
||||
@ -114,8 +122,14 @@ def export_scene(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 bpy.context.scene.objects:
|
||||
for object in mesh_objects_sorted(bpy.context.scene.objects):
|
||||
#object.rotation_mode = 'AXIS_ANGLE'
|
||||
#object.name
|
||||
#object.rotation_axis_angle
|
||||
@ -131,19 +145,20 @@ def export_scene(f):
|
||||
f.write(" ")
|
||||
f.write(f" .mesh = &{obj_mesh_name},\n")
|
||||
|
||||
location, rotation, scale = object.matrix_world.decompose()
|
||||
f.write(" ")
|
||||
render_scale(f, object.scale)
|
||||
render_scale(f, scale)
|
||||
f.write(" ")
|
||||
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
|
||||
render_rotation_quaternion(f, rotation)
|
||||
f.write(" ")
|
||||
render_location(f, object.location)
|
||||
render_location(f, 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
Normal file
1039
example/bloom.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -1250,6 +1250,7 @@ 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
|
||||
@ -1272,6 +1273,7 @@ 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
|
||||
@ -1296,6 +1298,7 @@ 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
|
||||
@ -1334,6 +1337,7 @@ 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
|
||||
@ -1374,6 +1378,7 @@ 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
|
||||
@ -2087,6 +2092,7 @@ 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);
|
||||
@ -2542,7 +2548,7 @@ int main()
|
||||
ta_polygon_converter_writeback(writer.buf, writer.offset);
|
||||
ta_polygon_converter_transfer(writer.buf, writer.offset);
|
||||
|
||||
while (next_frame)
|
||||
while (next_frame == 0);
|
||||
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)
|
||||
while (next_frame == 0);
|
||||
next_frame = 0;
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +82,8 @@ MACAW_MULTIPASS_OBJ = \
|
||||
holly/region_array.o \
|
||||
holly/background.o \
|
||||
holly/ta_fifo_polygon_converter.o \
|
||||
texture/macaw/macaw.data.o
|
||||
texture/macaw/macaw.data.o \
|
||||
sh7091/serial.o
|
||||
|
||||
example/macaw_multipass.elf: LDSCRIPT = $(LIB)/main.lds
|
||||
example/macaw_multipass.elf: $(START_OBJ) $(MACAW_MULTIPASS_OBJ)
|
||||
@ -1084,3 +1085,24 @@ 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)
|
||||
|
@ -215,11 +215,7 @@ 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,
|
||||
const float a = 1.0f,
|
||||
const float r = 1.0f,
|
||||
const float g = 1.0f,
|
||||
const float b = 1.0f
|
||||
uint32_t texture_control_word
|
||||
)
|
||||
{
|
||||
const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume
|
||||
|
74
gauss.cpp
Normal file
74
gauss.cpp
Normal file
@ -0,0 +1,74 @@
|
||||
#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 frame_width, // in pixels
|
||||
uint32_t dither)
|
||||
{
|
||||
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 = fb_w_ctrl::fb_dither | fb_w_ctrl::fb_packmode::_565_rgb_16bit;
|
||||
holly.FB_W_CTRL = 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,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "holly/core_bits.hpp"
|
||||
|
||||
void core_init();
|
||||
|
||||
void core_start_render(uint32_t frame_address,
|
||||
@ -11,7 +13,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 frame_width, // in pixels
|
||||
uint32_t dither = fb_w_ctrl::fb_dither
|
||||
);
|
||||
|
||||
void core_start_render3(uint32_t region_array_start,
|
||||
|
@ -97,14 +97,13 @@ inline constexpr mat<4, 4, T> rotate_quaternion(vec<4, T> r)
|
||||
T zw2 = 2 * r.z * r.w;
|
||||
|
||||
return {
|
||||
1 - yy2 - zz2, xy2 - zw2, xz2 + yw2, 0,
|
||||
xy2 + zw2, 1 - xx2 - zz2, yz2 - xw2, 0,
|
||||
xz2 - yw2, yz2 + xw2, 1 - xx2 - yy2, 0,
|
||||
0, 0, 0, 1,
|
||||
1 - yy2 - zz2, xy2 - zw2, xz2 + yw2, 0,
|
||||
xy2 + zw2, 1 - xx2 - zz2, yz2 - xw2, 0,
|
||||
xz2 - yw2, yz2 + xw2, 1 - xx2 - yy2, 0,
|
||||
0, 0, 0, 1,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
978
model/bloom_scene/container2.data
Normal file
978
model/bloom_scene/container2.data
Normal file
File diff suppressed because one or more lines are too long
15
model/bloom_scene/container2.data.h
Normal file
15
model/bloom_scene/container2.data.h
Normal file
@ -0,0 +1,15 @@
|
||||
#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
|
BIN
model/bloom_scene/container2.png
Normal file
BIN
model/bloom_scene/container2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 435 KiB |
11609
model/bloom_scene/scene.h
Normal file
11609
model/bloom_scene/scene.h
Normal file
File diff suppressed because it is too large
Load Diff
643
model/bloom_scene/wood.data
Normal file
643
model/bloom_scene/wood.data
Normal file
File diff suppressed because one or more lines are too long
15
model/bloom_scene/wood.data.h
Normal file
15
model/bloom_scene/wood.data.h
Normal file
@ -0,0 +1,15 @@
|
||||
#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
|
BIN
model/bloom_scene/wood.png
Normal file
BIN
model/bloom_scene/wood.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 MiB |
Loading…
x
Reference in New Issue
Block a user