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 / [STICKY] Learning to write Shaders

Author
Message
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Dec 2006 00:23
@Chris Franklin

Quote: "Sorry to go kinda off topic i set a room on irc up for anyone with shader troubles "


Off topic? Doesn't seem likely. But if the discussion is about shaders generally, i.e. not just for use in DBPro, then you might be right.

@Airslide

Your welcome.

@ both of you

If I didn't take so long composing my posts I might have seen your posts before finally submitting MY posts. Too many visits to the beer fridge, I suspect.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Dec 2006 00:31
@headcrab 53

Quote: "Click on the picture in my sig to see my WIP. That should provide more information."


Rather too much information for this time of night, I'm afraid (it's 11:28pm here) - but VERY nice images though. What makes you think you need MY help? Looks like you're coping well enough already.

I'll still see if I can help though - but not tonight!
Seppuku Arts
Moderator
19
Years of Service
User Offline
Joined: 18th Aug 2004
Location: Cambridgeshire, England
Posted: 4th Dec 2006 00:39
Cool, I'm in a que, I feel special

Just to elaborate on my issue, I assumed it would be something people would have found an answer to, I've seen such works as Chris K's with water and bloom working together, but now as its my next stage to work on my engine, I'm going to put more effort into fixing it.

With the Shader pack, you get Evolved's water shader and his Bloom shader, they seem to conflict with each other, the bloom turns on and off for the water and the water looks funny, now removing the bloom, the water still looks weird, so there I've probably implemented it wrong, I think I'll take the coding from my previous entry attempt to make sure things work for that before trying the bloom again.

All I've really done with it, as Evolved puts his shaders into separate functions, one to set up, the other to update, he does that for both of the bloom and water, that's what I've tried, looking through the code I don't think I have found any reason for them to conflict, but before leaving my work load onto someone else, I'll explore it more.

"Cut down the gods if they stand in your way" - Hakamoto Tsunetomo
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Dec 2006 09:47
@Seppuku Arts

Quote: "Cool, I'm in a que, I feel special"


Trouble is, I'm in it too - and I'm struggling to answer my own questions.

Quote: "but before leaving my work load onto someone else, I'll explore it more."


Thanks, that will probably help.

Just a couple of comments for now.

Not absolutely sure about this, but I suspect you'll need to combine the two shaders into a single shader possibly with several passes if you are trying to apply the effects to the same objects. Perhaps you are already doing this?

Combining the shaders might be awkward because the bloom shaders take a weighted average of several neighbouring pixels (the "blur" part of the shader). So, if you combine the effects in the wrong way, the averaging effect might destroy the water effect or vice versa. You will probably need to think carefully about what's going on at the pixel level - especially things like the order of the various passes and the alphablending. That's quite apart from making sure there aren't any naming conflicts between the two shaders.

If you still need help it would help me if you could post a simplified version of the problem, e.g. only a few objects and images - and don't include the executable in the download (it's easier for me to compile your code here).

Good luck with your investigations.
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 4th Dec 2006 10:55
Hello.

I have been playing with the Vertex Fur shader that Evolved has converted and have been trying to get it applied to my objects.
The trouble is it only makes some of them furry and not all.

This is the shader:

The only thing I have changed is the fur colour.

This is the result:


As you can see there is one furry object which is an asteroid from the DarkMatter1 pack (Which I believe started out as a geosphere). The object above and left of the furry one (the one with leopard spots) should also be furry but it clearly isn't. I am using the same code to apply the shader to all objects so it isn't a coding problem on my part but is instead (I presume) something to do with the way the models are saved. The trouble is, I have no idea what that is.
I don't know how the DarkMatter model was saved but the others I made in 3DS Max 8 and saved as a .X file using the Panda Exporter and the settings I found on this page and then converted them all (asteroid as well) to .DBO's.

Does anyone know what format the models need to be inorder for the vertex fur shader to work correctly?

Thank you

Overdroid
21
Years of Service
User Offline
Joined: 22nd Sep 2002
Location:
Posted: 4th Dec 2006 11:19
GG,
I still haven't been able to get it to work, but I mostly work on the weekend so haven't had time to look at it. Maybe this week I can put some more effort in. I'm exporting my objects from Giles, don't know if that helps. Maybe there is an export option in Giles that will solve the problem.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Dec 2006 12:17
@Scraggle

Quote: "I am using the same code to apply the shader to all objects so it isn't a coding problem on my part but is instead (I presume) something to do with the way the models are saved."


I always hesitate before saying anything as bold as that - but you may be right.

Several queries have cropped up recently relating to things like texture stages, texture stage UV coords, limbs, etc. So you could be right. If you could post some simple example code (or e-mail it to me), with, say, just two objects and their media to illustrate the problem, I'll have a quick look before I tackle the main queue.

In the meantime, have you tried adjusting some of the "tweakables" such as the effect constant "FurHeight"?

Another thing you could try is to write a simple shader which merely accesses the same input variables, i.e.



and then process them in some simple way. That should tell you whether the shader is accessing the input in the way you expect.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Dec 2006 12:28 Edited at: 4th Dec 2006 12:30
@Overdroid

I'm sure the answer to your problem lies in finding out how DBP applies the lightmap to your object - it is obviously not a simple correspondence between the object's standard UV coords and the lightmap image coords. It's possible - and I am guessing - that when the lightmap is prepared, a second set of UV coordinates are applied to the object so that different parts of the lightmap image get applied to the right parts of the object. I can't see how the lightmap gets applied correctly otherwise.

However, I haven't used the kind of lightmaps you are using and can't really help you much more I'm afraid. Might be worth contacting the people who wrote the lightmapping software.

Edit: corrected a nonsensical typo.
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 4th Dec 2006 12:39
I found the problem and a solution. It is one of the things that you have mentioned above. So, thank you.
The problem was the FurHeight. On most of the objects it was too small to notice. The trouble is that increasing it, increases it on ALL objects. Which made some of them have fur that spanned the whole screen, not good!
The solution I have found is to use a different fur shader for each object type. It's not an ideal solution but it does work. However, I might not be keeping the fur shader in the game at all because with it my FPS drops to 27. So, on lower spec machines it would be unplayably slow.

The other odd thing is the colour. Some time I run it and get the orangy-brown colour I would expect from this setting float4 FurColor = {0.67f, 0.58f, 0.3f, 1.0f};. However, most of the time I get a very bright yellow instead. It's very odd.

I got the following images by running the same code twice in succession without changing anything:






clearly something isn't working correctly with the shader ... any ideas?

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Dec 2006 13:41 Edited at: 4th Dec 2006 14:45
@Scraggle

Glad you worked it out.

Quote: "On most of the objects it was too small to notice."


I thought that might be the problem. I had a similar problem with a glow shader. Worked perfectly on my first test object. Then tested it on another object - no glow. Eventually traced it to a problem sililar to yours. It's certainly a pain having to load several copies of the shader just to fix that. I'm not sure if you can access the object's size within the shader - i.e. without passing an effect constant.

You could try modifying the shader code in two ways:

1. The vertex shader contains the following position calculation:



In that snippet you can see that the FurHeight variable is applied to the object's internal "object space" coordinates. Might be worth applying it to the transformed coordinates in "World space" instead - i.e. after applying the World transformation. With luck you might get a more uniform effect across different objects. At the expense of a bit more calculation possibly .

2. You could speed it up by removing some of the passes - do you really need 10? Your objects are quite small so a lot of detail is presumably lost anyway. Try removing the last 3 or 4 passes and see what happens to the visual effect and fps. Try adjusting "FurHeight" as well to compensate.

It would be a shame not to use it somehow - your cat could make an appearance in the game

Edit: No real ideas about the yellow/orange problem though I'm afraid. Might be that the textures are not being accessed correctly so it's a matter of luck what happens to be in the GPU at the time ??

2nd edit: Couldn't resist having a go at this. Try the attached. The revised version implements both suggestions above and is both visually more consistent and faster. You'll need to comment/uncomment two lines in the dba code to see the difference. Have fun.

Attachments

Login to view attachments
Peter H
20
Years of Service
User Offline
Joined: 20th Feb 2004
Location: Witness Protection Program
Posted: 4th Dec 2006 15:12 Edited at: 4th Dec 2006 15:29
Scraggle, could you please post some code to show how you're implementing the fur shader? (and the general size of one of objects too pretty please)

I'm having no luck using it, the objects just show up with their normal texture [edit]now they show up with just static[/edit]... i tried messing around with the fur length, everything from 100.0f (which i don't think is even a legal value heheh) to 0.003f ....

the way i am doing it (my objects are roughly 1 darkbasic unit in size)
setup


application to the hogs


i don't update the light position in the main loop, because there aren't any moving lights... or any light but the default light... (i tried making an extra light to see if that was the problem, but it didn't do anything..)

[edit] i'm looking at Green Gandalf's recently posted code now.

[edit2] ok, using GG's shader i actually got some results... though now all that's happening is that they are covered in "static" a constantly changing version of the rustyiron texture... (i changed the code snippets to what i currently have now) the fur doesn't extend beyond the object's outline at all

One man, one lawnmower, plenty of angry groundhogs.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Dec 2006 16:21 Edited at: 4th Dec 2006 16:25
@Peter H

Try changing the "FurHeight" constant - it needs to be tailored to your particular object's scale (which isn't always obvious when you use objects created in another application). Try halving or doubling the value to begin with. If that doesn't work perhaps you could post simple code plus media (WITHOUT the executable, please ).

Edit: Sorry. Missed the following remark:

Quote: "i tried messing around with the fur length, everything from 100.0f "


You'd better just post the code and media - I'm sure it's a simple fix.
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 4th Dec 2006 16:24
Peter, I would have no problem showing you the code I wrote but I have just lost it!

I made a stupid mistake. I sometimes work on my desktop machine upstairs and sometimes my laptop downstairs. The latest version of my code was on my desktop and I wanted to work on my laptop so I tried to copy it over the wireless network. Trouble is, I transferred the wrong way and copied over my latest version with one from last week.

I will obviously work on it again and let you know when I have it functioning correctly ... watch this space.

Peter H
20
Years of Service
User Offline
Joined: 20th Feb 2004
Location: Witness Protection Program
Posted: 4th Dec 2006 16:43 Edited at: 4th Dec 2006 17:56
don't worry about it lol...

I found out that it was indeed working when i was putting together an example for Green Gandalf and saw it close up, just that it looks like static from a distance (which is the way it is in-game)

so now i'm just trying different textures and texture resolutions to see if i can find one that looks decent.

[edit] bah, can't get it to look nice... i think the shader just wasn't meant for objects that take up tiny amounts of the screen...

i attached a sample with the camera about as far away as it is in-game. but in the game there is a nasty yellow ring around it, and it doesn't look nearly as sharp

One man, one lawnmower, plenty of angry groundhogs.

Attachments

Login to view attachments
Terrorist Zero
17
Years of Service
User Offline
Joined: 29th Aug 2006
Location: Teh YouKai
Posted: 4th Dec 2006 18:03
Real sorry GG, it's the Evolved Flashlight shader you posted for me, that's the one i'm on about.

www.tornupgaming.com
The home of free games and game projects.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Dec 2006 19:31 Edited at: 4th Dec 2006 20:26
@Overdroid, Irradic, Airslide and anyone else having problems with shaders and multi-textured objects

Just had an interesting e-mail correspondence with Paul Johnstone about some of the problems you've been having. It seems there were some bugs with the way UV data was handled in Advanced Terrain and other multitextured objects. In particular, this meant that shaders didn't work correctly - especially those which used the "tangent", "binormal" and "normal" vectors as input to the vertex shader (like the various bump-mapping shaders and Evolved's grass shader). Paul thinks the bugs were fixed - but I've sent him a demo which fails on my machine (I'm using U6.2 - it's possible it's been fixed for U6.3). Paul is on the case.

If a fix isn't available yet, workarounds may be available. For example, I posted a workaround for Advanced Terran in connection with the flashlight shaders. A different workaround may be possible for Overdroid's problem with lightmapping.

In a way I guess this is all good news...

I attach the example I sent to Paul. It uses some code and media from Overdroid's lightmapping problem. The following is an extract from what I've sent to Paul:

Quote: "If you run the program you should see two objects. The one on the left is a lightmapped but untextured version of the object while the one on the right is another version of the same object with a simple shader applied to it. The shader simply modulates the texture and lightmap and then removes the red component
(so you can see it is actually doing something). No problems so far.

Now look at the shader code. You'll see that the input to the vertex shader specifies the tangent, binormal and normal vectors - but does nothing with them. If you uncomment the lines which use those vectors - the calculation should do nothing of consequence really - the UV mapping of the lightmap (stage 1) is broken and just uses the stage 0 UV data so the right hand object looks awful. I am sure this is what is causing Overdroid (and others)
some problems with shaders."


I think I need some of these - and it's only Monday.

Edited silly typo.

*** 2nd Edit: ***

Just heard from Paul. The demo works with the latest Upgrade 6.3 which I have just installed and the lightmapping problem has disappeared, so if you haven't upgraded yet do it now!! (It's easy.)

Attachments

Login to view attachments
Overdroid
21
Years of Service
User Offline
Joined: 22nd Sep 2002
Location:
Posted: 4th Dec 2006 21:57
Dang.
Thanks for at least taking a look GG. The problem is really out of my depth until I can get a better understanding of shaders. I'm pretty sure DBP stores the lightmap texture in the object's second stage, the same place the grass shader stores the displacement map for the grass movement. There are definitely two sets of UV coords, one for the lightmap and one for actual texture map, and once the shader is applied the lightmap coordinates get lost in the shuffle. If you or anyone else here figures it out, let me know.

I wonder if there's any way to contact Ninja Matt.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Dec 2006 22:36
@Overdroid

I fixed your shader for you earlier this evening - have a look at your "Lightmapping and shaders" thread on the main DBPro board. I assumed you'd check there. It does need the U6.3 update though.
Overdroid
21
Years of Service
User Offline
Joined: 22nd Sep 2002
Location:
Posted: 4th Dec 2006 23:15
Doh!
Great - Thanks GG. YOU ROCK.

I only have one more question. How hard would it be to modify the shader so a version of the flashlight shader works on it? And is it worth it or will there be a horrible performance hit?

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Dec 2006 23:51
@Overdroid

That was two questions.

Do you mean in addition to the grass waving effect plus lightmapping? If so, I'd probably build it from scratch in HLSL - and I might use a different method from Ninja Matt. It would be very difficult to modify the shader directly - it's at the instruction count limit already for PS1.4 and I'd probably have to change the instructions to upgrade it to PS2.0. In which case it'd probably be easier to re-write it in HLSL.

I doubt the performance hit will be too bad - the main problem is with things like fur, water and bloom shaders where several passes are required. Many of these shaders have common code so only two or three extra instructions might be needed. [Weird when you compare shaders with our usual DBPro programs - we don't usually care about an extra addition or multiplication. But in a pixel shader such things can make a big difference - because the extra instructions are performed per pixel (roughly) and many times a second.]

Anyway, food for thought - and I'm finished for the day. I'll be back on Wednesday.
Airslide
19
Years of Service
User Offline
Joined: 18th Oct 2004
Location: California
Posted: 5th Dec 2006 01:06 Edited at: 5th Dec 2006 01:06
I just upgraded to 6.3, I'll start testing things out. Thanks for all your help Green.

EDIT: You deserve a medal or something

Irradic
17
Years of Service
User Offline
Joined: 1st Jul 2006
Location:
Posted: 5th Dec 2006 07:48 Edited at: 5th Dec 2006 07:51
Thank you, great that you like the station level. Quiet some time went into the modell. Concerning the loading function, you are right it can be quiet inefficient.
Quote: "You should be able to load the effect once and apply it to each textured object."

I tried this as well,but I have the same problem as you.
I always export as binary, however since we are 2 artists I don't always check in what format my partner exports his modells.
I guess that he exports as text .x files.
If there is a big downside to it I will see to it that all modells are being exported in the same way.
Thanks again and cheers !
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 5th Dec 2006 10:00
@Irradic

Quote: "I tried this as well,but I have the same problem as you.
"


It might be a bug that's fixed by U6.3. I'll have another try now that I've got U6.3. If I still can't get it to work I'll try to isolate the problem and report it to Paul or on the Bug board and see what response I get.

However, I'm busy with work today so don't expect much before tomorrow evening (Wednesday) - and there are some other requests in the queue.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th Dec 2006 17:28
@Everyone using shaders and advanced terrain.

Some recent bug fixes in U6.3 have fixed a number of problems with shaders. See my latest post in the following thread for details:

http://forum.thegamecreators.com/?m=forum_view&t=94242&b=1&p=0
Cave Man
17
Years of Service
User Offline
Joined: 22nd Aug 2006
Location: North Carolina, US
Posted: 8th Dec 2006 18:14
Hi. I've been wondering what the saturate function does. It has only one parameter, so i have no idea what it does.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Dec 2006 21:16
@Cave Man

Quote: "I've been wondering what the saturate function does."


It clamps its argument to the range [0,1]. If its argument is a vector (e.g. a float4 in shader jargon) then the clamping is applied to each component. For example, if you applied the saturate function to the vector (0.2, 1.5, -0.1, 0.9) the result would be the vector (0.2, 1.0, 0.0, 0.9). This function is often used to ensure that colour values lie in the range [0, 1] after a calulation. Another use is in lighting calculations where you want incident light to show only on surfaces that are oriented towards the light source, so you might see code such as



in which "normal" is a float3 containing the normal to the surface and "lightDirection" is another float3 containing the lightDirection (assumed to be pointing towards the surface).

In this snippet "diffuseLevel" will take values ranging from 0 to 1 as the angle between the normal vector and minus the light direction vector lightDirection ranges from 90 down to zero (assuming the vectors are normalised first). If the light direction is coming from behind the surface then "diffuseLevel" stays at zero as a result of saturate.

The "clamp" function is a more flexible alternative to saturate and allows you to use target ranges other than [0,1].
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Dec 2006 21:48
OK, time for an update. Let me know if I've overlooked anyone.

State of play as at 3rd Dec 2006 23:14 -

1. Terrorist Zero (hasn't had much detailed help yet).
2. Irradic (but probably not much more that I can do for the present).
3. Seppuku Arts (I might need more info though).
4. headcrab 53 (ditto - but I probably have enough to get started).
5. Overdroid (I think I'm still waiting for a response from him).

New additions:

6. Scraggle.
7. Peter H.
8. Cave Man.

State of play as at 8th December 2006 20:35 -

1. Terrorist Zero (hasn't had much detailed help yet). [Sorry, no progress yet.]
2. Irradic (but probably not much more that I can do for the present). [ ditto ]
3. Seppuku Arts (I might need more info though). [ ditto ]
4. headcrab 53 (ditto - but I probably have enough to get started). [ ditto ]
5. Overdroid (I think I'm still waiting for a response from him). [ SOLVED!!!]
6. Scraggle. [SOLVED - but then Scraggle shot himself in the foot...]
7. Peter H. [Not quite solved?]
8. Cave Man. [ Answered query I hope.]

So, new list is:

1. Terrorist Zero.
2. Irradic.
3. Seppuku Arts.
4. headcrab 53.

Sorry I've been a bit quiet for a few days - been either busy with work or distracted by other things. But the list IS shorter.
Peter H
20
Years of Service
User Offline
Joined: 20th Feb 2004
Location: Witness Protection Program
Posted: 8th Dec 2006 23:33
You're a hero man!

I think i just decided to ditch the fur shader (it would be nice, but doesn't look good in my game...)

Do you know of anyway to... give my Hogs glowing red eyes? I'm thinking possibly a modified bloom shader. It doesn't have to be just their eyes though, it could be their entire body...

anyway, thanks for all the help you've given!

One man, one lawnmower, plenty of angry groundhogs.
Seppuku Arts
Moderator
19
Years of Service
User Offline
Joined: 18th Aug 2004
Location: Cambridgeshire, England
Posted: 8th Dec 2006 23:59
Yeah sorry Gandalf, I got caught up in trying out other normal maps today, other than that, extremely busy with other commitments, I'll see what I can do tomorrow morning to give you more info on the water shaders and then continue with other commitments, as I've got deadlines nearing

"Cut down the gods if they stand in your way" - Hakamoto Tsunetomo
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 9th Dec 2006 02:07 Edited at: 9th Dec 2006 02:09
@Peter H

Quote: "I think i just decided to ditch the fur shader (it would be nice, but doesn't look good in my game...)
"


Fair enough - this things don't always work as well as we would like. Don't forget that my version removed some of the passes for speed - you might get a better effect if you put them back in (but slower). You can also adjust the FurHeight to suit your game, or use another texture (mine was merely an example). Any way, it's up to you.

Quote: "Do you know of anyway to... give my Hogs glowing red eyes?"


Possibly. A simple way would be to apply another texture which matched the hogs' usual texture - but which was, say, black everywhere except for the eyes and make those parts of the texture white. Then add or blend the two images together, with a separate colour for the eyes - which you could pass as a parameter - in the shader. You would probably want to add some code for the basic lighting as well (ambient, diffuse, etc). It could certainly be done.

@Seppuku Arts

Don't worry - we're all in the same position and just do the best we can - the important thing is that we enjoy what we're doing here when we get the chance.

Anyway, enough for now. Let's see what I can come up with over the weekend.

Edit: added comment about textures for Peter H.
Seppuku Arts
Moderator
19
Years of Service
User Offline
Joined: 18th Aug 2004
Location: Cambridgeshire, England
Posted: 9th Dec 2006 10:44
Hey Gandalf (or anybody else ), I've put the whole thing into an isolated piece of code, looking through it, I cannot find anything to best explain why the two shaders should conflict, not even the camera numbers should conflict, as bloom uses number 50 for cameras and water use 30 and 31 cameras, so I am confused myself.

So I've uploaded the project up here and the video below demonstrating issues, I much appreciate your interest to help Gandalf.



"Cut down the gods if they stand in your way" - Hakamoto Tsunetomo

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: 9th Dec 2006 13:12 Edited at: 9th Dec 2006 13:28
@Seppuku

Just downloaded your program and run it. Weird! It was displaying images from my screensaver!!

Something obviously isn't initialised correctly, probably a texture, so the shader just uses whatever happens to be in video memory.

Will investigate - you've aroused my curiousity.

Edit: Found one possible problem - I think you've used an invalid camera number. I believe there can be at most 32 cameras, corresponding to each of the 32 bits in a DWORD. So camera 50 will probably produce unpredictable effects. Will look at this more closely now.
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 9th Dec 2006 13:15
@Seppuku
If you are using 6.3 then you will need to change the camera numbers so that they are consecutive. I am not sure why it was changed in that way but it has been.

Seppuku Arts
Moderator
19
Years of Service
User Offline
Joined: 18th Aug 2004
Location: Cambridgeshire, England
Posted: 9th Dec 2006 13:23 Edited at: 9th Dec 2006 13:30
Oh right, thanks Scraggle, I'll try that.

[edit]
Success! Well the water still looks funky, even with out the bloom shader, which is odd because I had the shader running in my first compo game attempt, I'll investigate why that be (Mind you there are no other objects in the isolated scene, perhaps that's why)

"Cut down the gods if they stand in your way" - Yamamoto Tsunetomo
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 9th Dec 2006 13:50
@Scraggle

Well spotted! I'd forgotten about the change to camera numbering in the recent upgrades (which I installed only a few days ago).

@Seppuku Arts

Quote: "Mind you there are no other objects in the isolated scene, perhaps that's why"


Yes, that's bound to make things look strange because I think the refraction is supposed to use the image of the thing that's under the water - and there ain't any in your demo.
Syncaidius
18
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: United Kingdom
Posted: 9th Dec 2006 15:11 Edited at: 9th Dec 2006 15:13
I've managed to get the fresnal water shader and the bloom shader working perfectly together. Heres are screenshot:


Heres the code I've put together for this:


I've attached the source files, media and the compiled EXE so you can take a look for yourselves.

The only problems I get is with the fresnal water shader. When I set the SYNC RATE to anything other than 0 it seems to kill the framerate. when I set it to zero, i seem to get around 215 frames, but when I set the sync rate to 60 (for example), it seems to drop down to 14 frames per second. Any ideas?

Anyway, I hope this code sort of helps a few people.

EDIT:
Forgot to mention the controls:
- Arrow keys to move camera
- Move mouse to rotate camera

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: 9th Dec 2006 15:52
@DBking

Thanks for that. People should find that useful. I think getting the positioning/scaling of the various cameras and objects right is the key to getting those shaders working properly.

I get an fps of about 7 to 11 with both of those sync settings
Chris K
20
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 9th Dec 2006 18:48
The frame rate drop is because it uses separate syncs to sync individual cameras, but these are still counted in the 'maximum sync per second' set by sync rate.

I think it's either fixed by the latest update, or by using fastsync...

Or you could just multiply the cap by however many cameras you have... I guess you are using 4 cameras (1 main, 1 bloom, 2 water), because 60 / 4 is pretty much 14.

Try sync rate ( 60 * 4 ).

Now back to the joys of STEP...

-= Out here in the fields, I fight for my meals =-
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 9th Dec 2006 21:24 Edited at: 9th Dec 2006 21:40
@Chris K

But sync rate 0 should allow the system to use the maximum rate available. I got 7 to 11 fps with both 60 and 0. Perhaps that means 28 to 44 by your reckoning, so 60 and 0 would give the same result? [I think I've just talked myself into accepting your explanation... ]

Edit: just tried removing all but one of the syncs and fastsyncs from DBking's code - fps increases to just 8 to 13. Suggests all the syncs count so you get a true fps regardless of what the sync is doing. Not sure why the fps increases slightly when I remove the fastsyncs though.
Cave Man
17
Years of Service
User Offline
Joined: 22nd Aug 2006
Location: North Carolina, US
Posted: 9th Dec 2006 21:50
Hi GG. Thanks for replying. i'm gonna start playing around making shaders again. Thanks a ton for all your help

Sunflash
18
Years of Service
User Offline
Joined: 28th Jun 2005
Location: Seattle, Wa
Posted: 10th Dec 2006 08:34
Lol, this stuff is SOOOOOO cunfuzling! I really hope there's a good tutorial for shader creation in the next newsletter! Lol

"I must tell the Queen that a robin has seen Cludd hanging about. No, thats not right. I must tell the robin that Cludd has been hanging the Queen..." -Mossflower.
Chris K
20
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 10th Dec 2006 11:00
What's happening is it's putting an effective clamp at 15 FPS.

What it's actually clamping to is 60 syncs per second, so 4 sync per frame means 15 FPS.

Average computers might not be able to hit 15 FPS anyway, so that clamp will never come into effect.

Try it with a program that your computer can run at 60 FPS...

-= Out here in the fields, I fight for my meals =-
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 10th Dec 2006 12:00 Edited at: 10th Dec 2006 12:40
Quote: "Lol, this stuff is SOOOOOO cunfuzling! I really hope there's a good tutorial for shader creation in the next newsletter! Lol"


I sympathise. But what's "cunfuzling" us at the moment isn't a shader issue, so shader tutorials probably won't help.

Quote: "What it's actually clamping to is 60 syncs per second, so 4 sync per frame means 15 FPS."


You've "cunfuzled" me - what do you mean by "4 sync per frame", or, to put it another way, what's the difference between "frames per second" and "syncs per second".

Quote: "Try it with a program that your computer can run at 60 FPS..."


Try what exactly?

Edit: Well I tried something anyway. The following code compares the effect of doing one sync between each screen fps() call and doing five. I get the same fps in each case (about 210) when I use sync rate 0. When I use sync rate 60 I get about 49 with the single sync per fps call, and only 9 with 5 syncs per fps call. This seems to be in direct conflict with the Help file which says (very cunfuzlingly):

Quote: "This command will get the current frames per second to measure how many times the screen is refreshed
each second. The integer value returned is measured in units of 1/1000th of a second."


I'd love to know what the second sentence means.

Does it mean "the number of times per second that the screen fps() function is called"? That would make sense - and would be a useful measure of a games speed when several separate camera syncs are needed per game loop iteration. But then, why do I get about 200 in each case with sync rate 0? I would expect about 40 in the multiple sync case - unless each masked sync took only about a fifth of the time that a full sync takes.

Either way, it looks like you're right Chris. Thanks.

Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 10th Dec 2006 12:23 Edited at: 10th Dec 2006 12:29
I think what Chris K is getting at is the extra flag on the SET DISPLAY MODE command. If it is set to one then DBP will be synced with the screen refresh, which in most cases is 60Hz (or 60 fps). Using SYNC 4 times in one loop will 'confuse' the issue and the 60fps will be divided by the number of syncs (in this case 4) which gives 15 fps.

At least that is what I think we are all talking about.

Running this code will return 60fps:


While running this code will return 15fps:


Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 10th Dec 2006 12:48 Edited at: 10th Dec 2006 12:52
This is getting really cunfuzling now. Scraggle posted while I was composing my edit.

I have no idea what the effect of the extra flag on set display mode might be - or of the effect of fastsync versus sync. This multiplies the number of combinations to test by 4, so we will have at least 16 different combinations to try out. We could be here all day

Let's get back to shaders - or Scraggle's latest game - to rest our brains.

Quote: "At least that is what I think we are all talking about.
"


I think we can agree on that

Edit: Just looked at Scraggle's code. I got essentially the same result without the extra flag. Still don't know why I don't get the fps reduction if I use sync rate 0 though.
Chris K
20
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 10th Dec 2006 13:24 Edited at: 10th Dec 2006 13:25
OK it's like this...

This code will give out (roughly) 60 FPS:



Whereas this code will give out (roughly) 15 FPS:



screen fps() only counts syncs of camera 0 I think (or maybe writes to the backbuffer, I don't know).

The point is, in one loop, I was syncing 4 fours for every 'proper sync'...

Eh, it's hard to explain.

-= Out here in the fields, I fight for my meals =-
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 10th Dec 2006 14:10
Quote: "The point is, in one loop, I was syncing 4 fours for every 'proper sync'..."


Yes, I get 49 and 12 with your code.

Quote: "screen fps() only counts syncs of camera 0 I think "


Seems plausible, but my question is: why do I get an fps of 313 in EACH case when I use your code with sync rate 0 instead of 60?
Chris K
20
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 10th Dec 2006 14:18
Because it never hits that cap.

Let's imagine that instead of sync rate 0, you said sync rate 10,000

Then the first time it will clamp the FPS whenever it goes above 10,000 (never), and the second time it will clamp the FPS whenever it goes above 2,500 (never).

-= Out here in the fields, I fight for my meals =-
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 10th Dec 2006 15:08 Edited at: 10th Dec 2006 16:31
No - I don't see it.

The following code reports an fps of about 300/num on my system:



It should be obvious that the actual sync rate stays at about 300 per second AND each sync uses camera zero. It's as if the screen fps() command is only counting the immediately preceding sync - hence the apparent fall in fps when screen fps() is only called once every num syncs.

Still don't get the sync rate 0 thing - will think again after lunch.

Edit: Ok, the point seems to be that sync-ing cameras other than camera zero is very fast so setting sync rate 0 will cause "screen fps()" to report (almost) the same fps whether or not additional syncs for other cameras are put in the loop. If additional syncs for camera 0 are put in the loop then "screen fps()" will report progressively smaller values.

This is all consistent with the following rules being applied:

1. "sync rate num" limits the number of times "sync" is called per second - regardless of the camera masking.
2. "screen fps()" only counts the most recent sync to camera 0 between calls.

I think I'll return to shaders - they're much less confusing.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 10th Dec 2006 17:50
@Terrorist Zero

Sorry I've been so long getting back to your query. Just started now - but the code snippet doesn't compile. The problem is lines like the following near the beginning of the snippet:



It's obviously expecting a string array containing filenames - but I can only guess which ones.

Could you post a new snippet - and make sure it compiles with the media you pointed me to earlier (I've got the media)?

Thanks.

Login to post a reply

Server time is: 2024-03-19 02:59:02
Your offset time is: 2024-03-19 02:59:02