Forums > Jitter

glsl shader for affecting color based on geometry

August 28, 2006 | 7:35 pm

hello,
i’m trying to change the saturation of a texture based on the z value of a given geometry using a glsl shader. namely, i’d like the texture to be black and white where the z-value of the geometry is 0., and then become progressively more colored as points are displaced.

as i understand it, i need to pass the vertex coordinates from the vertext to the fragment programs. i attempt to do so with a varying variable but i’m not getting what i expect in the fragment shader. has any one a hint about what i’m doing wrong?

script and patch are below.

_______________script "grooves-in-surf-01.jxs"



Textured glass-like material lit with a point light w/ two specular components calculated per pixel.

Position of Light Source

Position

Tangent

Primary Specular Color

Secondary Specular Color

Base Color

Primary Specular Multiplier

Secondary Specular Multiplier

Specularity Adjustment



< ![CDATA[

uniform vec3 lightpos; // position of light source
attribute vec3 position;
//attribute vec3 tangent;

varying vec3 lightdir; // direction of light source
varying vec3 viewdir; // view direction
varying vec3 normal; // surface normal
varying vec3 mypos;

void main(void)
{
// perform standard transform on vertex

gl_Position = gl_ModelViewProjectionMatrix*gl_Vertex;
mypos = position;

//tried this also…
//mypos = gl_Vertex;

//so that fragment shader can pass texture through
gl_FrontColor = gl_Color;

// normalize view direction
viewdir = -normalize(vec3(gl_ModelViewMatrix * gl_Vertex));

// normalize light direction
lightdir = normalize(lightpos);

// get texture coordinate
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;

// transform normal into view space
normal = normalize(gl_NormalMatrix * gl_Normal);
}
]]>

< ![CDATA[
/*
*
* Derek Gerstmann – derek@cycling74.com
* Copyright 2005 – Cycling ’74
*
* GLSL fragment program for a textured glass-like material lit by a
* point light source.
*
*/

uniform sampler2DRect mytext;
varying vec3 mypos;

void main()
{
gl_FragColor = texture2DRect(mytext,gl_TexCoord[0].st);
gl_FragColor.r = mix(gl_FragColor.g, gl_FragColor.r,mypos.z);
gl_FragColor.b = mix(gl_FragColor.g, gl_FragColor.b,mypos.z);

}
]]>

_______________________________patch
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P comment 82 361 67 196617 read shader;
#B color 14;
#P window setfont "Sans Serif" 18.;
#P comment 55 353 25 196626 7.;
#B color 14;
#P window setfont "Sans Serif" 9.;
#P comment 333 361 67 196617 apply shader;
#B color 14;
#P window setfont "Sans Serif" 18.;
#P comment 302 353 25 196626 8.;
#B color 14;
#P window setfont "Sans Serif" 9.;
#P message 36 394 141 196617 read grooves-in-surf-01.jxs;
#P toggle 283 361 15 0;
#P newex 281 386 41 196617 sel 0 1;
#P toggle 359 250 15 0;
#P message 359 272 46 196617 axes $1;
#P user jit.fpsgui 478 469 60 196617 4;
#P newex 39 518 99 196617 prepend draw_mode;
#P user ubumenu 40 495 68 196617 0 1 1 0;
#X add points;
#X add lines;
#X add line_strip;
#X add line_loop;
#X add triangles;
#X add tri_strip;
#X add tri_fan;
#X add quads;
#X add quad_strip;
#X add polygon;
#X add tri_grid;
#X prefix_set 0 0 0;
#X pattrmode 1;
#P message 282 415 40 196617 shader;
#P message 324 415 82 196617 shader myshade;
#P message 108 424 30 196617 read;
#P newex 17 448 198 196617 jit.gl.shader render_grid @name myshade;
#P newex 541 125 31 196617 dac~;
#P user ezdac~ 357 165 401 198 0;
#P newex 573 365 69 196617 loadmess 0.2;
#P flonum 573 398 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P hidden newex 713 286 48 196617 loadbang;
#P hidden newex 713 306 31 196617 t b 3;
#P comment 776 406 66 196617 draw on LCD;
#B color 14;
#P window setfont "Sans Serif" 18.;
#P comment 745 398 25 196626 5.;
#B color 14;
#P button 857 282 15 0;
#P user jit.pwindow 842 346 29 20 0 1 0 0 1 0;
#P window setfont "Sans Serif" 9.;
#P message 987 265 74 196617 read chilis.jpg;
#P comment 454 396 60 196617 blur on/off;
#B color 14;
#P window setfont "Sans Serif" 18.;
#P comment 423 388 25 196626 6.;
#B color 14;
#P toggle 531 402 15 0;
#P window setfont "Sans Serif" 9.;
#N vpatcher 30 89 704 557;
#P inlet 268 59 15 0;
#P window setfont "Sans Serif" 9.;
#P window linecount 0;
#P newex 50 50 59 196617 r geomsize;
#P newex 50 78 27 196617 t b l;
#P window linecount 2;
#P message 472 141 178 196617 exprfill 0 "norm[0]" , exprfill 1 1.-
norm[1] , bang;
#P window linecount 1;
#P newex 472 173 190 196617 jit.matrix texcoords 2 float32 320 240;
#P message 293 218 213 196617 exprfill 0 "snorm[0]" , exprfill 1 "snorm[1]";
#P newex 293 254 168 196617 jit.matrix geom 3 float32 320 240;
#P newex 67 254 211 196617 jit.pack 3 float32 320 240 @out_name geom;
#P inlet 173 58 15 0;
#P outlet 472 195 15 0;
#P outlet 67 276 15 0;
#P connect 9 0 8 0;
#P connect 8 1 3 0;
#P connect 2 0 3 0;
#P connect 3 0 0 0;
#P connect 10 0 3 2;
#P connect 8 0 5 0;
#P connect 8 1 4 0;
#P connect 5 0 4 0;
#P connect 8 0 7 0;
#P connect 7 0 6 0;
#P connect 8 1 6 0;
#P connect 6 0 1 0;
#P pop;
#P newobj 164 506 61 196617 p geometry;
#N vpatcher 0 44 1440 870;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 386 314 66 196617 jit.unpack 4;
#P inlet 592 75 15 0;
#P user jit.pwindow 616 167 82 62 0 1 0 0 1 0;
#P user jit.pwindow 619 365 82 62 0 1 0 0 1 0;
#P inlet 322 50 15 0;
#P user gswitch2 357 150 39 32 1 0;
#P window linecount 0;
#P newex 318 234 59 196617 r geomsize;
#P newex 386 263 142 196617 jit.matrix 4 float32 320 240;
#P newex 386 234 167 196617 jit.gl.slab.gauss6x.pat render_grid;
#P inlet 386 51 15 0;
#P outlet 386 412 15 0;
#P connect 6 0 5 0;
#P connect 1 0 5 1;
#P connect 5 1 2 0;
#P connect 4 0 3 0;
#P connect 2 0 3 0;
#P connect 3 0 10 0;
#P connect 10 1 0 0;
#P fasten 5 0 0 0 288 219 288 272;
#P connect 9 0 2 1;
#P connect 1 0 8 0;
#P connect 3 0 7 0;
#P pop;
#P newobj 531 435 52 196617 p blur;
#P comment 189 90 40 196617 render;
#B color 14;
#P comment 980 246 142 196617 send image to GPU as texture;
#B color 14;
#N vpatcher 40 104 640 504;
#P window setfont "Sans Serif" 9.;
#P newex 50 140 66 196617 prepend size;
#P newex 50 106 79 196617 vexpr $i1 + 20;
#P newex 50 77 53 196617 route dim;
#P newex 50 50 59 196617 r geomsize;
#P outlet 50 162 15 0;
#P connect 1 0 2 0;
#P connect 2 0 3 0;
#P connect 3 0 4 0;
#P connect 4 0 0 0;
#P pop;
#P hidden newobj 691 404 30 196617 p;
#P newex 1031 304 57 196617 route read;
#P user jit.fpsgui 813 304 60 196617 3;
#P flonum 205 112 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P toggle 164 111 15 0;
#P newex 164 131 51 196617 qmetro 2;
#P user jit.fpsgui 88 164 60 196617 0;
#P window setfont "Sans Serif" 18.;
#P comment 160 82 25 196626 4.;
#B color 14;
#P comment 954 240 25 196626 3.;
#B color 14;
#P button 1031 330 15 0;
#P window setfont "Sans Serif" 9.;
#P number 713 330 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 713 350 73 196617 pensize $1 $1;
#P comment 1039 58 74 196617 geometry size;
#B color 14;
#P comment 923 58 57 196617 image size;
#B color 14;
#P window setfont "Sans Serif" 18.;
#P comment 1012 51 25 196626 2.;
#B color 14;
#P window setfont "Sans Serif" 9.;
#P newex 757 90 60 196617 loadmess 1;
#P newex 875 245 62 196617 r imagesize;
#P button 876 59 15 0;
#P button 994 57 15 0;
#P newex 994 203 59 196617 s geomsize;
#P newex 994 179 64 196617 prepend dim;
#P newex 994 154 56 196617 route text;
#P user textedit 994 85 1094 135 32896 3 9 100 100;
#P newex 876 203 62 196617 s imagesize;
#P newex 876 179 64 196617 prepend dim;
#P newex 876 154 56 196617 route text;
#P user textedit 876 85 976 135 32896 3 9 800 600;
#P message 679 350 33 196617 clear;
#P user jit.pwindow 678 439 102 102 0 1 0 0 1 0;
#N vpatcher 0 44 1440 870;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 692 282 56 196617 jit.pack 4.;
#P newex 717 236 115 196617 jit.op @op !- @val 255.;
#P message 725 73 45 196617 color $1;
#P number 725 54 35 9 0 255 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 103 168 66 196617 prepend size;
#P newex 103 138 53 196617 route dim;
#P newex 103 101 59 196617 r geomsize;
#P newex 296 119 59 196617 r geomsize;
#P newex 865 73 59 196617 r geomsize;
#P newex 689 204 66 196617 jit.unpack 4.;
#P newex 384 178 142 196617 jit.matrix 4 float32 640 480;
#P outlet 485 331 15 0;
#P inlet 1127 51 15 0;
#P inlet 588 51 15 0;
#P outlet 384 331 15 0;
#P window linecount 0;
#P newex 824 74 31 196617 r lcd;
#P window linecount 1;
#P message 1057 465 44 196617 getpixel;
#P message 1057 445 50 196617 getpenloc;
#P toggle 824 514 15 0;
#P newex 824 532 50 196617 gate 1 1;
#P newex 961 521 50 196617 gate 2 2;
#P message 983 548 50 196617 set lineto;
#P message 900 549 58 196617 set moveto;
#P newex 898 443 29 196617 t i b;
#P newex 900 470 27 196617 int;
#P newex 824 583 79 196617 prepend moveto;
#P newex 824 487 47 196617 pack 0 0;
#P message 984 74 32 196617 reset;
#P message 984 57 31 196617 clear;
#P newex 824 117 111 196617 jit.lcd 4 char 640 480;
#B color 5;
#P comment 839 424 28 196617 x , y;
#P number 988 402 16 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 970 402 16 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 952 402 16 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 934 402 16 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 916 402 16 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 898 402 16 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 861 402 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 824 402 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 824 376 166 196617 unpack 0 0 0 0 0 0 0 0;
#P newex 824 350 110 196617 route mouse mouseidle;
#P comment 908 424 169 196617 button , cmd , shift , caps , opt , ctrl;
#P newex 900 491 40 196617 sel 0 1;
#P window linecount 4;
#P comment 1051 512 130 196617 picts can either be read in from a file just like lcd , or can reference named matrices (must be 4 char);
#P user ubumenu 961 494 82 196617 0 1 1 0;
#X add no_mouse;
#X add mouse_moves;
#X add mouse_draws;
#X prefix_set 0 0
0;
#X pattrmode 1;
#P connect 38 0 39 0;
#P connect 39 0 40 0;
#P connect 31 0 34 0;
#P connect 44 0 34 0;
#P connect 37 0 34 0;
#P connect 34 0 30 0;
#P connect 40 0 33 0;
#P connect 15 0 33 0;
#P connect 15 0 35 0;
#P connect 43 0 44 0;
#P connect 43 0 44 1;
#P connect 35 2 43 0;
#P connect 43 0 44 2;
#P connect 41 0 42 0;
#P connect 43 0 44 3;
#P connect 36 0 15 0;
#P hidden connect 28 0 15 0;
#P hidden connect 27 0 15 0;
#P hidden connect 17 0 15 0;
#P hidden connect 16 0 15 0;
#P connect 29 0 15 0;
#P fasten 19 0 15 0 829 609 802 609 802 105 829 105;
#P connect 42 0 15 0;
#P connect 31 0 15 0;
#P connect 32 0 4 0;
#P fasten 4 1 5 0 879 371 829 371;
#P connect 4 0 5 0;
#P connect 5 0 6 0;
#P connect 6 0 18 0;
#P fasten 0 0 26 0 966 511 829 511;
#P connect 26 0 25 0;
#P connect 25 0 19 0;
#P fasten 22 0 19 0 905 573 829 573;
#P fasten 23 0 19 0 988 573 829 573;
#P fasten 5 1 7 0 851 397 866 397;
#P connect 7 0 18 1;
#P fasten 18 0 25 1 829 511 869 511;
#P fasten 5 2 8 0 873 397 903 397;
#P connect 8 0 21 0;
#P connect 21 1 20 0;
#P connect 20 0 2 0;
#P connect 2 0 22 0;
#P fasten 24 0 22 0 966 544 905 544;
#P fasten 5 3 9 0 895 397 921 397;
#P connect 21 0 20 1;
#P fasten 5 4 10 0 917 397 939 397;
#P fasten 5 5 11 0 939 397 957 397;
#P fasten 0 0 24 0 966 514 966 514;
#P fasten 5 6 12 0 961 397 975 397;
#P fasten 24 1 23 0 1006 544 988 544;
#P fasten 5 7 13 0 983 397 993 397;
#P fasten 2 1 24 1 920 518 1006 518;
#P pop;
#P newobj 649 404 40 196617 p lcd;
#P toggle 459 501 15 0;
#P message 459 524 88 196617 poly_mode $1 $1;
#P toggle 757 130 15 0;
#P message 757 158 44 196617 fsaa $1;
#P toggle 698 130 15 0;
#P message 698 158 46 196617 sync $1;
#P hidden newex 386 471 80 196617 loadmess -0.25;
#P flonum 386 502 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 343 502 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 301 502 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 272 526 99 196617 pak scale 1. 1. 0.25;
#P newex 164 177 80 196617 t b l erase b;
#P newex 875 351 192 196617 jit.gl.texture render_grid @name mytex;
#P newex 164 579 423 196617 jit.gl.mesh render_grid @draw_mode tri_grid @texture mytex @color 1. 1. 1. 1.;
#P user jit.fpsgui 679 687 60 196617 0;
#N vpatcher 645 520 1121 872;
#P inlet 230 84 15 0;
#P toggle 352 214 15 0;
#P window setfont "Sans Serif" 9.;
#P message 352 233 75 196617 auto_rotate $1;
#P message 315 233 32 196617 reset;
#P newex 103 101 27 196617 t i i;
#P flonum 261 213 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 261 233 51 196617 radius $1;
#P flonum 194 213 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 194 233 60 196617 tracking $1;
#P newex 10 254 355 196617 jit.gl.handle render_grid @inherit_transform 1 @depth_enable 1 @tracking 8;
#P outlet 10 284 15 0;
#P newex 103 56 50 196617 select 27;
#P newex 103 34 40 196617 key;
#P newex 120 146 91 196617 prepend fullscreen;
#P newex 120 167 312 196617 jit.window render_grid @size 320 240 @depthbuffer 1 @floating 1;
#P comment 10 218 178 196617 inherit_transform is important here , since we are controlling jit.gl.render;
#P toggle 103 81 15 0;
#P fasten 14 0 7 0 357 251 15 251;
#P fasten 10 0 7 0 266 251 15 251;
#P fasten 8 0 7 0 199 248 15 248;
#P fasten 13 0 7 0 320 251 15 251;
#P connect 7 0 6 0;
#P connect 4 0 5 0;
#P connect 5 0 0 0;
#P connect 0 0 12 0;
#P connect 12 1 3 0;
#P connect 3 0 2 0;
#P connect 16 0 2 0;
#P connect 9 0 8 0;
#P connect 11 0 10 0;
#P connect 15 0 14 0;
#P pop;
#P newobj 698 185 115 196617 p window-mouse-rotate;
#P message 1176 271 111 196617 read bastille.png , bang;
#P newex 875 304 153 196617 jit.qt.movie 320 240 @unique 1;
#P newex 210 224 120 196617 jit.gl.render render_grid;
#P user panel 669 430 120 120;
#X brgb 191 191 191;
#X frgb 0 0 0;
#X border 1;
#X rounded 0;
#X shadow 0;
#X done;
#P window setfont "Sans Serif" 18.;
#P comment 895 51 25 196626 1.;
#B color 14;
#P connect 80 0 69 0;
#P fasten 70 0 69 0 113 443 22 443;
#P fasten 73 1 74 0 74 514 44 514;
#P connect 9 0 44 0;
#P connect 46 0 45 0;
#P connect 45 0 9 0;
#P connect 9 0 54 0;
#P connect 74 0 7 0;
#P connect 71 0 7 0;
#P connect 72 0 7 0;
#P fasten 19 0 7 0 464 560 169 560;
#P fasten 10 0 7 0 277 554 169 554;
#P connect 54 0 7 0;
#P connect 47 0 45 1;
#P fasten 9 0 2 0 169 207 215 207;
#P fasten 5 0 2 0 703 207 215 207;
#P fasten 9 2 2 0 215 206 215 206;
#P connect 76 0 2 0;
#P fasten 53 0 54 1 536 465 220 465;
#P connect 54 1 7 1;
#P connect 79 0 78 0;
#P connect 78 0 72 0;
#P connect 11 0 10 1;
#P connect 78 1 71 0;
#P connect 12 0 10 2;
#P connect 77 0 76 0;
#P connect 13 0 10 3;
#P hidden connect 14 0 13 0;
#P connect 20 0 19 0;
#P connect 53 0 75 0;
#P connect 55 0 53 0;
#P fasten 21 0 53 1 654 426 557 426;
#P connect 66 0 65 0;
#P connect 65 0 53 2;
#P fasten 9 3 21 0 238 192 654 192 654 215 654 215;
#P connect 23 0 21 0;
#P connect 39 0 21 0;
#P hidden connect 50 0 1 0;
#P hidden connect 63 0 23 0;
#P fasten 22 1 21 1 774 567 1114 567 1114 390 684 390;
#P connect 21 1 22 0;
#P connect 22 0 6 0;
#P connect 16 0 15 0;
#P connect 17 0 5 0;
#P connect 15 0 5 0;
#P hidden connect 64 0 63 0;
#P hidden connect 63 1 40 0;
#P connect 40 0 39 0;
#P connect 35 0 18 0;
#P connect 18 0 17 0;
#P connect 3 0 48 0;
#P connect 3 0 59 0;
#P connect 41 0 3 0;
#P fasten 4 0 3 0 1181 295 880 295;
#P connect 34 0 3 0;
#P fasten 58 0 3 0 992 295 880 295;
#P connect 60 0 3 0;
#P connect 3 0 8 0;
#P connect 33 0 24 0;
#P connect 24 0 25 0;
#P connect 25 0 26 0;
#P connect 26 0 27 0;
#P connect 32 0 28 0;
#P connect 28 0 29 0;
#P connect 29 0 30 0;
#P connect 30 0 31 0;
#P connect 3 1 49 0;
#P connect 49 0 41 0;
#P window clipboard copycount 85;


August 29, 2006 | 1:13 am

Hi Ali,

>

> Position
>

> attribute vec3 position;
> varying vec3 mypos;

> gl_Position = gl_ModelViewProjectionMatrix*gl_Vertex;
> mypos = position;

This position is all zero unfortunately. I’ve never used this means
of binding the position as a vertex attribute, so there may be issues
or it may not be supported within the context of our GLSL shaders
(may be relevant for Cg). I guess I need to investigate this further,
but regardless, in GLSL I would recommend you simply use the built-in
GLSL attribute "gl_Vertex" (transformed or untransformed as you
choose). This is equivalent to what position would be.

The following line is probably what you want to do (use the vertex
values untransofrmed by the world transformation). However, as you
probably noticed, based on your comments, it gives you an error.

> mypos = gl_Vertex;

"ERROR: 0:18: ‘assign’ : cannot convert from ‘attribute 4-component
vector of float’ to ‘varying 3-component vector of float’"

If you see errors like the above, it means that you are trying to
work with incompatible types that need to be resolved one way or
another. Please read the OpenGL orange book for GLSL type values. In
this case, this means that you are trying to assign a vec4 to a vec3.
This is not permitted without an explicit cast. Why is gl_Vertex a
vec4? Because OpenGL internally uses homogenous coordinates for
applying transforms to values. A 3D position vector (x,y,z)
represented in homogenous coordinates is a 4 element value (x,y,z,w)
where w is a scaling factor, typically 1 (no scaling). This is useful
for the matrix multiplication that will translate, rotate, scale, etc
all points. For more information about homogenous coordinates, please
check out any of the OpenGL documentation (red book, orange book,
etc.), and/or search online.

So, the following line works as you would expect.

mypos = vec3(gl_Vertex);

Or another solution is to change the mypos variable to a vec4 in both
the vertex and fragment shader.

I would also recommend that you eliminate varying values which are
not used in both shaders, and that you approach debugging your
shaders by setting the output fragment color to some value that you
wish to monitor. For example if you set gl_FragColor = vec4
(mypos.z); you will see what its value is.

-Joshua


August 29, 2006 | 1:25 am

Also, before continuing to bang your head against the wall with this
stuff. I’d recommend taking an afternoon or two to slowly walk
through some GLSL tutorials such as those found at the following web
sites. This is a general technology (not jitter specific) and there
are lots of great resources out there to help you learn how to use it.

http://www.lighthouse3d.com/opengl/glsl/
http://www.clockworkcoders.com/oglsl/tutorials.html

http://nehe.gamedev.net/data/articles/article.asp?article=21

-Joshua


August 29, 2006 | 1:57 am

To add to that list, this one is quite nice as well:

http://www.ozone3d.net/tutorials/glsl_texturing.php

wes


August 29, 2006 | 5:43 am

hello,
not a whole lot of head banging going on over here as i indeed started with 2 afternoons of tutorials, namely the first two of josh’s three. so i’m well aware of the differenc between a vec3 and vec4, so i wasn’t getting a compiler error when i tried filling my varying variable with gl_Vertex; i must have had some other stupid bug in my code cuz for whatever reason, i can get it working now.

as for the 1st way of filling the ‘mypos’ variable, which was with the binding of ‘position’ to gl_Position, that definitely works in other cases. i got it from the patch/shader that wes posted 2 days ago as a vertext-displacement example. however, i can’t get it to work in this instance…

on the otherhand, i’d also found this tutorial from the site that wes mentioned:

http://ozone3d.net/tutorials/vertex_displacement_mapping.php

this seems to suggest that accessing textures in the vertex program is indeed possible, whereas wes was saying that’ll only going be availble in glsl 2.0. which is it i wonder.

thanks,
a


August 29, 2006 | 6:08 am

I saw that too, but there’s a gotcha:

The displacement mapping involves a graphics controller that supports
Shader Model 3.0 norm. Currently, all nVidia Geforce 6xxx and higher
based graphics controllers are SM 3.0 complient as well as the latest
ATI Radeons X1800 and X1900. To be more accurate, we have to access at
least to one texture inside the vertex shader in order to make
displacement mapping working. The access to a texture inside the
vertex shader is called Vertex Texture Fetching. The shader model 3.0
imposes that at least 4 texture units are accessible inside the vertex
shader.

This information can be get in OpenGL using the constant:
GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB.

If I run the OpenGL profile (assuming you’re on OSX) in
Developer/Applications/Graphics Toos/ and go to Monitors->Renderer
Info and look under my graphics card’s rendere->OpenGL limits, I see
GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB = 0. I think that’s pretty
definitive. If you’re on windows, I’m sure there’s a tool that can
tell you what this limit is on your machine or you can compile a
simple OpenGL test application and query this value yourself. At this
point in time you need some really bad ass hardware to do Vertex
Texture Fetching. I personally have not come across a machine that
does this yet, but it will be a fine day when I do.

Also, my current version of GLSL is 1.10 and
GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB is only > 0 for GLSL 1.2 or
higher.

best,
wes

On 8/28/06, Ali Momeni wrote:
>
>
> hello,
> not a whole lot of head banging going on over here as i indeed started with 2 afternoons of tutorials, namely the first two of josh’s three. so i’m well aware of the differenc between a vec3 and vec4, so i wasn’t getting a compiler error when i tried filling my varying variable with gl_Vertex; i must have had some other stupid bug in my code cuz for whatever reason, i can get it working now.
>
> as for the 1st way of filling the ‘mypos’ variable, which was with the binding of ‘position’ to gl_Position, that definitely works in other cases. i got it from the patch/shader that wes posted 2 days ago as a vertext-displacement example. however, i can’t get it to work in this instance…
>
> on the otherhand, i’d also found this tutorial from the site that wes mentioned:
>
> http://ozone3d.net/tutorials/vertex_displacement_mapping.php
>
> this seems to suggest that accessing textures in the vertex program is indeed possible, whereas wes was saying that’ll only going be availble in glsl 2.0. which is it i wonder.
>
> thanks,
> a
>
>
>


August 29, 2006 | 6:11 am

PS If you’re on windows, download this tool:

http://ozone3d.net/hardware_infos.php

It will tell you what you need to know.

wes

On 8/28/06, Wesley Smith wrote:
> I saw that too, but there’s a gotcha:
>
> The displacement mapping involves a graphics controller that supports
> Shader Model 3.0 norm. Currently, all nVidia Geforce 6xxx and higher
> based graphics controllers are SM 3.0 complient as well as the latest
> ATI Radeons X1800 and X1900. To be more accurate, we have to access at
> least to one texture inside the vertex shader in order to make
> displacement mapping working. The access to a texture inside the
> vertex shader is called Vertex Texture Fetching. The shader model 3.0
> imposes that at least 4 texture units are accessible inside the vertex
> shader.
>
> This information can be get in OpenGL using the constant:
> GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB.
>
> If I run the OpenGL profile (assuming you’re on OSX) in
> Developer/Applications/Graphics Toos/ and go to Monitors->Renderer
> Info and look under my graphics card’s rendere->OpenGL limits, I see
> GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB = 0. I think that’s pretty
> definitive. If you’re on windows, I’m sure there’s a tool that can
> tell you what this limit is on your machine or you can compile a
> simple OpenGL test application and query this value yourself. At this
> point in time you need some really bad ass hardware to do Vertex
> Texture Fetching. I personally have not come across a machine that
> does this yet, but it will be a fine day when I do.
>
> Also, my current version of GLSL is 1.10 and
> GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB is only > 0 for GLSL 1.2 or
> higher.
>
> best,
> wes
>
> On 8/28/06, Ali Momeni wrote:
> >
> >
> > hello,
> > not a whole lot of head banging going on over here as i indeed started with 2 afternoons of tutorials, namely the first two of josh’s three. so i’m well aware of the differenc between a vec3 and vec4, so i wasn’t getting a compiler error when i tried filling my varying variable with gl_Vertex; i must have had some other stupid bug in my code cuz for whatever reason, i can get it working now.
> >
> > as for the 1st way of filling the ‘mypos’ variable, which was with the binding of ‘position’ to gl_Position, that definitely works in other cases. i got it from the patch/shader that wes posted 2 days ago as a vertext-displacement example. however, i can’t get it to work in this instance…
> >
> > on the otherhand, i’d also found this tutorial from the site that wes mentioned:
> >
> > http://ozone3d.net/tutorials/vertex_displacement_mapping.php
> >
> > this seems to suggest that accessing textures in the vertex program is indeed possible, whereas wes was saying that’ll only going be availble in glsl 2.0. which is it i wonder.
> >
> > thanks,
> > a
> >
> >
> >
>


Viewing 7 posts - 1 through 7 (of 7 total)