3D: shader de vértice (o "compile o shader" descobre o estágio)
- novo bloco "mude a posição do vértice para x y z" (Shader.Vertex): a pilha que o usa vira um shader de VÉRTICE; a que usa "cor do pixel" vira de FRAGMENTO; misturar os dois dá erro claro - o GLSL gerado é tb_vert (vértice) ou tb_shade (fragmento); o software roda o mesmo programa vértice a vértice - OpenGL e Vulkan montam o programa do estágio certo e juntam com o estágio padrão (posição intacta / cor do objeto com luz) - Tb3dShader ganha "stage"; Tb3dRenderer.compile leva o estágio; TB_3D_RENDERER_VERSION -> 5 - docs regeradas (blocos, referência da API, libraries, pendências) e exemplo examples/jogo-3d/onda.sb (esfera que pulsa) - test-3d: o shader de vértice dá igual nos 3 renderizadores Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1e171411f7
commit
d5c16a5237
14 files changed
+667
-85
No files matched your search
@@ -261,6 +261,45 @@ int main(void) {
|
||||
}
|
||||
tb_image_release(ui);
|
||||
}
|
||||
|
||||
/* -- shader de vertice: estica o triangulo no y -- */
|
||||
{
|
||||
const char* vex = "[" BLK("Shader.Vertex", BLK0("Shader.VX") "," BLK("Math.Mul", BLK0("Shader.VY") "," "2") "," BLK0("Shader.VZ")) "]";
|
||||
TinyBlocks_Block* sv = compile_shader(vex);
|
||||
CHECK(sv != NULL, "shader de vértice (\"mude a posição do vértice\") compila");
|
||||
CHECK(!compile_shader("[" BLK("Shader.Pixel", BLK("Shader.Color", "\"azul\"")) "," BLK("Shader.Vertex", BLK0("Shader.VX") "," BLK0("Shader.VY") "," BLK0("Shader.VZ")) "]"),
|
||||
"não mistura \"cor do pixel\" com \"mude a posição do vértice\"");
|
||||
tinyblocks_clear_error(rt);
|
||||
if (sv) {
|
||||
TinyBlocks_Block* g = run_with_shader("3D.ShaderGlsl", sv, NULL);
|
||||
CHECK(g->outputs[0].kind == TB_VALUE_TEXT && strstr(g->outputs[0].as.text, "vec3 tb_vert("),
|
||||
"o GLSL gerado pelo shader de vértice é tb_vert");
|
||||
run_with_shader("3D.ShaderUse", sv, "quad");
|
||||
TinyBlocks_Image* vi = render_with("software");
|
||||
CHECK(vi != NULL, "o shader de vértice desenha no software");
|
||||
if (vi) {
|
||||
uint8_t t[4];
|
||||
tb_image_get_pixel(vi, 160, 40, &t[0], &t[1], &t[2], &t[3]);
|
||||
printf(" vertice: topo y=40 rgb=(%d,%d,%d)\n", t[0], t[1], t[2]);
|
||||
for (int i = 0; i < 2; i++) {
|
||||
const char* lib = i ? "tinyblocks-vk" : "tinyblocks-gl";
|
||||
if (!tb_rt_find_library(rt, lib)) continue;
|
||||
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(vi, gi, &mean, &bad);
|
||||
printf(" vértice %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), "o shader de vértice desenha igual no %s", gpu[i]);
|
||||
CHECK(gi && mean < 4.0 && bad < 0.02, m);
|
||||
tb_image_release(gi);
|
||||
}
|
||||
}
|
||||
tb_image_release(vi);
|
||||
}
|
||||
}
|
||||
tb_image_release(sw);
|
||||
tinyblocks_deinit(&rt);
|
||||
if (fails) printf("\n%d FALHA(S)\n", fails);
|
||||
|
||||
Reference in new issue
Block a user