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 / Why do vertex diffuse values get overriden by shaders generating data on load?

Author
Message
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 24th Aug 2018 04:02
Hi

I have attached a project folder containing code which demonstrates that the vertex colours of a loaded 3D object are overridden when generating data upon assigning the shader, which was written for vertex color output for testing purposes.

The code which requires Matrix Utils indicated that an attempt to write the diffuse values back leads to no change whatsoever.

You will have to set the runtime settings in the code as indicated in the comments.

Does anybody know the best solution to get around this problem?



Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 24th Aug 2018 14:51
This issue has been a long-standing bone of contention between me and Lee. Lee doesn't seem to see this is as a bug - I have no idea why despite his explanations . In the end I gave up trying to convince him. The only solution Lee could suggest, which leads to other problems, seems to be to use the DoNotGenerateExtraData flag when loading the shader. I believe this has the unfortunate side effect of requiring you to calculate tangents and binormals in the shader if you need them (except see comments about UV stages below).

I'm not sure whether you can cheat and calculate them in advance and store them in a set of UV s which you can reserve for that specific purpose - I vaguely recall someone pointing out that extra sets of UV data get messed up when you use the DoNotGenerateExtraData flag (which I think is what you're saying). My preferred solution to all this is to avoid using the vertex diffuse altogether and store any required colours in extra sets of UV data and use the default LOAD EFFECT command. I believe that method works - and you have up to 14 slots available for storing floats that way, i.e. UV stages 1 to 7. So if your application doesn't require UV stages 5 and 6, for example, then you could use UV(5) for the RG components and UV(6) for the BA components. A bit messy, but doable.

I don't know the underlying reason for these issues - but I suspect it has something to do with the way DBPro defines it's vertex formats internally and the methods it uses to assign data to them. It might be worth asking Rudolpho to take a look at the code as he might be able to fix it for us.

I could have a look at your project folder if you like - but you'd need to attach it first .
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 24th Aug 2018 14:59 Edited at: 24th Aug 2018 15:00
Quote: "I'm not sure whether you can cheat and calculate them in advance and store them in a set of UV s which you can reserve for that specific purpose "


That sounds like a good idea; I think I'll have to make use of the unused UV slots.

Quote: "I could have a look at your project folder if you like - but you'd need to attach it first"


Lol, browsed the file but did not click upload.

Many thanks

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 24th Aug 2018 15:42
Thanks. Got your code now. Will report back when I've got something useful to suggest.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 24th Aug 2018 16:44 Edited at: 24th Aug 2018 20:07
Chris, I'm not sure if this is the only problem with your code, but does the following slightly amended version work better?

The important lines are the ones marked with

// amended by GG -- ****** --

i.e. I'm fairly sure you intended to store data for every vertex separately.



Oops, sorry Chris, forgot to warn you that I inserted a loop to break the code into sections, just press <spacekey> when the current set of calculations seem to be complete..

Code for loop:

Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 24th Aug 2018 20:15
Indeed, that's an appreciated improvement. Thanks.

I will be using your UV suggestion, at the next opportunity, and will post the outcome.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 24th Aug 2018 20:29
You're welcome and I look forward to hearing how you get on

It's been a while since I looked at this UV stuff with shaders, etc, so some of my comments might be a bit wide of the mark. However, I might be able to help if you still get stuck. It's always annoying to have to use clumsy, non-intuitive, work-arounds to get things working in DBPro - but my experience is that there usually IS a way around such obstacles.
revenant chaos
Valued Member
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 25th Aug 2018 00:45
Hi Chris,
Although DBPro's vertexdata command set doesn't support them, Dx9's FVF system allows for the usage of float1-float4 sized texcoord elements. I've attached an example which shows how to add a float3 texcoord element to an object's FVF, store random colors within it, then render the object using a normal mapping shader.

Attachments

Login to view attachments
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 25th Aug 2018 00:58
I think I will pull this one off, I should easily be able to reference UV1-UV7 in the vertex shader once I get the chance.

Off topic, I remember a while back you created a shader which improves the level of detail of textures when close to the screen, I vagely remember it had something to do with layering a 'detail' texture on top of a base texture. It will be interesting to find out what kind of technique you used. I'm thinking of trying a similar principle with bump maps.

I've recently started using Visual Studio's HLSL extension for editing the .FX files. Should give it or Visual Code a try. I was using notepad++ this stuff for years.
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 25th Aug 2018 01:00
Quote: "I've attached an example which shows how to add a float3 texcoord element to an object's FVF"


That sounds like something I'd need to try out as well.

Lovely.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 26th Aug 2018 00:24 Edited at: 26th Aug 2018 00:39
Chris, I think you're talking about this thread:

https://forum.thegamecreators.com/thread/207224

Some explanation is given on that thread. However, I've since improved the shader to make it easier to use. Let me know if you need help getting it working.
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 26th Aug 2018 16:13
Thanks. I have taken a look at the concept; and will be trying it out to rely more on procedural methods to produce variety of highly detailed materials with efficiently sized image files, preserving more memory.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 26th Aug 2018 22:08
Sounds good.

Login to post a reply

Server time is: 2024-04-26 13:51:12
Your offset time is: 2024-04-26 13:51:12