Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Am I expected to reqrite the tint functions when using shaders?

This thread is locked; no one can reply to it. rss feed Print
Am I expected to reqrite the tint functions when using shaders?
jmasterx
Member #11,410
October 2009

I have been scratching my head all day trying to figure this out. When using ALLEGRO_USE_PROGRAMMABLE_PIPELINE, any tinting does not work.

I found the variables allegro uses:

Quote:

projview_matrix - matrix for Allegro's orthographic projection multiplied by the al_use_transform matrix (vertex shader)

pos - vertex position attribute (vertex shader)

color - vertex color attribute (vertex shader, passed to fragment shader)

texcoord - vertex texture coordinate (vertex shader, passed to fragment shader)

use_tex - whether or not to use the bound texture (fragment shader)

tex - the sampler2D for the texture if one is bound (fragment shader)

use_tex_matric - whether or not to use a texture matrix (fragment shader)

tex_matrix - the texture matrix (fragment shader, used by the primitives addon)

But none of these offer the tint color. Am I expected to do like in ex_shader and send an array of floats each time I want to use a tinted function? That almost seems less efficient.

Is there an alternative? Am I doing something wrong?

I was also wondering, am I forced to use the pipeline flag? I cannot seem to get shaders working without it.

Thanks

Elias
Member #358
May 2000

What about "color"?

--
"Either help out or stop whining" - Evert

jmasterx
Member #11,410
October 2009

I tried that. Only gives me the color without the tint multiplied in.

Funny, if you look at:

#SelectExpand
1static void d3d_draw_textured_quad( 2 ALLEGRO_DISPLAY_D3D *disp, ALLEGRO_BITMAP *bmp, ALLEGRO_COLOR tint, 3 float sx, float sy, float sw, float sh, int flags) 4{ 5 float right; 6 float bottom; 7 float tu_start; 8 float tv_start; 9 float tu_end; 10 float tv_end; 11 int texture_w; 12 int texture_h; 13 ALLEGRO_BITMAP_EXTRA_D3D *extra = get_extra(bmp); 14 15 const float z = 0.0f; 16 17 ALLEGRO_DISPLAY* aldisp = (ALLEGRO_DISPLAY*)disp; 18 19 if (aldisp->num_cache_vertices != 0 && (uintptr_t)bmp != aldisp->cache_texture) { 20 aldisp->vt->flush_vertex_cache(aldisp); 21 } 22 aldisp->cache_texture = (uintptr_t)bmp; 23 24 right = sw; 25 bottom = sh; 26 27 texture_w = extra->texture_w; 28 texture_h = extra->texture_h; 29 tu_start = sx / texture_w; 30 tv_start = sy / texture_h; 31 tu_end = sw / texture_w + tu_start; 32 tv_end = sh / texture_h + tv_start; 33 34 if (flags & ALLEGRO_FLIP_HORIZONTAL) { 35 float temp = tu_start; 36 tu_start = tu_end; 37 tu_end = temp; 38 } 39 if (flags & ALLEGRO_FLIP_VERTICAL) { 40 float temp = tv_start; 41 tv_start = tv_end; 42 tv_end = temp; 43 } 44 45#define ALLEGRO_COLOR_TO_D3D(c) D3DCOLOR_COLORVALUE(c.r, c.g, c.b, c.a) 46 47#define SET(f) \ 48 vertices[0].x = 0; \ 49 vertices[0].y = 0; \ 50 vertices[0].z = z; \ 51 vertices[0].color = f(tint); \ 52 vertices[0].u = tu_start; \ 53 vertices[0].v = tv_start; \ 54 \ 55 vertices[1].x = right; \ 56 vertices[1].y = 0; \ 57 vertices[1].z = z; \ 58 vertices[1].color = f(tint); \ 59 vertices[1].u = tu_end; \ 60 vertices[1].v = tv_start; \ 61 \ 62 vertices[2].x = right; \ 63 vertices[2].y = bottom; \ 64 vertices[2].z = z; \ 65 vertices[2].color = f(tint); \ 66 vertices[2].u = tu_end; \ 67 vertices[2].v = tv_end; \ 68 \ 69 vertices[5].x = 0; \ 70 vertices[5].y = bottom; \ 71 vertices[5].z = z; \ 72 vertices[5].color = f(tint); \ 73 vertices[5].u = tu_start; \ 74 vertices[5].v = tv_end; \ 75\ 76 if (aldisp->cache_enabled) { \ 77 transform_vertex(&vertices[0].x, &vertices[0].y); \ 78 transform_vertex(&vertices[1].x, &vertices[1].y); \ 79 transform_vertex(&vertices[2].x, &vertices[2].y); \ 80 transform_vertex(&vertices[5].x, &vertices[5].y); \ 81 } \ 82 \ 83 vertices[3] = vertices[0]; \ 84 vertices[4] = vertices[2]; 85 86 bool pp = (aldisp->flags & ALLEGRO_USE_PROGRAMMABLE_PIPELINE) != 0; 87 88 if (pp) { 89 ALLEGRO_VERTEX *vertices = (ALLEGRO_VERTEX *)aldisp->vt->prepare_vertex_cache(aldisp, 6); 90 SET(ALLEGRO_COLOR) 91 } 92 else { 93 D3D_FIXED_VERTEX *vertices = (D3D_FIXED_VERTEX *)aldisp->vt->prepare_vertex_cache(aldisp, 6); 94 SET(ALLEGRO_COLOR_TO_D3D) 95 } 96 97 if (!aldisp->cache_enabled) 98 aldisp->vt->flush_vertex_cache(aldisp); 99}

Then you see the vertex color should be the tint color...

someone972
Member #7,719
August 2006
avatar

It does appear that tinting should still work with shaders, since the vertex color is what controls it. Are you discarding it in your shader and replacing it with a different color? Perhaps you should show the code for the shaders you are using right now.

EDIT: I see you have another thread with the code in it. I'll respond there since it has more of the information I was looking for.

______________________________________
As long as it remains classified how long it took me to make I'll be deemed a computer game genius. - William Labbett
Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why. -Unknown
I have recklessly set in motion a chain of events with the potential to so-drastically change the path of my life that I can only find it to be beautifully frightening.

Go to: