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.

DarkBASIC Professional Discussion / Passing lights to a shader? Can anyone figure out what's wrong with this code?

Author
Message
mnemonic
19
Years of Service
User Offline
Joined: 14th Jan 2007
Location: Sweden
Posted: 3rd May 2013 14:41 Edited at: 3rd May 2013 14:45
,,,or at least help me see some bad syntax,, I've been staring mad at this.

here is the code:


the above code is a write-off from the help file of dark shader.

It won't compile the compiler complains about this line:


saying: "Parameter for 'SET VECTOR4' do not match 'VectorResult, X, Y, Z, W"


BEST!

www.memblockgames.com
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd May 2013 18:55
You need to declare the arrays lightred(), etc - and also to give them some values (ambientR etc need values too). That Help file code is incomplete.

One further point to note: for shader use the color values probably need to be in the range 0 to 1 not 0 to 255.
mnemonic
19
Years of Service
User Offline
Joined: 14th Jan 2007
Location: Sweden
Posted: 5th May 2013 23:24
Thanks, I have done what you said, but my object is still black. I must be doing something wrong. This shader requires light according to the description in dark shader, so passing lights to it sounds like a good idea

does the code part for passing the lights need to be in the main loop?

www.memblockgames.com
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th May 2013 00:47
Could you post both the shader and dba code you're using? I'll then take a quick look at it. Sounds like a simple error somewhere.
James H
19
Years of Service
User Offline
Joined: 21st Apr 2007
Location: St Helens
Posted: 6th May 2013 01:31 Edited at: 6th May 2013 02:12
Quote: "It won't compile the compiler complains about this line:

saying: "Parameter for 'SET VECTOR4' do not match 'VectorResult, X, Y, Z, W""


Odd, I just put that specific line into the IDE and hit F4 - compiles fine. Perhaps the upgrade you have installed is different to me - I seem to recall at some stage updates including a number of shader related commands that I think were FPSC specific(maybe for lightmapping that was previously only available buy purchasing Dark Lights?), either way I`m more than sure that at one point in DBP`s life there was a change in shader related commands of some sort.
I do recall having an issue with that particular code in the past on more than one occasion along with a small number of other items that were easily corrected from other project exports from DS, sometimes in dbp code sometimes in shader code. I think you should look into updates aswell as post the full code for DBP`s wonderfull green wizard to take a look at

edit doh! my page didnt fully load so didnt see other posts - do your best to ignore me!
edit2 weird - i put that line in alone yet compiler never threw out error for not having declared array or told me no such function...Oo
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th May 2013 13:07
Sounds like you are using an old update. I'm using U77RC7 which gives the compile error (as it should).
James H
19
Years of Service
User Offline
Joined: 21st Apr 2007
Location: St Helens
Posted: 6th May 2013 14:22
o dear, call it a bad night, I use a program called Always On Top to keep certain windows always on top while I play kingdoms of camelot, last night it was running and the IDE(Indigo) was hiding the window that Indigo uses to inform me of any errors, left my machine on overnight and retried this just now(yes am lazy git) only spotting now that the little window was hidden away
mnemonic
19
Years of Service
User Offline
Joined: 14th Jan 2007
Location: Sweden
Posted: 6th May 2013 15:34
Quote: "Could you post both the shader and dba code you're using? I'll then take a quick look at it. Sounds like a simple error somewhere."


Here they are:

The db code:



and the shader code:



I'm pretty new to shaders so I do not fully master them and therefore I donnot quite understand what I'm doing here (A programmers worst nightmare) so I'm happy and thankful for all the help I can get

www.memblockgames.com
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th May 2013 17:02
Quote: "I'm pretty new to shaders so I do not fully master them and therefore I donnot quite understand what I'm doing here "


No problem. We were all in that state once.

Thanks for the code - I'll check it out and report back later.
James H
19
Years of Service
User Offline
Joined: 21st Apr 2007
Location: St Helens
Posted: 6th May 2013 18:06 Edited at: 6th May 2013 18:59
In a vague attempt to redeem my idiocy;
You need a diffuse texture in texture stage 0, a normal texture in texture stage 1 - without textures you will get just black cube
You need to set the effect technique to DBLight8 to see the lights
All your lights are positioned in a straight line inside the cubes boundaries with same range(not a large enough range) and the same color so you wont see much the way they are currently setup
I could be wrong but setting DB lights as directional won`t affect the shader lights type, think that part needs to be in the shader
Although you did declare arrays for light colour - they are currently not floats which they need to be as GG said values are between 0.0 and 1.0

This is by no means a good example(especially as i havent coloured spheres that mark the light positions very well as light 0 is in use, prob better to hide light 0 and create an 8th db light - Im sure you can do this) but will give you an idea of how things work, use the same shader code you already have and just find a normal and diffuse texture to use;



Edit; In fact there is plenty wrong with my code(ambient instead of ambience for example!!) - suggest you wait on better example from GG though my earlier points are definately worth noting

Edit2; The following is much better, it uses just 6 lights to show clearer more obvious results and is easier to read;


Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 7th May 2013 00:09
Quote: "In a vague attempt to redeem my idiocy"


You have.
James H
19
Years of Service
User Offline
Joined: 21st Apr 2007
Location: St Helens
Posted: 7th May 2013 01:31
Phew!
mnemonic
19
Years of Service
User Offline
Joined: 14th Jan 2007
Location: Sweden
Posted: 7th May 2013 11:45
Cool! Now I've got a cool shaded object on my screen!

But I have some questions:

QUESTION 1:
Why do I have to load the textures in the code? When they already seem to be defined in the shader code?



QUESTION 2:

You have created spheres as emitters for the lights in the db code you provided. Is this necessary to acctualy 'see' the scene lights?

www.memblockgames.com
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 7th May 2013 12:59
Quote: "Why do I have to load the textures in the code? When they already seem to be defined in the shader code?"


You don't have to. You can use this



instead of



The final flag tells DBPro whether or not to use the model's textures or the ones in the shader. Indeed the Help file tells you this - just (). Don't forget to check them now and then.

Quote: "You have created spheres as emitters for the lights in the db code you provided. Is this necessary to acctualy 'see' the scene lights?"


No. That was obviously just a device to make it crystal clear what was going on. In fact a positional light should logically have an object associated with it - e.g. a table lamp, car headlight, a fire, etc. But you don't actually need it - you could just have the light mysteriously emanating from an invisible point in the scene.
nachwaal3ab
13
Years of Service
User Offline
Joined: 7th May 2013
Location:
Posted: 7th May 2013 16:10
Could you post both the shader and dba code you're using? I'll then take a quick look at it. Sounds like a simple error somewhere.

[URL="http://nachwa.com"]العاب ماهر[/URL]
[URL="http://nachwa.com"]hguhf[/URL]

Login to post a reply

Server time is: 2026-07-07 19:35:18
Your offset time is: 2026-07-07 19:35:18