diff --git a/MAKE.bat b/MAKE.bat index 6e259f9..7bb6ac7 100644 --- a/MAKE.bat +++ b/MAKE.bat @@ -344,7 +344,7 @@ if "%1"=="gwk" ( copy/y ..\fwk-mirror\engine\fwk _fwk\engine\fwk copy/y ..\fwk-mirror\engine\split\*.inl _fwk\engine\split\ rem copy/y ..\fwk-mirror\engine\split\3rd_*.c _fwk\engine\split\ - make back + call MAKE.bat back exit /b ) diff --git a/engine/joint/v4k.h b/engine/joint/v4k.h index 8d0dae8..6aae981 100644 --- a/engine/joint/v4k.h +++ b/engine/joint/v4k.h @@ -367390,11 +367390,18 @@ texture_t texture_checker() { pixels[i++] = (rgb>>8) & 255; pixels[i++] = (rgb>>0) & 255; pixels[i++] = 255; -#else +#elif 0 extern const uint32_t secret_palette[32]; uint32_t lum = (x^y) & 8 ? 128 : (x^y) & 128 ? 192 : 255; uint32_t rgb = rgba(lum,lum,lum,255); pixels[i++] = rgb; +#else + int j = y, i = x; + unsigned char *p = (unsigned char *)&pixels[x + y * 256]; + p[0] = (i / 16) % 2 == (j / 16) % 2 ? 255 : 0; // r + p[1] = ((i - j) / 16) % 2 == 0 ? 255 : 0; // g + p[2] = ((i + j) / 16) % 2 == 0 ? 255 : 0; // b + p[3] = 255; // a #endif } } @@ -369547,6 +369554,10 @@ void model_set_state(model_t m) { glVertexAttribPointer(11, 4, GL_UNSIGNED_BYTE, GL_FALSE, sizeof(iqm_vertex), (GLvoid*)offsetof(iqm_vertex,color) ); glEnableVertexAttribArray(11); + // lmap data + glVertexAttribPointer(12, 2, GL_FLOAT, GL_FALSE, sizeof(iqm_vertex), (GLvoid*)offsetof(iqm_vertex, texcoord2) ); + glEnableVertexAttribArray(12); + // animation if(numframes > 0) { glVertexAttribPointer( 8, 4, GL_UNSIGNED_BYTE, GL_FALSE, sizeof(iqm_vertex), (GLvoid*)offsetof(iqm_vertex,blendindexes) ); @@ -369582,10 +369593,6 @@ void model_set_state(model_t m) { glVertexAttribDivisor(7, 1); } - // lmap data - glVertexAttribPointer(12, 2, GL_FLOAT, GL_FALSE, sizeof(iqm_vertex), (GLvoid*)offsetof(iqm_vertex, texcoord2) ); - glEnableVertexAttribArray(12); - // 7 bitangent? into texcoord.z? glBindVertexArray( 0 ); @@ -369941,7 +369948,7 @@ model_t model_from_mem(const void *mem, int len, int flags) { // if( shaderprog < 0 ) { const char *symbols[] = { "{{include-shadowmap}}", vfs_read("shaders/fs_0_0_shadowmap_lit.glsl") }; // #define RIM int shaderprog = shader(strlerp(1,symbols,vfs_read("shaders/vs_323444143_16_3322_model.glsl")), strlerp(1,symbols,vfs_read("shaders/fs_32_4_model.glsl")), //fs, - "att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_bitangent,att_texcoord2","fragColor", + "att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_texcoord2,att_bitangent","fragColor", va("SHADING_PHONG,%s", (flags&MODEL_RIMLIGHT)?"RIM":"")); // } // ASSERT(shaderprog > 0); @@ -370350,7 +370357,7 @@ lightmap_t lightmap(int hmsize, float cnear, float cfar, vec3 color, int passes, const char *symbols[] = { "{{include-shadowmap}}", vfs_read("shaders/fs_0_0_shadowmap_lit.glsl") }; // #define RIM lm.shader = shader(strlerp(1,symbols,vfs_read("shaders/vs_323444143_16_3322_model.glsl")), strlerp(1,symbols,vfs_read("shaders/fs_32_4_model.glsl")), //fs, - "att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_bitangent,att_texcoord2","fragColor", + "att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_texcoord2,att_bitangent","fragColor", va("%s", "LIGHTMAP_BAKING")); return lm; @@ -370399,7 +370406,7 @@ void lightmap_bake(lightmap_t *lm, int bounces, void (*drawscene)(lightmap_t *lm LM_FLOAT, (uint8_t*)m->verts + offsetof(iqm_vertex, normal), sizeof(iqm_vertex), LM_FLOAT, (uint8_t*)m->verts + offsetof(iqm_vertex, texcoord), sizeof(iqm_vertex), m->num_tris*3, LM_UNSIGNED_INT, m->tris); - + glDisable(GL_BLEND); int vp[4]; float view[16], projection[16]; @@ -370412,7 +370419,7 @@ void lightmap_bake(lightmap_t *lm, int bounces, void (*drawscene)(lightmap_t *lm lmEnd(lm->ctx); } } - + // postprocess texture for (int i = 0; i < array_count(lm->models); i++) { model_t *m = lm->models[i]; @@ -370426,7 +370433,7 @@ void lightmap_bake(lightmap_t *lm, int bounces, void (*drawscene)(lightmap_t *lm lmImageDilate(temp, m->lmdata, w, h, 4); lmImagePower(m->lmdata, w, h, 4, 1.0f / 2.2f, 0x7); // gamma correct color channels FREE(temp); - + // save result to a file // if (lmImageSaveTGAf("result.tga", m->lmdata, w, h, 4, 1.0f)) // printf("Saved result.tga\n"); diff --git a/engine/split/v4k_render.c b/engine/split/v4k_render.c index f70581d..880cf4a 100644 --- a/engine/split/v4k_render.c +++ b/engine/split/v4k_render.c @@ -788,11 +788,18 @@ texture_t texture_checker() { pixels[i++] = (rgb>>8) & 255; pixels[i++] = (rgb>>0) & 255; pixels[i++] = 255; -#else +#elif 0 extern const uint32_t secret_palette[32]; uint32_t lum = (x^y) & 8 ? 128 : (x^y) & 128 ? 192 : 255; uint32_t rgb = rgba(lum,lum,lum,255); pixels[i++] = rgb; +#else + int j = y, i = x; + unsigned char *p = (unsigned char *)&pixels[x + y * 256]; + p[0] = (i / 16) % 2 == (j / 16) % 2 ? 255 : 0; // r + p[1] = ((i - j) / 16) % 2 == 0 ? 255 : 0; // g + p[2] = ((i + j) / 16) % 2 == 0 ? 255 : 0; // b + p[3] = 255; // a #endif } } @@ -2945,6 +2952,10 @@ void model_set_state(model_t m) { glVertexAttribPointer(11, 4, GL_UNSIGNED_BYTE, GL_FALSE, sizeof(iqm_vertex), (GLvoid*)offsetof(iqm_vertex,color) ); glEnableVertexAttribArray(11); + // lmap data + glVertexAttribPointer(12, 2, GL_FLOAT, GL_FALSE, sizeof(iqm_vertex), (GLvoid*)offsetof(iqm_vertex, texcoord2) ); + glEnableVertexAttribArray(12); + // animation if(numframes > 0) { glVertexAttribPointer( 8, 4, GL_UNSIGNED_BYTE, GL_FALSE, sizeof(iqm_vertex), (GLvoid*)offsetof(iqm_vertex,blendindexes) ); @@ -2980,10 +2991,6 @@ void model_set_state(model_t m) { glVertexAttribDivisor(7, 1); } - // lmap data - glVertexAttribPointer(12, 2, GL_FLOAT, GL_FALSE, sizeof(iqm_vertex), (GLvoid*)offsetof(iqm_vertex, texcoord2) ); - glEnableVertexAttribArray(12); - // 7 bitangent? into texcoord.z? glBindVertexArray( 0 ); @@ -3339,7 +3346,7 @@ model_t model_from_mem(const void *mem, int len, int flags) { // if( shaderprog < 0 ) { const char *symbols[] = { "{{include-shadowmap}}", vfs_read("shaders/fs_0_0_shadowmap_lit.glsl") }; // #define RIM int shaderprog = shader(strlerp(1,symbols,vfs_read("shaders/vs_323444143_16_3322_model.glsl")), strlerp(1,symbols,vfs_read("shaders/fs_32_4_model.glsl")), //fs, - "att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_bitangent,att_texcoord2","fragColor", + "att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_texcoord2,att_bitangent","fragColor", va("SHADING_PHONG,%s", (flags&MODEL_RIMLIGHT)?"RIM":"")); // } // ASSERT(shaderprog > 0); @@ -3748,7 +3755,7 @@ lightmap_t lightmap(int hmsize, float cnear, float cfar, vec3 color, int passes, const char *symbols[] = { "{{include-shadowmap}}", vfs_read("shaders/fs_0_0_shadowmap_lit.glsl") }; // #define RIM lm.shader = shader(strlerp(1,symbols,vfs_read("shaders/vs_323444143_16_3322_model.glsl")), strlerp(1,symbols,vfs_read("shaders/fs_32_4_model.glsl")), //fs, - "att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_bitangent,att_texcoord2","fragColor", + "att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_texcoord2,att_bitangent","fragColor", va("%s", "LIGHTMAP_BAKING")); return lm; @@ -3797,7 +3804,7 @@ void lightmap_bake(lightmap_t *lm, int bounces, void (*drawscene)(lightmap_t *lm LM_FLOAT, (uint8_t*)m->verts + offsetof(iqm_vertex, normal), sizeof(iqm_vertex), LM_FLOAT, (uint8_t*)m->verts + offsetof(iqm_vertex, texcoord), sizeof(iqm_vertex), m->num_tris*3, LM_UNSIGNED_INT, m->tris); - + glDisable(GL_BLEND); int vp[4]; float view[16], projection[16]; @@ -3810,7 +3817,7 @@ void lightmap_bake(lightmap_t *lm, int bounces, void (*drawscene)(lightmap_t *lm lmEnd(lm->ctx); } } - + // postprocess texture for (int i = 0; i < array_count(lm->models); i++) { model_t *m = lm->models[i]; @@ -3824,7 +3831,7 @@ void lightmap_bake(lightmap_t *lm, int bounces, void (*drawscene)(lightmap_t *lm lmImageDilate(temp, m->lmdata, w, h, 4); lmImagePower(m->lmdata, w, h, 4, 1.0f / 2.2f, 0x7); // gamma correct color channels FREE(temp); - + // save result to a file // if (lmImageSaveTGAf("result.tga", m->lmdata, w, h, 4, 1.0f)) // printf("Saved result.tga\n"); diff --git a/engine/v4k.c b/engine/v4k.c index dbcc024..2879831 100644 --- a/engine/v4k.c +++ b/engine/v4k.c @@ -17719,11 +17719,18 @@ texture_t texture_checker() { pixels[i++] = (rgb>>8) & 255; pixels[i++] = (rgb>>0) & 255; pixels[i++] = 255; -#else +#elif 0 extern const uint32_t secret_palette[32]; uint32_t lum = (x^y) & 8 ? 128 : (x^y) & 128 ? 192 : 255; uint32_t rgb = rgba(lum,lum,lum,255); pixels[i++] = rgb; +#else + int j = y, i = x; + unsigned char *p = (unsigned char *)&pixels[x + y * 256]; + p[0] = (i / 16) % 2 == (j / 16) % 2 ? 255 : 0; // r + p[1] = ((i - j) / 16) % 2 == 0 ? 255 : 0; // g + p[2] = ((i + j) / 16) % 2 == 0 ? 255 : 0; // b + p[3] = 255; // a #endif } } @@ -20726,9 +20733,9 @@ void lightmap_bake(lightmap_t *lm, int bounces, void (*drawscene)(lightmap_t *lm lmSetGeometry(lm->ctx, m->pivot, LM_FLOAT, (uint8_t*)m->verts + offsetof(iqm_vertex, position), sizeof(iqm_vertex), LM_FLOAT, (uint8_t*)m->verts + offsetof(iqm_vertex, normal), sizeof(iqm_vertex), - LM_FLOAT, (uint8_t*)m->verts + offsetof(iqm_vertex, texcoord2), sizeof(iqm_vertex), + LM_FLOAT, (uint8_t*)m->verts + offsetof(iqm_vertex, texcoord), sizeof(iqm_vertex), m->num_tris*3, LM_UNSIGNED_INT, m->tris); - + glDisable(GL_BLEND); int vp[4]; float view[16], projection[16]; @@ -20741,7 +20748,7 @@ void lightmap_bake(lightmap_t *lm, int bounces, void (*drawscene)(lightmap_t *lm lmEnd(lm->ctx); } } - + // postprocess texture for (int i = 0; i < array_count(lm->models); i++) { model_t *m = lm->models[i]; @@ -20755,7 +20762,7 @@ void lightmap_bake(lightmap_t *lm, int bounces, void (*drawscene)(lightmap_t *lm lmImageDilate(temp, m->lmdata, w, h, 4); lmImagePower(m->lmdata, w, h, 4, 1.0f / 2.2f, 0x7); // gamma correct color channels FREE(temp); - + // save result to a file // if (lmImageSaveTGAf("result.tga", m->lmdata, w, h, 4, 1.0f)) // printf("Saved result.tga\n"); diff --git a/tools/ass2iqe.c b/tools/ass2iqe.c index 5ca7831..d9e87bf 100644 --- a/tools/ass2iqe.c +++ b/tools/ass2iqe.c @@ -1,8 +1,6 @@ // License: BSD unless otherwise stated. // https://github.com/ccxvii/asstools -#include "3rd_base64.h" - #include #include #include @@ -14,6 +12,13 @@ #include #include +#define BASE64_C +#define FREE free +#define MALLOC malloc +#include "3rd_base64.h" +#define STB_IMAGE_IMPLEMENTATION +#include "3rd_stb_image.h" + int verbose = 0; int need_to_bake_skin = 0; int save_all_bones = 0; @@ -1077,15 +1082,42 @@ void export_node(FILE *out, const struct aiScene *scene, const struct aiNode *no #if 1 // embedded textures char *embedded = 0; - if( strchr(buffer, '*') ) { // look for embedded textures. referenced like *1, *2, *3... where N is texture ID + + // look for embedded textures. referenced like *1, *2, *3... where N is texture ID + // note: mHeight can be zero, in this case texture->pcData is not RGB values but + // compressed JPEG/PNG/etc. data. Using stb_image to decode such image in that case. + + if( !strchr(buffer, '*') ) { + for( int j = 0; j < scene->mNumTextures; ++j ) { + struct aiTexture *tex = scene->mTextures[j]; + if( strstr(tex->mFilename.data, buffer + !isalpha(buffer[0])) ) { + snprintf(buffer, sizeof(buffer-1), "*%d", j); + break; + } + } + } + + if( strchr(buffer, '*') ) { int tex_id = atoi(buffer+1); if( tex_id < scene->mNumTextures ) { struct aiTexture *tex = scene->mTextures[tex_id]; struct aiTexel *data = tex->pcData; + const char *hint = tex->achFormatHint; // "rgba8888" or "png" unsigned w = tex->mWidth + !tex->mWidth; unsigned h = tex->mHeight + !tex->mHeight; - const char *hint = tex->achFormatHint; // "rgba8888" or "png" + +// stbi_uc *decoded = 0; + if( !tex->mHeight ) + { + int len = (int)w; + embedded = base64_encode(data, len); // leak +// int x = 0, y = 0, n = 0; +// decoded = stbi_load_from_memory((const stbi_uc *)data, len, &x, &y, &n, 4); +// w = x; h = y; data = (struct aiTexel *)decoded; + } + #if 1 + if(!embedded) embedded = base64_encode(data, w * h * sizeof(struct aiTexel)); // leak #else fprintf(stderr, "%dx%d (%s)\n", w,h,hint); @@ -1096,6 +1128,8 @@ void export_node(FILE *out, const struct aiScene *scene, const struct aiNode *no fwrite(&data[x+y*w].b, 1, 4, out); fclose(out); #endif + +// if( decoded ) stbi_image_free(decoded); } } #endif diff --git a/tools/ass2iqe.exe b/tools/ass2iqe.exe index a71607e..159be71 100644 Binary files a/tools/ass2iqe.exe and b/tools/ass2iqe.exe differ