scene: improve retexturing
parent
3858f73f3f
commit
d1cc36207f
|
@ -1422,7 +1422,7 @@ enum BILLBOARD_MODE {
|
|||
void model_render_instanced(model_t, mat44 proj, mat44 view, mat44 *models, int shader, unsigned count);
|
||||
void model_render_instanced_pass(model_t m, mat44 proj, mat44 view, mat44* models, int shader, unsigned count, int pass);
|
||||
void model_render_pass(model_t m, mat44 proj, mat44 view, mat44 model, int shader, int pass);
|
||||
void model_set_texture(model_t, texture_t t);
|
||||
void model_set_texture(model_t*, texture_t t);
|
||||
bool model_get_bone_pose(model_t m, unsigned joint, mat34 *out);
|
||||
void model_destroy(model_t);
|
||||
unsigned model_getpass();
|
||||
|
@ -1549,7 +1549,7 @@ typedef struct object_t {
|
|||
mat44 transform;
|
||||
quat rot;
|
||||
vec3 sca, pos, euler, pivot;
|
||||
handle* textures;
|
||||
texture_t* textures;
|
||||
model_t model;
|
||||
anim_t anim;
|
||||
float anim_speed;
|
||||
|
|
|
@ -185,7 +185,7 @@ object_pivot(obj3, vec3(0,90,0));
|
|||
// @todo: add shadertoy material
|
||||
static model_t cube; do_once cube = model("cube.obj", 0);
|
||||
static shadertoy_t s; do_once s = shadertoy("shadertoys/4ttGWM.fs", 256);
|
||||
model_set_texture(cube, shadertoy_render(&s, window_delta())->tx);
|
||||
model_set_texture(&cube, shadertoy_render(&s, window_delta())->tx);
|
||||
model_render(cube, cam.proj, cam.view, cube.pivot, 0);
|
||||
|
||||
while(window_swap() && !input(KEY_ESC)) {
|
||||
|
@ -203,7 +203,7 @@ while(window_swap() && !input(KEY_ESC)) {
|
|||
|
||||
// load static scene
|
||||
// model_t sponza = model("sponza.obj", MODEL_MATCAPS);
|
||||
// model_set_texture(sponza, texture("matcaps/normals", 0));
|
||||
// model_set_texture(&sponza, texture("matcaps/normals", 0));
|
||||
// translation44(sponza.pivot, 0,-1,0);
|
||||
// rotate44(sponza.pivot, -90,1,0,0);
|
||||
// scale44(sponza.pivot, 10,10,10);
|
||||
|
|
|
@ -20,7 +20,7 @@ int main() {
|
|||
|
||||
// config 3d model #1
|
||||
model_t witch = model("witch/witch.obj", 0);
|
||||
model_set_texture(witch, texture("witch/witch_diffuse.tga.png", 0));
|
||||
model_set_texture(&witch, texture("witch/witch_diffuse.tga.png", 0));
|
||||
mat44 witch_pivot; vec3 witch_p = {-5,0,-5}, witch_r={-180,180,0}, witch_s={0.1,-0.1,0.1};
|
||||
|
||||
// config 3d model #2
|
||||
|
|
|
@ -59,15 +59,15 @@ int main() {
|
|||
|
||||
if( flag("--matcaps") ) {
|
||||
// patch models to use matcaps
|
||||
model_set_texture(george, texture("matcaps/3B6E10_E3F2C3_88AC2E_99CE51-256px", 0)); // green
|
||||
model_set_texture(leela, texture("matcaps/39433A_65866E_86BF8B_BFF8D8-256px", 0));
|
||||
model_set_texture(mike, texture("matcaps/394641_B1A67E_75BEBE_7D7256-256px.png", 0));
|
||||
model_set_texture(stan, texture("matcaps/test_steel", 0));
|
||||
model_set_texture(girl, texture("matcaps/material3", 0));
|
||||
model_set_texture(alien, texture("matcaps/material3", 0));
|
||||
model_set_texture(&george, texture("matcaps/3B6E10_E3F2C3_88AC2E_99CE51-256px", 0)); // green
|
||||
model_set_texture(&leela, texture("matcaps/39433A_65866E_86BF8B_BFF8D8-256px", 0));
|
||||
model_set_texture(&mike, texture("matcaps/394641_B1A67E_75BEBE_7D7256-256px.png", 0));
|
||||
model_set_texture(&stan, texture("matcaps/test_steel", 0));
|
||||
model_set_texture(&girl, texture("matcaps/material3", 0));
|
||||
model_set_texture(&alien, texture("matcaps/material3", 0));
|
||||
|
||||
if( flag("--shaderball") )
|
||||
model_set_texture(shaderball, texture("matcaps/normals", 0));
|
||||
model_set_texture(&shaderball, texture("matcaps/normals", 0));
|
||||
}
|
||||
|
||||
// camera
|
||||
|
|
|
@ -39,7 +39,7 @@ int main()
|
|||
|
||||
unsigned char emissive[] = { 255, 180, 0, 255 };
|
||||
texture_t emission = texture_create(1,1,4,emissive,TEXTURE_LINEAR);
|
||||
model_set_texture(litm, emission);
|
||||
model_set_texture(&litm, emission);
|
||||
|
||||
lightmap_t baker = lightmap(64, 0.01, 100, vec3(0,0,0), 2, 0.01, 0.0);
|
||||
lightmap_setup(&baker, 512, 512);
|
||||
|
|
|
@ -17687,7 +17687,7 @@ API void model_render_skeleton(model_t, mat44 model);
|
|||
API void model_render_instanced(model_t, mat44 proj, mat44 view, mat44 *models, int shader, unsigned count);
|
||||
API void model_render_instanced_pass(model_t m, mat44 proj, mat44 view, mat44* models, int shader, unsigned count, int pass);
|
||||
API void model_render_pass(model_t m, mat44 proj, mat44 view, mat44 model, int shader, int pass);
|
||||
API void model_set_texture(model_t, texture_t t);
|
||||
API void model_set_texture(model_t*, texture_t t);
|
||||
API bool model_get_bone_pose(model_t m, unsigned joint, mat34 *out);
|
||||
API void model_destroy(model_t);
|
||||
|
||||
|
@ -17878,7 +17878,7 @@ typedef struct object_t {
|
|||
mat44 transform;
|
||||
quat rot;
|
||||
vec3 sca, pos, euler, pivot;
|
||||
array(handle) textures;
|
||||
array(texture_t) textures;
|
||||
model_t model;
|
||||
anim_t anim;
|
||||
float anim_speed;
|
||||
|
@ -384813,12 +384813,14 @@ typedef struct iqm_t {
|
|||
vec4 *colormaps;
|
||||
} iqm_t;
|
||||
|
||||
void model_set_texture(model_t m, texture_t t) {
|
||||
if(!m.iqm) return;
|
||||
iqm_t *q = m.iqm;
|
||||
void model_set_texture(model_t *m, texture_t t) {
|
||||
if(!m->iqm) return;
|
||||
iqm_t *q = m->iqm;
|
||||
|
||||
for( int i = 0; i < q->nummeshes; ++i) { // assume 1 texture per mesh
|
||||
q->textures[i] = t.id;
|
||||
if (m->materials[i].layer[MATERIAL_CHANNEL_DIFFUSE].map.texture)
|
||||
*m->materials[i].layer[MATERIAL_CHANNEL_DIFFUSE].map.texture = t;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -387792,7 +387794,7 @@ void object_anim(object_t *obj, anim_t anim, float speed) {
|
|||
}
|
||||
|
||||
void object_push_diffuse(object_t *obj, texture_t tex) {
|
||||
array_push(obj->textures, tex.id);
|
||||
array_push(obj->textures, tex);
|
||||
}
|
||||
|
||||
void object_pop_diffuse(object_t *obj) {
|
||||
|
@ -388047,13 +388049,18 @@ void scene_render(int flags) {
|
|||
mat44 *views = (mat44*)(&cam->view);
|
||||
|
||||
// @todo: avoid heap allocs here?
|
||||
static array(handle) old_textures = 0;
|
||||
static array(handle) old_texture_ids = 0;
|
||||
static array(texture_t) old_textures = 0;
|
||||
|
||||
int do_retexturing = model->iqm && array_count(obj->textures) > 0;
|
||||
int do_retexturing = model->iqm && model->shading != SHADING_PBR && array_count(obj->textures) > 0;
|
||||
if( do_retexturing ) {
|
||||
for(int i = 0; i < model->iqm->nummeshes; ++i) {
|
||||
array_push(old_textures, model->iqm->textures[i]);
|
||||
model->iqm->textures[i] = *array_back(obj->textures);
|
||||
array_push(old_texture_ids, model->iqm->textures[i]);
|
||||
model->iqm->textures[i] = (*array_back(obj->textures)).id;
|
||||
if (model->materials[i].layer[MATERIAL_CHANNEL_DIFFUSE].map.texture) {
|
||||
array_push(old_textures, *model->materials[i].layer[MATERIAL_CHANNEL_DIFFUSE].map.texture);
|
||||
*model->materials[i].layer[MATERIAL_CHANNEL_DIFFUSE].map.texture = (*array_back(obj->textures));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -388083,8 +388090,13 @@ void scene_render(int flags) {
|
|||
|
||||
if( do_retexturing ) {
|
||||
for(int i = 0; i < model->iqm->nummeshes; ++i) {
|
||||
model->iqm->textures[i] = old_textures[i];
|
||||
model->iqm->textures[i] = old_texture_ids[i];
|
||||
if (i < array_count(old_textures)) {
|
||||
if (model->materials[i].layer[MATERIAL_CHANNEL_DIFFUSE].map.texture)
|
||||
*model->materials[i].layer[MATERIAL_CHANNEL_DIFFUSE].map.texture = old_textures[i];
|
||||
}
|
||||
}
|
||||
array_resize(old_texture_ids, 0);
|
||||
array_resize(old_textures, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3173,12 +3173,14 @@ typedef struct iqm_t {
|
|||
vec4 *colormaps;
|
||||
} iqm_t;
|
||||
|
||||
void model_set_texture(model_t m, texture_t t) {
|
||||
if(!m.iqm) return;
|
||||
iqm_t *q = m.iqm;
|
||||
void model_set_texture(model_t *m, texture_t t) {
|
||||
if(!m->iqm) return;
|
||||
iqm_t *q = m->iqm;
|
||||
|
||||
for( int i = 0; i < q->nummeshes; ++i) { // assume 1 texture per mesh
|
||||
q->textures[i] = t.id;
|
||||
if (m->materials[i].layer[MATERIAL_CHANNEL_DIFFUSE].map.texture)
|
||||
*m->materials[i].layer[MATERIAL_CHANNEL_DIFFUSE].map.texture = t;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -719,7 +719,7 @@ API void model_render_skeleton(model_t, mat44 model);
|
|||
API void model_render_instanced(model_t, mat44 proj, mat44 view, mat44 *models, int shader, unsigned count);
|
||||
API void model_render_instanced_pass(model_t m, mat44 proj, mat44 view, mat44* models, int shader, unsigned count, int pass);
|
||||
API void model_render_pass(model_t m, mat44 proj, mat44 view, mat44 model, int shader, int pass);
|
||||
API void model_set_texture(model_t, texture_t t);
|
||||
API void model_set_texture(model_t*, texture_t t);
|
||||
API bool model_get_bone_pose(model_t m, unsigned joint, mat34 *out);
|
||||
API void model_destroy(model_t);
|
||||
|
||||
|
|
|
@ -279,7 +279,7 @@ void object_anim(object_t *obj, anim_t anim, float speed) {
|
|||
}
|
||||
|
||||
void object_push_diffuse(object_t *obj, texture_t tex) {
|
||||
array_push(obj->textures, tex.id);
|
||||
array_push(obj->textures, tex);
|
||||
}
|
||||
|
||||
void object_pop_diffuse(object_t *obj) {
|
||||
|
@ -534,13 +534,18 @@ void scene_render(int flags) {
|
|||
mat44 *views = (mat44*)(&cam->view);
|
||||
|
||||
// @todo: avoid heap allocs here?
|
||||
static array(handle) old_textures = 0;
|
||||
static array(handle) old_texture_ids = 0;
|
||||
static array(texture_t) old_textures = 0;
|
||||
|
||||
int do_retexturing = model->iqm && array_count(obj->textures) > 0;
|
||||
int do_retexturing = model->iqm && model->shading != SHADING_PBR && array_count(obj->textures) > 0;
|
||||
if( do_retexturing ) {
|
||||
for(int i = 0; i < model->iqm->nummeshes; ++i) {
|
||||
array_push(old_textures, model->iqm->textures[i]);
|
||||
model->iqm->textures[i] = *array_back(obj->textures);
|
||||
array_push(old_texture_ids, model->iqm->textures[i]);
|
||||
model->iqm->textures[i] = (*array_back(obj->textures)).id;
|
||||
if (model->materials[i].layer[MATERIAL_CHANNEL_DIFFUSE].map.texture) {
|
||||
array_push(old_textures, *model->materials[i].layer[MATERIAL_CHANNEL_DIFFUSE].map.texture);
|
||||
*model->materials[i].layer[MATERIAL_CHANNEL_DIFFUSE].map.texture = (*array_back(obj->textures));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -570,8 +575,13 @@ void scene_render(int flags) {
|
|||
|
||||
if( do_retexturing ) {
|
||||
for(int i = 0; i < model->iqm->nummeshes; ++i) {
|
||||
model->iqm->textures[i] = old_textures[i];
|
||||
model->iqm->textures[i] = old_texture_ids[i];
|
||||
if (i < array_count(old_textures)) {
|
||||
if (model->materials[i].layer[MATERIAL_CHANNEL_DIFFUSE].map.texture)
|
||||
*model->materials[i].layer[MATERIAL_CHANNEL_DIFFUSE].map.texture = old_textures[i];
|
||||
}
|
||||
}
|
||||
array_resize(old_texture_ids, 0);
|
||||
array_resize(old_textures, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ typedef struct object_t {
|
|||
mat44 transform;
|
||||
quat rot;
|
||||
vec3 sca, pos, euler, pivot;
|
||||
array(handle) textures;
|
||||
array(texture_t) textures;
|
||||
model_t model;
|
||||
anim_t anim;
|
||||
float anim_speed;
|
||||
|
|
30
engine/v4k.c
30
engine/v4k.c
|
@ -19972,12 +19972,14 @@ typedef struct iqm_t {
|
|||
vec4 *colormaps;
|
||||
} iqm_t;
|
||||
|
||||
void model_set_texture(model_t m, texture_t t) {
|
||||
if(!m.iqm) return;
|
||||
iqm_t *q = m.iqm;
|
||||
void model_set_texture(model_t *m, texture_t t) {
|
||||
if(!m->iqm) return;
|
||||
iqm_t *q = m->iqm;
|
||||
|
||||
for( int i = 0; i < q->nummeshes; ++i) { // assume 1 texture per mesh
|
||||
q->textures[i] = t.id;
|
||||
if (m->materials[i].layer[MATERIAL_CHANNEL_DIFFUSE].map.texture)
|
||||
*m->materials[i].layer[MATERIAL_CHANNEL_DIFFUSE].map.texture = t;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22951,7 +22953,7 @@ void object_anim(object_t *obj, anim_t anim, float speed) {
|
|||
}
|
||||
|
||||
void object_push_diffuse(object_t *obj, texture_t tex) {
|
||||
array_push(obj->textures, tex.id);
|
||||
array_push(obj->textures, tex);
|
||||
}
|
||||
|
||||
void object_pop_diffuse(object_t *obj) {
|
||||
|
@ -23206,13 +23208,18 @@ void scene_render(int flags) {
|
|||
mat44 *views = (mat44*)(&cam->view);
|
||||
|
||||
// @todo: avoid heap allocs here?
|
||||
static array(handle) old_textures = 0;
|
||||
static array(handle) old_texture_ids = 0;
|
||||
static array(texture_t) old_textures = 0;
|
||||
|
||||
int do_retexturing = model->iqm && array_count(obj->textures) > 0;
|
||||
int do_retexturing = model->iqm && model->shading != SHADING_PBR && array_count(obj->textures) > 0;
|
||||
if( do_retexturing ) {
|
||||
for(int i = 0; i < model->iqm->nummeshes; ++i) {
|
||||
array_push(old_textures, model->iqm->textures[i]);
|
||||
model->iqm->textures[i] = *array_back(obj->textures);
|
||||
array_push(old_texture_ids, model->iqm->textures[i]);
|
||||
model->iqm->textures[i] = (*array_back(obj->textures)).id;
|
||||
if (model->materials[i].layer[MATERIAL_CHANNEL_DIFFUSE].map.texture) {
|
||||
array_push(old_textures, *model->materials[i].layer[MATERIAL_CHANNEL_DIFFUSE].map.texture);
|
||||
*model->materials[i].layer[MATERIAL_CHANNEL_DIFFUSE].map.texture = (*array_back(obj->textures));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23242,8 +23249,13 @@ void scene_render(int flags) {
|
|||
|
||||
if( do_retexturing ) {
|
||||
for(int i = 0; i < model->iqm->nummeshes; ++i) {
|
||||
model->iqm->textures[i] = old_textures[i];
|
||||
model->iqm->textures[i] = old_texture_ids[i];
|
||||
if (i < array_count(old_textures)) {
|
||||
if (model->materials[i].layer[MATERIAL_CHANNEL_DIFFUSE].map.texture)
|
||||
*model->materials[i].layer[MATERIAL_CHANNEL_DIFFUSE].map.texture = old_textures[i];
|
||||
}
|
||||
}
|
||||
array_resize(old_texture_ids, 0);
|
||||
array_resize(old_textures, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3754,7 +3754,7 @@ API void model_render_skeleton(model_t, mat44 model);
|
|||
API void model_render_instanced(model_t, mat44 proj, mat44 view, mat44 *models, int shader, unsigned count);
|
||||
API void model_render_instanced_pass(model_t m, mat44 proj, mat44 view, mat44* models, int shader, unsigned count, int pass);
|
||||
API void model_render_pass(model_t m, mat44 proj, mat44 view, mat44 model, int shader, int pass);
|
||||
API void model_set_texture(model_t, texture_t t);
|
||||
API void model_set_texture(model_t*, texture_t t);
|
||||
API bool model_get_bone_pose(model_t m, unsigned joint, mat34 *out);
|
||||
API void model_destroy(model_t);
|
||||
|
||||
|
@ -3945,7 +3945,7 @@ typedef struct object_t {
|
|||
mat44 transform;
|
||||
quat rot;
|
||||
vec3 sca, pos, euler, pivot;
|
||||
array(handle) textures;
|
||||
array(texture_t) textures;
|
||||
model_t model;
|
||||
anim_t anim;
|
||||
float anim_speed;
|
||||
|
|
Loading…
Reference in New Issue