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 / How do you load a .fx file into DBPro?

Author
Message
Cruise McClarren
20
Years of Service
User Offline
Joined: 23rd Aug 2005
Location:
Posted: 21st Jun 2014 19:36 Edited at: 21st Jun 2014 19:55
I've searched and haven't found an answer to this. I've looked at the "Special Effects" project in DBPro and tried to copy it over to my own project. When I try to include the .fx file and run it, my program fails to run. When I eliminate it, it works fine. Here's the code I'm working with. I know it's not an in depth thing as I'm just trying to work things out in stages.

The media is attached as well. Basically I would like the ship to have a shiny metal exterior. Now, I modeled it in Truespace 7.6 and in there, the shiny metal shader looks great. But when I exported it to a .x file and loaded it into DBPro it doesn't have that shine. So I wanted to use the metal.fx shader which in the example code looks like what I want to have. I have added a screenshot from Truespace so you can see what I am after. Thanks for any assistance

LIFE: "That thing that happens to us when we are too young to die"
~V.J.C. 2003
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 21st Jun 2014 23:29 Edited at: 21st Jun 2014 23:31
Just glancing this...

At the top add

SYNC ON
Sync Rate 0 // or 60 or 30 or whatever you like but 0 is as fast as your system can process it

At the top or bottom of your DO : LOOP add SYNC

EDIT

Code block function is not working?

Hello World

yup broken

BMacZero
20
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 22nd Jun 2014 00:01
SYNC ON is not required in DarkBASIC. There's something up with your mesh (.x) file. I tried substituting a different mesh file and the program didn't crash (I assume the crash is the problem you're having).

You might try importing the mesh into a different modelling program and re-exporting it. Or maybe this will help: http://newsfiles.thegamecreators.com/issue71/trueSpace%20for%20DarkBASIC%20Professional.pdf

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 22nd Jun 2014 01:49
It might be worth reducing the vertex count or splitting the object into limbs. Shaders sometimes give problems with high poly meshes.



Powered by Free Banners
Cruise McClarren
20
Years of Service
User Offline
Joined: 23rd Aug 2005
Location:
Posted: 22nd Jun 2014 04:07 Edited at: 22nd Jun 2014 04:16
When I remove the loading of the shader it works fine with the model included. So I don't understand how it can work fine without the shader file being included but once I try to include it either with the SET EFFECT ON command or LOAD EFFECT command to load the effect, it doesn't do anything. I am wondering if maybe there is something that doesn't jive with the combination of the .x file and the shader file.

LIFE: "That thing that happens to us when we are too young to die"
~V.J.C. 2003
wattywatts
17
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 22nd Jun 2014 08:33
If all you're looking for is a metallic shine, you might want to check out the sphere shading command.
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 22nd Jun 2014 12:10
Quote: "When I remove the loading of the shader it works fine with the model included. So I don't understand how it can work fine without the shader"

Could be that your shader expects some per-vertex data element that isn't included in your model by default (normals, tangents, etc.). The default shaders doesn't need this so they will render it fine. Or your shader doesn't compile (this throws no errors during runtime, it just causes everything that uses it not to be rendered at all). You can check that by opening a command prompt and running
fxc "your-shader-file.fx". If it complains that it cannot find a main function, that's quite OK because the techniques work around that, but if it says anything else you should try to fix the shader.

Quote: "Now, I modeled it in Truespace 7.6 and in there, the shiny metal shader looks great."

Chances are the shaders used by TrueSpace, or any other programs, differ from what you can use in DBPro. It can be everything from different shader models to extra constants and/or vertexdata that you have to provide manually.

I took a look at your shader and well... it doesn't look like anything I'm used to with those asm blocks but still. The main thing I see are the constants declared at the top. You're not setting any of those from your DBPro code so you'll essentially give the shader uninitialized world, view and projection matrices (among the other constants) that it will offset your vertices by. As you can imagine this will not do. Either send the matrices to the shader (which will be hard since standard DBPro doesn't allow you to set matrix constants) or change them to use the semantics automatically provided by DBPro (World, View, Projection, ViewProjection, WorldViewProjection, InverseWorldViewProjection and so on - as for inverses, you can inverse matrices in your shader code as well if they're not available from DBPro, however that will generally take more time than if you can just precompute it per mesh / frame. Probably won't matter much in this particular case though).


"Why do programmers get Halloween and Christmas mixed up?"
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 22nd Jun 2014 13:42 Edited at: 22nd Jun 2014 15:21
There's nothing wrong with the shader - and simple basic lighting shaders won't work with his model either.

I'm 95% sure the problem is something to do with the model - but not sure what at the moment.

Edit I've done a bit of experimenting. Your object consists of two meshes. The first mesh consists of about 2000 vertices and represents the cockpit and part of the tail. When I load that as a separate object your program works fine. However, when I try to do the same with the main fuselage, i.e. the second mesh consisting of about 22000 vertices, the program crashes as before. I suspect the combination of a model set up for animation plus a relatively high vertex count is the cause of your problem.

I suggest you try splitting the fuselage into smaller meshes, say 4 or 5, and then try again. There is a known limitation with DBPro in the size of each limb it can handle - and this gets worse with shaders because of the additional vertex data constructed behind the scenes. Whenever I've encountered this sort of issue before, splitting the model into more limbs has solved the problem.

Edit2 Yep. That fixes the problem - see partial screenshot. That used a maximum of about 5000 vertices per limb. I used MilkShape to split the model - takes only a few seconds.





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: 22nd Jun 2014 16:05
Here's a complete version of your model consisting of six meshes. Seems to work fine.



Powered by Free Banners
Cruise McClarren
20
Years of Service
User Offline
Joined: 23rd Aug 2005
Location:
Posted: 22nd Jun 2014 18:55 Edited at: 22nd Jun 2014 18:58
@ Gandalf:

Thank you for figuring it out. For some reason now when I load the split model into the program with the same code as above, the model is solid black as if there is no texture or anything added to it. I thought maybe it was bc there was no light so I added the ambient light command at 100% and white. It still shows black. What am I missing? I will make sure that the models in the future are split and lowered as much as they can be when it comes to polys. Thanks again I really appreciate it.

P.S. : If I wanted to give the user the ability to select a different color for the model while in the program, could I do it with just the COLOR OBJECT command and still have the shader give that metallic look with the new color?

LIFE: "That thing that happens to us when we are too young to die"
~V.J.C. 2003
wattywatts
17
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 22nd Jun 2014 19:37 Edited at: 22nd Jun 2014 20:04
Quote: "the model is solid black as if there is no texture or anything added to it"

Sounds like the UV data was lost. Just need to set it up again.
edit
I just looked at your model, wow that's a lot of vertices..
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 23rd Jun 2014 00:05
Quote: "For some reason now when I load the split model into the program with the same code as above, the model is solid black as if there is no texture or anything added to it."


Guess what - you haven't applied any textures to your model. Load two images in DBPro in the usual way and apply them to the correct stages and you should be fine. I used the "alien.dds" cube map from Dark Shader and an arbitrary stonewall normal map image. I also used set object effect which is much easier.

Here's the code I used:





Powered by Free Banners
Cruise McClarren
20
Years of Service
User Offline
Joined: 23rd Aug 2005
Location:
Posted: 23rd Jun 2014 05:46 Edited at: 23rd Jun 2014 05:58
Thanks fer yer assistance. Also, I guess you can't change the color of the model within the program and then add the shader can you. It would make the program pretty large if I had to create multiple copies of the same model just to have other colors of the model for the user to choose from. Is there a better way than that to do it?

LIFE: "That thing that happens to us when we are too young to die"
~V.J.C. 2003

Login to post a reply

Server time is: 2026-07-06 08:23:01
Your offset time is: 2026-07-06 08:23:01