Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Shader Problems - Parallax Mapping (EVOLVED)

Author
Message
Zaibatsu
18
Years of Service
User Offline
Joined: 1st May 2006
Location: Lost in Thought
Posted: 19th Jun 2009 04:06 Edited at: 19th Jun 2009 04:14
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.



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:



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:



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.

Attachments

Login to view attachments
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 19th Jun 2009 04:48 Edited at: 19th Jun 2009 04:53
The shader doesn't recognize DBP's default lights, it uses its own lights. To translate DBP lights into the shader lights, you need a vector. While vector has its own mathematical definition, in this case I would describe it as a storage box for a 3D position. So, store your DBP light's position in the vector, then pass the vector on to the shader.

To create the vector needed (it's a vector4 to store X,Y and Z but I'm not sure what the 4th value is-- it may be the light's range), do this:


In his code he uses vector number 1. You could use any vector number but let's just use 1:


I have "null" there because the make vector4(vectornumber) command returns a number for no apparent reason so you have to treat it like it returns something or it won't work. So we just store the returned value in some random variable (here it's called "null" but you could call it whatever you wanted) and move on.

Okay. Now we'll want to put the light's position into that vector so it can be passed on to the shader. To store your light 0's position in vector 1, do this (I'm ignoring W because I thought it was the light's range but your code has it working fine at 0):


Think of a vector as a spaceship of sorts in this case. It carries your three position values from your program's planet to the shader's planet

Finally, you pass the vector on to the shader using SET EFFECT CONSTANT VECTOR. Basically that sets one of the effect's (shader's) constants equal to the values in the vector. We want to change the light's position. In the shader, the light's position variable is called "LightPosition". So, lets make the shader light's position equal to our light 0's position, which we just stored in vector 1.


And that's pretty much it. Whenever you move your light, you'll want to store the light's new position and pass it on to the shader so the shader knows that the light has moved. That's why when EVOLVED moves his light every loop, he calls SET EFFECT CONSTANT VECTOR every loop.

Hope this helps, as I'm no shader guru either . For all the technical stuff you'll have to wait for Green Gandalf or someone .

<-- Spell based team dueling game!
Zaibatsu
18
Years of Service
User Offline
Joined: 1st May 2006
Location: Lost in Thought
Posted: 19th Jun 2009 05:24
Thank you for the help. I've got it working now. What would I do if I wanted to use a light color other than white though?

Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 19th Jun 2009 13:27 Edited at: 19th Jun 2009 13:28
You would have to set the vector equal to your RGB values (the RGB values are floats from 0.0-1.0 instead of integers from 0-255), then pass that into the "LightColor" constant of the shader.

For example, this would be purple:


Here's a light blueish color:


If you really wanted to use the 0-255 RGB values you could do this (here it's like RGB(255,100,55)):


I have the ".0" at the end to ensure that the values are floats. Again I am not sure what that last value does, so I've set it to 0...

<-- Spell based team dueling game!
AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 19th Jun 2009 16:12 Edited at: 19th Jun 2009 16:13
Shaders often have several "tweakables". A tweakable is a variable that can be edited from within DBP. Sixty Squares has just showed you two of the ones that can be found in this shader--"LightPos" and "LightColor"--but many shaders have others, such as "LightRange", "LightDir", "AmbientColor", etc. to allow you to customize the appearance of the shader from within your program. Also the names I gave are just examples--sometimes "LightColor" may be "LightCol", or "LightRange" may be "LR". You'll have to find an example or look in the shader file.

i like orange
Zaibatsu
18
Years of Service
User Offline
Joined: 1st May 2006
Location: Lost in Thought
Posted: 19th Jun 2009 19:14
Thanks for the help, I think I understand enough to get some basic use out of shaders now

Zaibatsu
18
Years of Service
User Offline
Joined: 1st May 2006
Location: Lost in Thought
Posted: 29th Jun 2009 21:30
I've run into another problem with it: Multiple Lights. I tried just using the same code more than once, but it didn't work.



It just uses Light 1's data. When I told it to use light 1, it overwrote light 0, instead of using them both. I need to get multiple lights working, because I'm using this to light a level in a FPS game (which is why the lights are so far away).

Also, does anyone know what kind of license EVOLVED has on his shaders? I couldn't see anything on his site, and the downloads didn't come with a readme.

Butter fingers
18
Years of Service
User Offline
Joined: 20th Mar 2006
Location: Mecca
Posted: 10th Jul 2009 03:53
in the same way that your shader doesn't use DBP light positions, and you have to pass them the values in vectors, it doesn't support as a many lights. Infact, this shaders only supports 1 light.

you can (sort of) get around this, but checking for the light nearest the camera and setting the vector data to the position of the nearest light.

There is a nice normal/specular shader on Evolved site that handles like 7 or 8 lights, thats really your only option for multiple light sources on shaders right now.

I'm going to sit back and wait for someone to come and totally prove me wrong.

I want robotic legs.
Zaibatsu
18
Years of Service
User Offline
Joined: 1st May 2006
Location: Lost in Thought
Posted: 10th Jul 2009 19:24
Quote: "There is a nice normal/specular shader on Evolved site that handles like 7 or 8 lights, thats really your only option for multiple light sources on shaders right now. "


Yeah, I saw that one and tried to get it working, but was never able to.

david w
18
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 14th Jul 2009 07:11
you can do deferred shading and have hundereds of lights. There are examples floating around these forums and they are slightly more complicated to set-up.

Login to post a reply

Server time is: 2024-11-24 03:43:51
Your offset time is: 2024-11-24 03:43:51