3D: névoa e transparência nos 3 renderizadores
- Tb3dFrame ganha fog_color/fog_start/fog_end e opaque_count; versão 8. - Os draws saem com os opacos na frente e os transparentes (color[3] < 1) depois, do mais longe ao mais perto. - Software mistura por alfa e não grava o z; OpenGL e Vulkan usam um pipeline de blend separado (o alfa mistura a cor, sem gravar o z). - Blocos novos: "mude a opacidade de %1 para %2" (3D.Opacity) e "névoa de %1 até %2" (3D.Fog). - d3_test compara névoa e transparência nos três renderizadores. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cea7cb5ba4
commit
7b3cf8ce9b
11 files changed
+829
-647
No files matched your search
@@ -454,6 +454,68 @@ int main(void) {
|
||||
tb_image_release(si);
|
||||
}
|
||||
}
|
||||
/* -- Nevoa e transparencia: iguais nos tres renderizadores -- */
|
||||
{
|
||||
RUN("3D.Scene", NULL);
|
||||
RUN("3D.Use", "software");
|
||||
RUN("3D.Sky", "#ff0000");
|
||||
RUN("3D.Plane", "chão", "0", "0", "0");
|
||||
RUN("3D.Scale", "chão", "40", "1", "40");
|
||||
RUN("3D.Color", "chão", "#00ff00");
|
||||
RUN("3D.Camera", "0", "1", "0", "0", "1", "-10");
|
||||
RUN("3D.Ambient", "1");
|
||||
RUN("3D.Fog", "2", "8");
|
||||
TinyBlocks_Image* fg = render_with("software");
|
||||
CHECK(fg != NULL, "névoa: desenha");
|
||||
if (fg) {
|
||||
const uint8_t* p = tb_image_data_const(fg);
|
||||
int W = tb_image_width(fg), H = tb_image_height(fg);
|
||||
const uint8_t* perto = p + ((size_t)(H - 2) * W + W / 2) * 4; /* chao aos pes */
|
||||
const uint8_t* longe = p + ((size_t)(H / 2 + 3) * W + W / 2) * 4; /* chao no horizonte */
|
||||
printf(" névoa: perto (%d,%d,%d) longe (%d,%d,%d)\n", perto[0], perto[1], perto[2], longe[0], longe[1], longe[2]);
|
||||
CHECK(perto[1] > 200 && perto[0] < 60, "névoa: perto da câmera o chão fica com a cor dele");
|
||||
CHECK(longe[0] > 200 && longe[1] < 60, "névoa: longe o chão some na cor do céu");
|
||||
}
|
||||
RUN("3D.Fog", "0", "0");
|
||||
RUN("3D.Cube", "vidro", "0", "1", "-3");
|
||||
RUN("3D.Color", "vidro", "#0000ff");
|
||||
RUN("3D.Opacity", "vidro", "0.5");
|
||||
RUN("3D.Color", "vidro", "#0000ff"); /* trocar a cor mantem a opacidade */
|
||||
RUN("3D.Cube", "atras", "0", "1", "-6");
|
||||
RUN("3D.Scale", "atras", "3", "3", "1");
|
||||
RUN("3D.Color", "atras", "#ffffff");
|
||||
TinyBlocks_Image* tr = render_with("software");
|
||||
if (tr) {
|
||||
const uint8_t* p = tb_image_data_const(tr);
|
||||
int W = tb_image_width(tr), H = tb_image_height(tr);
|
||||
const uint8_t* c = p + ((size_t)(H / 2) * W + W / 2) * 4;
|
||||
printf(" transparência: centro (%d,%d,%d)\n", c[0], c[1], c[2]);
|
||||
/* frente e fundo do cubo misturam: branco -> 50% -> 25% de branco */
|
||||
CHECK(c[2] > 200 && c[0] > 40 && c[0] < 100, "transparência: o cubo azul a 50% deixa ver o branco atrás");
|
||||
}
|
||||
TinyBlocks_Image* both = tr;
|
||||
RUN("3D.Fog", "2", "12"); /* nevoa + transparencia juntas */
|
||||
TinyBlocks_Image* ref = render_with("software");
|
||||
const char* gpu[2] = { "opengl", "vulkan" };
|
||||
for (int i = 0; i < 2 && ref; i++) {
|
||||
TinyBlocks_Image* gi = render_with(gpu[i]);
|
||||
TinyBlocks_Block* gr = RUN("3D.Renderer", NULL);
|
||||
const char* used = gr->outputs[0].kind == TB_VALUE_TEXT ? gr->outputs[0].as.text : "";
|
||||
if (strncmp(used, gpu[i], strlen(gpu[i])) != 0) { tb_image_release(gi); continue; }
|
||||
double mean = 0, bad = 1;
|
||||
if (gi) compare(ref, gi, &mean, &bad);
|
||||
printf(" névoa+transparência %s x software: diferença média %.3f, pixels muito diferentes %.2f%%\n",
|
||||
gpu[i], mean, bad * 100);
|
||||
char m[96];
|
||||
snprintf(m, sizeof(m), "névoa e transparência desenham igual no %s", gpu[i]);
|
||||
CHECK(gi && mean < 4.0 && bad < 0.02, m);
|
||||
tb_image_release(gi);
|
||||
}
|
||||
if (fg) tb_image_release(fg);
|
||||
if (both) tb_image_release(both);
|
||||
if (ref) tb_image_release(ref);
|
||||
}
|
||||
|
||||
tb_image_release(sw);
|
||||
tinyblocks_deinit(&rt);
|
||||
if (fails) printf("\n%d FALHA(S)\n", fails);
|
||||
|
||||
Reference in new issue
Block a user