I've been looking into learning how to implement shaders in DBP, and found a link to Evolved's website and downloaded the Parallax Mapping shader from this page;
http://evolveduk.googlepages.com/Shaders_BumpMapping.html.
I tried to get the shader working in a simple example of my own, just a spinning cube program.
Rem Project: ShaderTest
Rem Created: Wednesday, June 17, 2009
Rem ***** Main Source File *****
SET WINDOW OFF
SET DISPLAY MODE 1280,1024,32
SYNC ON
SYNC RATE 60
LOAD IMAGE "IMAGE_COLOR.PNG",1 : image=1
LOAD IMAGE "IMAGE_NRM.PNG",2
LOAD IMAGE "IMAGE_DISP.PNG",3
LOAD EFFECT "ParallaxMapping.fx",1,0
POSITION LIGHT 0,-10,5,-10
SET LIGHT RANGE 0,1000
MAKE OBJECT CUBE 1,5 : object=1
TEXTURE OBJECT 1,0,1
TEXTURE OBJECT 1,1,2
TEXTURE OBJECT 1,2,3
SET OBJECT EFFECT 1,1
DO
POSITION CAMERA -8,0,-8
POINT CAMERA 0,0,0
YROTATE OBJECT 1, OBJECT ANGLE Y(1)+.25
SYNC
LOOP
The program doesn't give me any errors, but it certainly doesn't work. The object just looks dark, which lead me to believe it was an issue with the lighting I implemented, so I copied over all the code from the example that had to do with lighting, and my code looked like this:
Rem Project: ShaderTest
Rem Created: Wednesday, June 17, 2009
Rem ***** Main Source File *****
SET WINDOW OFF
SET DISPLAY MODE 1280,1024,32
SYNC ON
SYNC RATE 60
LOAD IMAGE "IMAGE_COLOR.PNG",1 : image=1
LOAD IMAGE "IMAGE_NRM.PNG",2
LOAD IMAGE "IMAGE_DISP.PNG",3
LOAD EFFECT "ParallaxMapping.fx",1,0
`Make Light
load image "Flare.JPG",20
make object plain 20,50,50
texture object 20,20
ghost object on 20
set object light 20,0
vec = make vector4(1)
MAKE OBJECT CUBE 1,5 : object=1
TEXTURE OBJECT 1,0,1
TEXTURE OBJECT 1,1,2
TEXTURE OBJECT 1,2,3
SET OBJECT EFFECT 1,1
DO
POSITION CAMERA -8,0,-8
POINT CAMERA 0,0,0
`Move Light
if KEYSTATE(38)=1 and MoveLight=1 and nopress=0 then MoveLight=0:nopress=1
if KEYSTATE(38)=1 and MoveLight=0 and nopress=0 then MoveLight=1:nopress=1
if MoveLight=0
ang#=wrapvalue(ang#+0.25)
position object 20,cos(ang#)*90,cos(ang#)*25,sin(ang#)*90
set vector4 1,object position x(20),object position y(20),object position z(20),0
set effect constant vector 1,"LightPosition",1
endif
point object 20,camera position x(),camera position y(),camera position z()
YROTATE OBJECT 1, OBJECT ANGLE Y(1)+.25
SYNC
LOOP
Now the program works perfectly, so I know my lighting code is to blame. But if I ever use this shader in some kind of project, chances are that I won't want the lights to move around. Taking a close look at the code, I think it's probably this line that's important out of the example code:
set effect constant vector 1,"LightPosition",1
I don't really know anything about vectors, or about shaders, so I don't really know what to do. How do I make it so the stationary light I put in the stage works with the shader? And what would I do if I had more than one light?
If you don't want to dig up a texture and a normal map and displacement map for it, I've attached a zip that has one I've prepared. The zip also has Evolved's .fx file and the Flare.JPG referenced in his code.
Any help will be appreciated.
EDIT:
Just to be a bit clearer for those who don't want to download anything, I've attached a couple screenshots.
This is it with my lighting code:
And this is it with the working code from the example:
Oh, and if anyone is interested, that image is just a picture I took a while ago of some graffiti I thought was interesting looking.