Forums > Jitter

specular + bump maps

December 5, 2006 | 3:23 pm

Im curious if specular and bump mapping is possible with shaders. Ive seen a few videogames with really nice realtime shaders with specular and bump mapping, which gives the scene alot more realism.


December 5, 2006 | 3:51 pm

yes. one of the older artists at the last jitter intensive i taught
was very curious about the possibility of bumpmapping. she said that
it might make the difference when it came to switching primary
applications.

On Dec 5, 2006, at 10:23 AM, Nicholas C. Raftis III wrote:

>
> Im curious if specular and bump mapping is possible with shaders.
> Ive seen a few videogames with really nice realtime shaders with
> specular and bump mapping, which gives the scene alot more realism.
> –
> -=ili!ili=- http://www.Axiom-Crux.net -=ili!ili=-
>


December 5, 2006 | 4:07 pm

Yes,
Bump mapping is definitely possible with shaders. Have a look at "The
Cg Tutorial" by Mark Kilgard on p. 199.

wes

On 12/5/06, joshua goldberg wrote:
> yes. one of the older artists at the last jitter intensive i taught
> was very curious about the possibility of bumpmapping. she said that
> it might make the difference when it came to switching primary
> applications.
>
> On Dec 5, 2006, at 10:23 AM, Nicholas C. Raftis III wrote:
>
> >
> > Im curious if specular and bump mapping is possible with shaders.
> > Ive seen a few videogames with really nice realtime shaders with
> > specular and bump mapping, which gives the scene alot more realism.
> > –
> > -=ili!ili=- http://www.Axiom-Crux.net -=ili!ili=-
> >
>
>


December 5, 2006 | 4:32 pm

any online examples? and are you thinking of providing
some bumpmap jxs in the next jit.release
?

On Dec 5, 2006, at 11:07 AM, Wesley Smith wrote:

> Yes,
> Bump mapping is definitely possible with shaders. Have a look at "The
> Cg Tutorial" by Mark Kilgard on p. 199.
>
> wes
>
> On 12/5/06, joshua goldberg wrote:
>> yes. one of the older artists at the last jitter intensive i taught
>> was very curious about the possibility of bumpmapping. she said that
>> it might make the difference when it came to switching primary
>> applications.
>>
>> On Dec 5, 2006, at 10:23 AM, Nicholas C. Raftis III wrote:
>>
>> >
>> > Im curious if specular and bump mapping is possible with shaders.
>> > Ive seen a few videogames with really nice realtime shaders with
>> > specular and bump mapping, which gives the scene alot more realism.
>> > –
>> > -=ili!ili=- http://www.Axiom-Crux.net -=ili!ili=-
>> >
>>
>>
>


December 11, 2006 | 9:05 pm

>any online examples? and are you thinking of providing
>some bumpmap jxs in the next jit.release
?

Because we don’t automatically generate vertex tangents for our
geometry, doing true bump-mapping in Jitter is going to be difficult,
and will require passing in the data via a texture, using pre-cooked
geometry data. However, you can do a sort of
good-enough-for-experimental-video version of it by passing in a Normal
perturbation map as a texture. Below you’ll find an example shader,
along with a patch to use it. As always, watch out for mail formatting
garbage.

Enjoy,
Andrew B.

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P comment 391 76 127 196617 bang to generate bump map;
#P button 374 76 15 0;
#P newex 374 102 368 196617 jit.gl.gridshape stock @dim 30 30
@matrixoutput 1 @automatic 0 @shape torus;
#P number 331 76 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 330 233 53 196617 jit.pack 4;
#P newex 330 135 177 196617 jit.matrix 3 float32 30 30 @interp 1;
#B color 5;
#P newex 330 255 68 196617 jit.normalize;
#P flonum 654 175 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 2;
#P newex 330 193 335 196617 jit.expr @expr
"noise.simplex(in[3]*in[0]\, in[3]*in[1]\, in[3]*in[2])" @inputs 4;
#P window linecount 1;
#P newex 330 156 334 196617 jit.unpack 3;
#P window linecount 2;
#P message 331 102 41 196617 dim $1 $1;
#P flonum 214 209 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 122 228 102 196617 pak param diffuse 0.;
#P flonum 215 161 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 219 250 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 183 250 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 147 250 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 123 273 130 196617 pak param color 0. 0. 0. 0.;
#P flonum 179 161 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 143 161 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 122 185 129 196617 pak param perturb 0. 0. 0.;
#P flonum 220 121 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 122 140 109 196617 pak param specular 0.;
#P newex 18 337 163 196617 jit.gl.handle stock @auto_rotate 1;
#B color 5;
#P flonum 264 76 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 228 76 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 192 76 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 122 100 153 196617 pak param LightPosition 0. 0. 0.;
#P newex 18 297 235 196617 jit.gl.shader stock @file ab.bmap.jxs @name bump;
#B color 5;
#P newex 330 280 154 196617 jit.gl.texture stock @name tex1;
#B color 5;
#P newex 18 358 385 196617 jit.gl.gridshape stock @shader bump @dim 30
30 @shape torus @texture tex1 tex2;
#P toggle 165 417 15 0;
#P message 165 434 44 196617 fsaa $1;
#P toggle 87 417 15 0;
#P message 87 434 77 196617 depthbuffer $1;
#P message 18 434 68 196617 fullscreen $1;
#P toggle 18 417 15 0;
#P newex 18 398 35 196617 sel 27;
#P newex 18 379 40 196617 key;
#P newex 18 459 156 196617 jit.window stock @size 640 480;
#P toggle 16 29 15 0;
#P newex 16 49 51 196617 qmetro 5;
#P newex 16 71 50 196617 t b erase;
#P newex 16 100 92 196617 jit.gl.render stock;
#P comment 666 193 107 196617 scale of noise function;
#P connect 32 0 16 0;
#P connect 27 0 16 0;
#P connect 24 0 16 0;
#P connect 17 0 16 0;
#P connect 22 0 16 0;
#P connect 36 0 40 0;
#P connect 36 0 40 1;
#P connect 36 0 40 2;
#P connect 36 0 40 3;
#P fasten 2 1 1 0 61 93 21 93;
#P connect 2 0 1 0;
#P connect 3 0 2 0;
#P connect 41 0 34 0;
#P fasten 42 0 39 0 379 131 335 131;
#P connect 43 0 42 0;
#P connect 38 0 15 0;
#P connect 40 0 38 0;
#P connect 21 0 14 0;
#P connect 35 2 36 2;
#P connect 35 1 36 1;
#P connect 35 0 36 0;
#P connect 37 0 36 3;
#P connect 34 0 39 0;
#P connect 39 0 35 0;
#P connect 31 0 24 4;
#P connect 13 0 12 0;
#P connect 26 0 24 3;
#P connect 30 0 27 4;
#P connect 25 0 24 2;
#P connect 29 0 27 3;
#P connect 11 0 10 0;
#P connect 28 0 27 2;
#P connect 23 0 22 2;
#P fasten 12 0 5 0 170 456 23 456;
#P fasten 10 0 5 0 92 456 23 456;
#P connect 9 0 5 0;
#P connect 8 0 9 0;
#P connect 7 0 8 0;
#P connect 6 0 7 0;
#P connect 33 0 32 2;
#P connect 20 0 17 4;
#P connect 19 0 17 3;
#P connect 18 0 17 2;
#P connect 4 0 3 0;
#P window clipboard copycount 45;


doing bump-mapping the dumb way







< ![CDATA[

varying vec3 N;
varying vec3 P;

varying vec3 LV;
varying vec3 VV;
uniform vec3 LightPosition;
varying vec2 texcoord0;

varying vec2 texcoord1;

void main (void)

{
//get the vertices into eye space
P = (gl_ModelViewMatrix*gl_Vertex).xyz;

//get the normals into eye space
N = normalize(gl_NormalMatrix*gl_Normal);//standard Normal transform
LV = normalize(LightPosition-P);//Light Vector
VV = normalize(-P);//Vertex Vector

gl_Position = ftransform();
//do the standard transform
texcoord0 = vec2(gl_TextureMatrix[0] * gl_MultiTexCoord0);
texcoord1 = vec2(gl_TextureMatrix[1] * gl_MultiTexCoord1);

}
]]>

< ![CDATA[

varying vec3 N;
varying vec3 P;
varying vec3 LV;
varying vec3 VV;
varying vec2 texcoord0;

varying vec2 texcoord1;

uniform float specular;

uniform float diffuse;
uniform vec3 perturb;
uniform vec4 color;
uniform sampler2DRect tex0;

uniform sampler2DRect tex1;

void main (void)
{
vec4 a = texture2DRect(tex0,texcoord0);//the "bump" map
vec4 b = texture2DRect(tex1,texcoord1);//texture map
vec3 nD = normalize(N);//normalize normals again per-pixel

//add scaled perturbance value to normal vector
nD = N+(vec3(a.xyz*vec3(2.)-vec3(1.))*perturb);

vec3 rV = reflect(-LV,nD);//reflection vector
float spec = clamp(dot(rV,VV), 0., 1.);//specular calculation

//do lighting calculations
float intensity = diffuse*max(dot(LV,nD),0.0) + specular*spec;
//apply texture,lighting + color
gl_FragColor = vec4((color.rgb+b.rgb)*vec3(intensity),color.a*b.a);
}
]]>


December 11, 2006 | 9:11 pm

> Because we don’t automatically generate vertex tangents for our
> geometry, doing true bump-mapping in Jitter is going to be difficult,

FWIW, there’s a vertex_attr_matrix function in jit.gl.mesh that will
allow arbitrary data to be passed in per-vertex. I can post an
example later.

wes


December 14, 2006 | 10:29 pm

wow, guys, that’s very cool. thank you!

On Dec 11, 2006, at 4:05 PM, Andrew Benson wrote:

> >any online examples? and are you thinking of
> providing >some bumpmap jxs in the next jit.release
?
>
> Because we don’t automatically generate vertex tangents for our
> geometry, doing true bump-mapping in Jitter is going to be
> difficult, and will require passing in the data via a texture,
> using pre-cooked geometry data. However, you can do a sort of good-
> enough-for-experimental-video version of it by passing in a Normal
> perturbation map as a texture. Below you’ll find an example
> shader, along with a patch to use it. As always, watch out for
> mail formatting garbage.
>
> Enjoy,
> Andrew B.
>
> #P window setfont "Sans Serif" 9.;
> #P window linecount 1;
> #P comment 391 76 127 196617 bang to generate bump map;
> #P button 374 76 15 0;
> #P newex 374 102 368 196617 jit.gl.gridshape stock @dim 30 30
> @matrixoutput 1 @automatic 0 @shape torus;
> #P number 331 76 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P newex 330 233 53 196617 jit.pack 4;
> #P newex 330 135 177 196617 jit.matrix 3 float32 30 30 @interp 1;
> #B color 5;
> #P newex 330 255 68 196617 jit.normalize;
> #P flonum 654 175 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P window linecount 2;
> #P newex 330 193 335 196617 jit.expr @expr "noise.simplex(in[3]*in
> [0]\, in[3]*in[1]\, in[3]*in[2])" @inputs 4;
> #P window linecount 1;
> #P newex 330 156 334 196617 jit.unpack 3;
> #P window linecount 2;
> #P message 331 102 41 196617 dim $1 $1;
> #P flonum 214 209 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P window linecount 1;
> #P newex 122 228 102 196617 pak param diffuse 0.;
> #P flonum 215 161 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P flonum 219 250 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P flonum 183 250 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P flonum 147 250 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P newex 123 273 130 196617 pak param color 0. 0. 0. 0.;
> #P flonum 179 161 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P flonum 143 161 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P newex 122 185 129 196617 pak param perturb 0. 0. 0.;
> #P flonum 220 121 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P newex 122 140 109 196617 pak param specular 0.;
> #P newex 18 337 163 196617 jit.gl.handle stock @auto_rotate 1;
> #B color 5;
> #P flonum 264 76 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P flonum 228 76 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P flonum 192 76 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P newex 122 100 153 196617 pak param LightPosition 0. 0. 0.;
> #P newex 18 297 235 196617 jit.gl.shader stock @file ab.bmap.jxs
> @name bump;
> #B color 5;
> #P newex 330 280 154 196617 jit.gl.texture stock @name tex1;
> #B color 5;
> #P newex 18 358 385 196617 jit.gl.gridshape stock @shader bump @dim
> 30 30 @shape torus @texture tex1 tex2;
> #P toggle 165 417 15 0;
> #P message 165 434 44 196617 fsaa $1;
> #P toggle 87 417 15 0;
> #P message 87 434 77 196617 depthbuffer $1;
> #P message 18 434 68 196617 fullscreen $1;
> #P toggle 18 417 15 0;
> #P newex 18 398 35 196617 sel 27;
> #P newex 18 379 40 196617 key;
> #P newex 18 459 156 196617 jit.window stock @size 640 480;
> #P toggle 16 29 15 0;
> #P newex 16 49 51 196617 qmetro 5;
> #P newex 16 71 50 196617 t b erase;
> #P newex 16 100 92 196617 jit.gl.render stock;
> #P comment 666 193 107 196617 scale of noise function;
> #P connect 32 0 16 0;
> #P connect 27 0 16 0;
> #P connect 24 0 16 0;
> #P connect 17 0 16 0;
> #P connect 22 0 16 0;
> #P connect 36 0 40 0;
> #P connect 36 0 40 1;
> #P connect 36 0 40 2;
> #P connect 36 0 40 3;
> #P fasten 2 1 1 0 61 93 21 93;
> #P connect 2 0 1 0;
> #P connect 3 0 2 0;
> #P connect 41 0 34 0;
> #P fasten 42 0 39 0 379 131 335 131;
> #P connect 43 0 42 0;
> #P connect 38 0 15 0;
> #P connect 40 0 38 0;
> #P connect 21 0 14 0;
> #P connect 35 2 36 2;
> #P connect 35 1 36 1;
> #P connect 35 0 36 0;
> #P connect 37 0 36 3;
> #P connect 34 0 39 0;
> #P connect 39 0 35 0;
> #P connect 31 0 24 4;
> #P connect 13 0 12 0;
> #P connect 26 0 24 3;
> #P connect 30 0 27 4;
> #P connect 25 0 24 2;
> #P connect 29 0 27 3;
> #P connect 11 0 10 0;
> #P connect 28 0 27 2;
> #P connect 23 0 22 2;
> #P fasten 12 0 5 0 170 456 23 456;
> #P fasten 10 0 5 0 92 456 23 456;
> #P connect 9 0 5 0;
> #P connect 8 0 9 0;
> #P connect 7 0 8 0;
> #P connect 6 0 7 0;
> #P connect 33 0 32 2;
> #P connect 20 0 17 4;
> #P connect 19 0 17 3;
> #P connect 18 0 17 2;
> #P connect 4 0 3 0;
> #P window clipboard copycount 45;
>
>
>
>
> doing bump-mapping the dumb way
>
>

>

>

>

>

>
>

>

>
>
>
>
>
>
>
>
>
>

> < ![CDATA[
>
> varying vec3 N;
> varying vec3 P;
>
> varying vec3 LV;
> varying vec3 VV;
> uniform vec3 LightPosition;
> varying vec2 texcoord0;
>
> varying vec2 texcoord1;
>
>
> void main (void)
>
> {
> //get the vertices into eye space
> P = (gl_ModelViewMatrix*gl_Vertex).xyz;
>
> //get the normals into eye space
> N = normalize(gl_NormalMatrix*gl_Normal);//standard Normal transform
> LV = normalize(LightPosition-P);//Light Vector
> VV = normalize(-P);//Vertex Vector
>
> gl_Position = ftransform();
> //do the standard transform
> texcoord0 = vec2(gl_TextureMatrix[0] * gl_MultiTexCoord0);
> texcoord1 = vec2(gl_TextureMatrix[1] * gl_MultiTexCoord1);
>
> }
> ]]>
>
>

> < ![CDATA[
>
>
> varying vec3 N;
> varying vec3 P;
> varying vec3 LV;
> varying vec3 VV;
> varying vec2 texcoord0;
>
> varying vec2 texcoord1;
>
> uniform float specular;
>
> uniform float diffuse;
> uniform vec3 perturb;
> uniform vec4 color;
> uniform sampler2DRect tex0;
>
> uniform sampler2DRect tex1;
>
>
> void main (void)
> {
> vec4 a = texture2DRect(tex0,texcoord0);//the "bump" map
> vec4 b = texture2DRect(tex1,texcoord1);//texture map
> vec3 nD = normalize(N);//normalize normals again per-pixel
>
> //add scaled perturbance value to normal vector
> nD = N+(vec3(a.xyz*vec3(2.)-vec3(1.))*perturb);
>
> vec3 rV = reflect(-LV,nD);//reflection vector
> float spec = clamp(dot(rV,VV), 0., 1.);//specular calculation
>
> //do lighting calculations
> float intensity = diffuse*max(dot(LV,nD),0.0) + specular*spec;
> //apply texture,lighting + color
> gl_FragColor = vec4((color.rgb+b.rgb)*vec3(intensity),color.a*b.a);
> }
> ]]>
>
>

>
>


December 15, 2006 | 1:49 am

HOww do I make that bottom half into a jxs? I tried pasting in a max text and saving but didn’t load.

Thanks though!


December 15, 2006 | 12:03 pm

On 12/14/06, Nicholas C. Raftis III wrote:
>
>
> HOww do I make that bottom half into a jxs? I tried pasting in a max text
> and saving but didn’t load.

make a new text file in your favorite text editor, paste the jxs text in,
and name the file something that ends in .jxs. andrew’s example patch looks
a for a file called "ab.bmap.jxs" so yo umight call it that and put it in
your max path.

all my best,
jonathan


December 15, 2006 | 2:12 pm

Sorry if I wasn’t explicit enough, but thats what I did and it doesn’t load.


December 15, 2006 | 2:16 pm

did you name the file as same as the file the jit.gl.shader @file
declaration?

On Dec 15, 2006, at 9:12 AM, Nicholas C. Raftis III wrote:

>
> Sorry if I wasn’t explicit enough, but thats what I did and it
> doesn’t load.
> –
> -=ili!ili=- http://www.Axiom-Crux.net -=ili!ili=-

v a d e //

http://www.vade.info
abstrakt.vade.info


December 15, 2006 | 3:19 pm

As I said, I did that.


December 15, 2006 | 3:24 pm

error jit_xml_document: error reading file at byte offset 1/ syntax error
error line (1) : varying vec3 N
error:jit.gl.shader : error reading shader xml file "blablabla/ab.bmap.jxs"

blabla = filepath


December 15, 2006 | 5:21 pm

As many of us have stated previously on the forum, you have to be
careful with copying shader files because many browsers and email
clients will try to parse the xml, or you’ll get some bad line breaks
due to document formatting.

You might have a look at other shader files on your machine and see if
it looks the same. If you can’t work it out, one of us can send you the
file offlist.

Cheers,
Andrew B.


December 23, 2006 | 7:59 am

Thanks, thats really cool! Do you have any specular ones or any other really cool shaders? Any resources on the net to download? I would love to get a nice realtime muted reflection if thats possible (I.E. Ibook plastic/Bjork Chris cunningham video) or something of the sort


March 30, 2009 | 1:08 am

I just went back to this file which I found on my drive, and realized I had never gotten it working, now that I know whats going on with shaders a bit, I realized that the java part which encompases the jitter param bindings isn’t there. Is there a way someone could post the shader with all the java stuff in a jsx file?


March 30, 2009 | 3:58 pm

i assume you mean xml, not java.
i’ve found that if you quote the original post (pressing the quote button as if you wish to reply) the jxs will appear un-munged.


     doing bump-mapping the dumb way

	
     	
     	
     	
     	

	
     	
     
    			
    			
    			
    			

			
			
			
         
< ![CDATA[

varying vec3 N;
varying vec3 P;

varying vec3 LV;
varying vec3 VV;
uniform vec3 LightPosition;
varying vec2 texcoord0;

varying vec2 texcoord1;

void main (void)

{
     //get the vertices into eye space
	P = (gl_ModelViewMatrix*gl_Vertex).xyz;

     //get the normals into eye space
	N = normalize(gl_NormalMatrix*gl_Normal);//standard Normal transform
	LV = normalize(LightPosition-P);//Light Vector
	VV = normalize(-P);//Vertex Vector

	gl_Position = ftransform();
//do the standard transform
	texcoord0 = vec2(gl_TextureMatrix[0] * gl_MultiTexCoord0);
	texcoord1 = vec2(gl_TextureMatrix[1] * gl_MultiTexCoord1);

}
]]>
         
         
< ![CDATA[

varying vec3 N;
varying vec3 P;
varying vec3 LV;
varying vec3 VV;
varying vec2 texcoord0;

varying vec2 texcoord1;

uniform float specular;

uniform float diffuse;
uniform vec3 perturb;
uniform vec4 color;
uniform sampler2DRect tex0;

uniform sampler2DRect tex1;

void main (void)
{
	vec4 a = texture2DRect(tex0,texcoord0);//the "bump" map
	vec4 b = texture2DRect(tex1,texcoord1);//texture map
	vec3 nD = normalize(N);//normalize normals again per-pixel

	//add scaled perturbance value to normal vector
	nD = N+(vec3(a.xyz*vec3(2.)-vec3(1.))*perturb);

	vec3 rV = reflect(-LV,nD);//reflection vector
	float spec = clamp(dot(rV,VV), 0., 1.);//specular calculation

	//do lighting calculations
	float intensity = diffuse*max(dot(LV,nD),0.0) + specular*spec;
	//apply texture,lighting + color
	gl_FragColor = vec4((color.rgb+b.rgb)*vec3(intensity),color.a*b.a);
}
]]>
         
     

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