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 / Get object position and angle in shader ?

Author
Message
Brightside_
12
Years of Service
User Offline
Joined: 27th Oct 2013
Location:
Posted: 6th Mar 2014 22:58 Edited at: 6th Mar 2014 22:59
Hi guys!
So rather simple question: I need to get object position and object angle inside shader.I mean not vertex position but whole object position and angle which were set inside DBPro.
Thanks
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th Mar 2014 23:14
Just define relevant variables in the shader with suitable default values in the usual way and pass the values to the shader using the commands set effect constant vector or set effect constant float as required.

For example, in the shader you might have:



and in your main DBPro program loop:



The above assumes that vectorId, objectId, etc, have suitable values and that the vector has been defined.



Powered by Free Banners
Brightside_
12
Years of Service
User Offline
Joined: 27th Oct 2013
Location:
Posted: 6th Mar 2014 23:27
@Green Gandalf
not so easy =((( I need to make it only in shader.So I want to have multiple objects and only one shader for them - not individual shader for each object.I think it is possible - shader have information about time, DBPro camera and so on.I think DBPro sends information about object scale and position too.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 7th Mar 2014 01:09
Ah, I see. I'll think again and come back later unless someone beats me to it.

Quote: "I think DBPro sends information about object scale and position too."


Thinking about it I guess you're right - you probably just need to extract the right bits of the world matrix. The scaling might be the top 3x3 part of the matrix and the position the first three elements of the 4th row (or column - not sure off-hand). Simple experimentation should tell you. Anyway, if you haven't already got a solution I'll try to check this tomorrow.



Powered by Free Banners
Brightside_
12
Years of Service
User Offline
Joined: 27th Oct 2013
Location:
Posted: 7th Mar 2014 09:36
Quote: "you probably just need to extract the right bits of the world matrix"
- looks like the only right way.Ill try to make this on these days
Brightside_
12
Years of Service
User Offline
Joined: 27th Oct 2013
Location:
Posted: 7th Mar 2014 21:36 Edited at: 7th Mar 2014 21:39
It works!
Code is pretty simple.



Still can't get object scale and object angle Maybe DBPro dont send this information to shader?
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 7th Mar 2014 23:51
Quote: "Still can't get object scale and object angle Maybe DBPro dont send this information to shader?"


I would expect both those to be part of the World matrix which is partly composed of a scale matrix and a rotation matrix multiplied together. The matrix won't involve the angles directly - it'll be things like the sine and cosine of the angles. There was a thread discussing just this point recently but I forget what the main topic was - or who was involved. Might have been Rudolpho? I'll see if I can find it.



Powered by Free Banners
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Mar 2014 17:32
Failed to find the thread. Perhaps I imagined it.

Anyway, see if this simple demo helps you (attached). It uses one of the Matrix1 functions to extract an object's world matrix and uses that instead of the usual one supplied by DBPro behind the scenes. As you can see the object looks exactly the same as it should regardless of which source you use for the world matrix.

Press t to choose technique t2 rather than t0.

Technique t0 uses the standard DBPro supplied world matrix, whereas t2 uses the one passed to the shader by the program. The program also prints out the world matrix for that object. As you can see, the upper left 3x3 part of the matrix contains the combined effect of scaling and rotation, whereas the first three elements of the bottom row contain the object's position.

If you comment out the set effect constant matrix line you'll see the effect of using the default value for the user supplied world matrix in technique t2.



Powered by Free Banners
Brightside_
12
Years of Service
User Offline
Joined: 27th Oct 2013
Location:
Posted: 8th Mar 2014 19:39
Thanks Green Gandalf!
i also find thread.Looks like you told about

http://forum.thegamecreators.com/?m=forum_view&t=209665&b=1
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Mar 2014 23:48
Quote: "i also find thread.Looks like you told about"


Yes, that's the one.

No idea why I couldn't find it.



Powered by Free Banners

Login to post a reply

Server time is: 2026-07-06 18:12:11
Your offset time is: 2026-07-06 18:12:11