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 / Shaders variables

Author
Message
Cescano
11
Years of Service
User Offline
Joined: 4th Sep 2014
Location: Italy
Posted: 27th Dec 2014 05:19
Is there a way to change shaders variable written in the shader file?

For example, the normalmap and reliefmap of evolved has some parameters such as light position, color etc.

Is there a way to change the light position without having to make different shaders that will lag the game because of all the different lights added?
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 27th Dec 2014 12:50
Yes, you can; any variable you declare in the global scope (ie. outside of a function) in a shader can be changed in realtime by your program. DBPro only allows for changing booleans, integers, floats, float4's and float4x4's if I recall correctly though, but you should be able to make do with that for the most part.
These shader variables are called constants, which I admit is pretty confusing since they do (and are even supposed to!) indeed change. The naming comes from the fact that their values are constant during a single rendering pass, but you are free to change them at will between render passes. Look up the set effect constant boolean / integer / float / vector / matrix functions in the DBPro help files

Cescano
11
Years of Service
User Offline
Joined: 4th Sep 2014
Location: Italy
Posted: 27th Dec 2014 13:33
the variable i need to change is :

float3 LightPosition={-30000.0f,9000.0f,30000.0f};

I do not know the difference between float3, float4 etc, i only know what a normal float is, how can i change that part (which is wrote in the shader) so that i can change the light position on my game?
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 27th Dec 2014 15:08
You can't (using an unmodified version of DBPro); you'll have to either make it three float variables and set it using set effect constant float, or make it a float4 (where you don't use the fourth component) and set it using set effect constant vector.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 31st Dec 2014 12:20
Quote: "You can't (using an unmodified version of DBPro); "


Not true. See my comment in another thread.



Powered by Free Banners
Cescano
11
Years of Service
User Offline
Joined: 4th Sep 2014
Location: Italy
Posted: 1st Jan 2015 23:04
Gandalf can you explain how to do then? I need to change the lightposition of the light using in the normal map shader, so that if i enter a building the light position is set for example on a lamp, instead of keeping the "sun coordinate" of when i am outside of the building
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Jan 2015 23:29
Yes. Taking your earlier example



and, for example, let's assume the light in the building has position (X, Y, Z) = (500, 50, 200) then you could do the following in DBPro:



That's all you need. (Obviously you'll need to load the shader as fxID, or change the vector ID if you need to, etc.)

An important point to note is that the shader constants are case sensitive so the following would not work in your example:





Powered by Free Banners
Cescano
11
Years of Service
User Offline
Joined: 4th Sep 2014
Location: Italy
Posted: 2nd Jan 2015 00:25
so i can write for example "null = make vector4(1)" at the start of the program (where i set all the variables for example), and use:

"set vector4 1, 500, 50, 200, 0
set effect constant vector fxID, "LightPosition", 1"

as soon as I enter a specific building, then when i quit outside i can reset the light on the sun position doing:

"set vector4 1, -30000, 9000, 30000, 0
set effect constant vector fxID, "LightPosition", 1"

Also, there is a parameter i must change too which in the shader is declared as "float LightRange=70000.0f; ", obviously the range is too big for the light in the building, but in this case its not a float3 but a normal float, how can I change it?
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 2nd Jan 2015 00:39
Quote: "so i can write for example "null = make vector4(1)" at the start of the program (where i set all the variables for example), and use:"


Yes, but we'd all find it a bit less confusing if you used the code tags instead of the quote tags. (Same probably applies to one of my posts. )

Just use something like



if your light range was 40 units for example.



Powered by Free Banners

Login to post a reply

Server time is: 2026-07-06 07:17:51
Your offset time is: 2026-07-06 07:17:51