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 / Am I Completely Missing Something (Shader Basics)

Author
Message
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 12th Jul 2013 05:34


PirateJohn
14
Years of Service
User Offline
Joined: 4th Aug 2011
Location: California
Posted: 13th Jul 2013 01:52
So has anyone had a chance to look at the code snippet I put up a few posts back? Still having trouble getting the textures to appear, and I want to be able to use a texturing shader in my weightlifting game so that I can make the scoreboard appear to be lit.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 13th Jul 2013 12:44
The shader works fine in Dark Shader so perhaps the problem is the way you've applied the texture in DBPro? Sample code please.
PirateJohn
14
Years of Service
User Offline
Joined: 4th Aug 2011
Location: California
Posted: 14th Jul 2013 11:57
Here's the short program I made for testing shaders.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th Jul 2013 12:51
I see what you mean. I'm obviously missing something very simple too.

I'll investigate when the heat chases me indoors.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th Jul 2013 13:45 Edited at: 14th Jul 2013 13:53
Yes, I missed one important thing. The texture declaration is missing the instruction telling DBPro how to find the texture. You need something like



That works fine when I use a standard DBPro sphere but not when I use the DirectX teapot.x object. Could you check to see what you get as you may be using a different teapot model?

There are other changes I'd suggest for the shader but let's get the texturing issue sorted out first.

In the meantime I'll delve into the teapot.x object.

Edit The teapot object I'm using has all its UV coordinates set to zero so you see just one colour. I'm sure there are others lurking in my files so I'll see if I can find one which has a sensible set of UV values.
GrumpyOne
18
Years of Service
User Offline
Joined: 27th Nov 2007
Location: London, UK
Posted: 14th Jul 2013 14:39
Hey PirateJohn,

I've done a little tutorial on shaders in DBPro here, you might find it useful:

http://forum.thegamecreators.com/?m=forum_view&t=203709&b=6

My suggestion is you take some existing shaders and change them a little to learn how they work.

Best,
Matt

GrumpyOne - the natural state of the programmer

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th Jul 2013 14:50 Edited at: 14th Jul 2013 14:52
OK. I've found a suitable teapot in one of Evolved's shader demos. With the texture declaration fixed I get this:

PirateJohn
14
Years of Service
User Offline
Joined: 4th Aug 2011
Location: California
Posted: 14th Jul 2013 22:18
Yeah, my model is called "teapot" but its actually just a series of shapes that I created and named "teapot." I'll try your code and see what happens.
PirateJohn
14
Years of Service
User Offline
Joined: 4th Aug 2011
Location: California
Posted: 14th Jul 2013 22:24
Ah, great, it worked.

One question, though... In the game I'm making, I want to make a scoreboard that has its own lighting effects. The way I'm making the scoreboard is to capture a screen image and texture the scoreboard with that image. Therefore, there is no actual file that contains the image. So how would I write the shader to use a texture that doesn't exist as a file?

Do I need to save the image to a file after I capture it, then reference that file name? I'm sure that would work but wouldn't be very efficient as it would require a lot of I/O from the hard drive.
PirateJohn
14
Years of Service
User Offline
Joined: 4th Aug 2011
Location: California
Posted: 14th Jul 2013 22:28
Here's the code that shows how I am texturing the scoreboard in the game:

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th Jul 2013 22:48
The shaders you are using here use image ids not file names so they can be camera screenshots, etc. The need for the "string name = "" " bit in the shader texture declaration is one of those behind the scenes things that only C++ programmers understand. It's quite beyond me I'm afraid. All I know for certain is that DBPro needs that - and it needs a filename name between the quotes if you set the texture flag on the load effect command (I wouldn't advise doing that though for obvious reasons).

In other words



is all you need if the shader expects the image on stage 0. When using shaders I usually use the following to make the stage connection obvious:



But if the shader expects only one texture then the former will usually be OK.
PirateJohn
14
Years of Service
User Offline
Joined: 4th Aug 2011
Location: California
Posted: 15th Jul 2013 00:11
So, then, if I'm sending a texture from the screenshot using the TEXTURE OBJECT 24, 25 command that I use, then do I have to include a file name in the string name = "" line? Or is there a different line of code that I write in the shader to tell it to use the image stored in memory?

Thanks again for all your help!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Jul 2013 03:20
No. The textures are assigned to "texture stages" using the DBPro texture object command: e.g.



That sequence of commands assigns images 3, 5 and 6 to texture stages 0, 1 and 2 of object 10. In DBPro the first three textures declared in the shader would be assigned to those three stages in order, i.e. image 3 would be assigned to the first texture declaration, 5 to the second and so on. As I said before

Quote: "and it needs a filename name between the quotes if you set the texture flag on the load effect command (I wouldn't advise doing that though for obvious reasons).
"


In other words, most of the time you don't need a filename (and I would advise against hard-coding it in the shader).
PirateJohn
14
Years of Service
User Offline
Joined: 4th Aug 2011
Location: California
Posted: 15th Jul 2013 03:42
Okay, so if I'm understanding you properly, my DBPro code should look like:



and my shader code should look like:



with the string name left blank?
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Jul 2013 16:53
Yes.
PirateJohn
14
Years of Service
User Offline
Joined: 4th Aug 2011
Location: California
Posted: 16th Jul 2013 20:37
Okay, thanks. I'll try that later today in my lifting game and post a screenshot
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 16th Jul 2013 21:06 Edited at: 16th Jul 2013 21:06
Also, just a side note:



If you're using DarkShader, you can add various attributes to your variables and textures within the <> symbols. I don't know if there are other shader editors which support this, or if you can even access these attributes from within your game, but here's an example on how to tell DarkShader to let you change the value of a float using a slider:



No idea where the documentation for this is.

TheComet

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Jul 2013 00:44
Quote: "No idea where the documentation for this is."


Let us know when you find out.

Sometimes it's just simplest to copy things you know work. Not completely satisfactory I know but it'll get you a long way.
PirateJohn
14
Years of Service
User Offline
Joined: 4th Aug 2011
Location: California
Posted: 17th Jul 2013 02:25
Quote: "Sometimes it's just simplest to copy things you know work."

That's SOP for me, especially considering that I'm making an Olympic Games simulator and there are a lot of common elements between games.
PirateJohn
14
Years of Service
User Offline
Joined: 4th Aug 2011
Location: California
Posted: 17th Jul 2013 02:46
Hmm, the scoreboard is just flat black. It's not getting the texture information from DBPro. Do I have to create UV coordinates from inside DBPro or does the shader accept the defaults?

The DBPro code is what I put up earlier and the following is my shader:

PirateJohn
14
Years of Service
User Offline
Joined: 4th Aug 2011
Location: California
Posted: 17th Jul 2013 03:27
Here's a screenshot of the game without the shader applied. As you can see, the scoreboard display looks very dull because I have the ambient light set to zero and am relying on spot lights to light the scene. I tried putting a spot light on the scoreboard but that didn't work at all, so I'm trying to use the shader to make the scoreboard brighter.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 17th Jul 2013 03:30
Try changing the following



To this



TheComet

PirateJohn
14
Years of Service
User Offline
Joined: 4th Aug 2011
Location: California
Posted: 17th Jul 2013 05:45
Tried it. Still blank, I'm afraid... Thanks, though!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Jul 2013 16:33
Quote: "The DBPro code is what I put up earlier and the following is my shader:"


Which of your DBPro code snippets are you using? I can't easily locate the one with a scoreboard.

The one with a teapot works fine.
PirateJohn
14
Years of Service
User Offline
Joined: 4th Aug 2011
Location: California
Posted: 17th Jul 2013 20:09
Here's the DBPro snippet:

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Jul 2013 01:42
Is that the whole program?

That snippet won't do anything interesting at all. Image 25 won't contain anything so is probably just black or perhaps blue. The repeat/until loop will simply paste that blank image repeatedly until you hit the spacekey after which the program will simply load an effect, apply it and then close an instant later. What do you expect to see and why?
PirateJohn
14
Years of Service
User Offline
Joined: 4th Aug 2011
Location: California
Posted: 18th Jul 2013 03:03 Edited at: 18th Jul 2013 03:05
No, it's not the whole program. The whole program is about a thousand lines right now. Basically for about 160 lines previous, I create the image and the program takes a snapshot of it. I know the GET IMAGE command isn't the problem because if I don't use the shader, I can see the image just fine. (See the screenshot I uploaded about five posts up.)

So basically what happens with this code is that the entire screen is the scoreboard until the player presses the space key. That part works just fine.

Here's the very long code that shows how the scoreboard is made:

thenerd
17
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 18th Jul 2013 03:19 Edited at: 18th Jul 2013 03:20
Just a tip for drawing the scoreboard: if you are willing to use matrix1, you can accomplish all of that in realtime without GET IMAGE while still drawing to an image. This relies on three commands:

CREATE IMAGE <imageid> allows you to create a blank image.
DRAW TO TEXTURE <imageid> allows you to redirect 2d drawing operations to a texture, in this case an image you've created with CREATE IMAGE.
DRAW TO BITMAP 0 resets 2d drawing to the main screen.

So you'd just create an image at the start of your program, texture it to your scoreboard object, and then use DRAW TO TEXTURE <imageid> before the scoreboard code and DRAW TO BITMAP 0 after the scoreboard code.

With this, you could draw the scoreboard in the main loop and it could be updated in realtime, because without the slowdown of GET IMAGE the drawing operations will go as fast as the TEXT, BOX and other 2d commands can go.

PirateJohn
14
Years of Service
User Offline
Joined: 4th Aug 2011
Location: California
Posted: 18th Jul 2013 03:57
If I use those commands, though, does that mean that the things I draw won't be drawn to the screen? Because I do want them to appear on the screen, and the amount of time it takes to execute the GET IMAGE isn't really a big deal since the player will spend a moment looking at the screen to know which player is lifting next.
thenerd
17
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 18th Jul 2013 04:11
Well, no, but then you can use paste image to paste the scoreboard image to the screen before each match. You could then use the wait command or create a loop where the player presses a key to continue. Either one of those ideas is better than using the delay from GET IMAGE. This is because different computers will execute this command at different speeds.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Jul 2013 16:31
Quote: "Tried it. Still blank, I'm afraid... Thanks, though!"


Are you saying that the following works



whereas the following is just blank?



Can you post the file "Scoreboard.fx" that you are using?
PirateJohn
14
Years of Service
User Offline
Joined: 4th Aug 2011
Location: California
Posted: 18th Jul 2013 22:18
Right. The first one in which the SET OBJECT EFFECT is not executed works and is what created the image that I uploaded. The problem with that image, though, is that the scoreboard is very dull and I want the display to "pop" a bit more, so I created a shader that has the ambient lighting set to max so that the lighted portions of the scoreboard will be much brighter.

Here is the complete scoreboard.fx shader:

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Jul 2013 03:01
Thanks. I'll check it out tomorrow unless someone beats me to it.
PirateJohn
14
Years of Service
User Offline
Joined: 4th Aug 2011
Location: California
Posted: 19th Jul 2013 04:11
Thanks again! If you're ever in northern California I seriously owe you a beer or three.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Jul 2013 03:09
Just a quick note to say I haven't forgotten this - been very busy with domestic things.

Hope to do better tomorrow.
PirateJohn
14
Years of Service
User Offline
Joined: 4th Aug 2011
Location: California
Posted: 23rd Jul 2013 08:21
Don't worry, I've been busy, too. Trying to get some lesson planning done before the school year starts. Three weeks to go!
ReElectro
22
Years of Service
User Offline
Joined: 4th Oct 2003
Location:
Posted: 27th Jul 2013 03:45 Edited at: 27th Jul 2013 05:53
edit: I was going to ask about the a template that does material and single texturing so I can build upon on it until I actually found FX Composer 1.8 via Google search which pretty much solved the problem because it works with DB Pro(via Dark Shader) unlike version 2.5.
TheKid
13
Years of Service
User Offline
Joined: 7th Feb 2013
Location: California
Posted: 28th Jul 2013 02:59
I am actually creating a shaders tutorial. As soon as I am finished with it, I will forward you the link.
ReElectro
22
Years of Service
User Offline
Joined: 4th Oct 2003
Location:
Posted: 28th Jul 2013 03:13 Edited at: 28th Jul 2013 05:43
Edit: I solved the problem again by just setting a single variable.

I have a couple of more questions..

1. Do I have to load the shader file each time when I want a different effect for each instanced object?

2. Is there a possible way to access the texture "ResourceName" in DBPro code?
PirateJohn
14
Years of Service
User Offline
Joined: 4th Aug 2011
Location: California
Posted: 28th Jul 2013 08:09
Quote: "I am actually creating a shaders tutorial. As soon as I am finished with it, I will forward you the link."


Looking forward to it!
PirateJohn
14
Years of Service
User Offline
Joined: 4th Aug 2011
Location: California
Posted: 29th Jul 2013 01:50
Ah, I finally fixed my shader. Turns out that it was one line of code. I had set the output color as:



but when I looked at it again, I realized that input.Color had never been declared, so when I multiplied it, it came out to zero. I rewrote that line of code as:



and now I have a gloriously bright scoreboard in my arena. I'll post a screenshot later.

Thanks everyone for all your help!
PirateJohn
14
Years of Service
User Offline
Joined: 4th Aug 2011
Location: California
Posted: 29th Jul 2013 02:01
Here are the screen shots. Now the scoreboard is much brighter and looks like it is actually lit up instead of being a dull backdrop.

The first one is what the scoreboard looked like without a shader.
PirateJohn
14
Years of Service
User Offline
Joined: 4th Aug 2011
Location: California
Posted: 29th Jul 2013 02:01
And here is the screenshot with the shader applied.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Jul 2013 15:43
Well spotted! Glad you were able to sort it out yourself. That should give you confidence to do more of this stuff. Good luck with this.

Login to post a reply

Server time is: 2026-07-06 19:00:17
Your offset time is: 2026-07-06 19:00:17