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
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 3rd Sep 2009 22:46
This thread is huge for a newcomer to DBPro. Too much to go through, and really hard to navigate. A lot of stuff needs moving to the front page. I still have no idea what the difference between a shader, and a Normal is, and how to edit them, and how to portray certain styles of lighting etc.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Sep 2009 01:16 Edited at: 4th Sep 2009 01:21
Quote: "With luck I'll have something to report tomorrow."


The basic idea worked - but needs rethinking. The breakers in the attached screenshot look OK from a distance, but awful close up. In particular, the breakers look very strange along bits of coastline which are nearly straight. May have to go back to my other idea.

Not defeated yet.

Attachments

Login to view attachments
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 4th Sep 2009 10:28
You should use a smoother normal map for the waves when trying things out. It may be misguiding this way.

The above photo looks great, whats wrong with it?

Also that kind of specularity is also misguiding. Its a dark and foggy environment.

There is always one more imbecile than you counted on.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Sep 2009 11:58 Edited at: 4th Sep 2009 12:35
Quote: "You should use a smoother normal map for the waves when trying things out. It may be misguiding this way. "


Yes, I agree they're not in balance - but that's more of a tweak.

Quote: "The above photo looks great, whats wrong with it?"


I'm a perfectionist.

Seriously though, the breaker texture near the camera is thinly stretched along the shore - although it isn't very obvious in that screenshot. Also it tends to be very blocky which shows close up. I'm now working on a variation which may be better - and is simpler too. I'll post a new screenshot soon.

Quote: "Also that kind of specularity is also misguiding. Its a dark and foggy environment."


Good point - but that is just a matter of adjusting one of the shader "tweaks". I'm more concerned with getting the logic right at this stage (and it isn't yet) - tweaking the various constants comes later.

Edit Here's a screenshot using the latest version. I've got rid of the blockiness that was present in yesterday's version - but still have problems with differing levels of stretching of the foam texture (see areas A and B). The only solution I can think of at the moment would require a specially prepared image as a lookup texture for the "V" coordinate of the foam image. I think this would work but I'm reluctant to go down this route because it would need to be calculated from the heightmap and would take some time to write the program . But I've done that sort of thing before.

Attachments

Login to view attachments
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 4th Sep 2009 12:39
IN the picture, (A) gives a random look and its great. Please share the current version so we can all play with it with different textures.

There is always one more imbecile than you counted on.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Sep 2009 13:31
Here you are. Have fun.

Attachments

Login to view attachments
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 5th Sep 2009 13:44
What i see is very different from the photo you posted above. All i see is pixels changing colors rapidly on the shore(Breakers) And again i had to xrotate the water plain to orient it to the terrain.

Howcome it works for you otherwise?

There is always one more imbecile than you counted on.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 5th Sep 2009 14:06
Quote: "What i see is very different from the photo you posted above."


Were you in the same position in the scene?

Quote: "All i see is pixels changing colors rapidly on the shore(Breakers)"


That's all I would expect to see! Perhaps you could post a screenshot to show what you mean?

Quote: "And again i had to xrotate the water plain to orient it to the terrain."


Which update are you using? I explained this several posts back.

Quote: "Howcome it works for you otherwise?"


I don't think it does work yet - which is why I didn't post the latest demo till you asked for it.

I think it might be easier to modify my original idea.
Monk
16
Years of Service
User Offline
Joined: 25th Sep 2008
Location: Standing in the snow =D
Posted: 5th Sep 2009 17:15 Edited at: 5th Sep 2009 17:31
Quote: "This thread is huge for a newcomer to DBPro. Too much to go through, and really hard to navigate. A lot of stuff needs moving to the front page. I still have no idea what the difference between a shader, and a Normal is, and how to edit them, and how to portray certain styles of lighting etc."

It is huge to a newcomer, but then again, what newcomer should start with shaders?

A shader is a mini program which acts on a pixel or a vertex to create some coll weird effects, and a normal is a number between 1 and 0 which shows which direction a vertex is pointing in. Eg, a normal of [0.5,0,0.5] is a vertex of a wall pointing at 45 degrees (NW).
A shader can be edited by any text program (I believe... I use notepad =) ) as long as you have knowledge of whatever language it is (HLSL?).
I dont know anything about styles of lighting =S

That comes from me having read very little of this thread, just read what you can and you pick bits up eventually.

Edit: GG,
Just tried the shader demo you posted above and it seems to me as if the breakers are trying to find their way around objects on the shore.
A screenshot is posted, but on my pc, the texture stretched around a seemingly invisible box and then as it passed it, the texture shrunk back to normal and continued up to the shore. The screenshot shows just two boxes on that part of the shoreline, but further round to the right, a larger section of shore seemed to have more objects closer to the shore which could be why the breakers seem wrong at the shoreline.
Just a suggestion...

Attachments

Login to view attachments
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 5th Sep 2009 17:52 Edited at: 5th Sep 2009 17:54
Do I need a dll to run these shader demos, DBPro doesn't recognise most of the commands in the file?

Like ...

Make Object terrain 1

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 5th Sep 2009 18:08 Edited at: 5th Sep 2009 18:43
Quote: "Edit: GG,
Just tried the shader demo you posted above and it seems to me as if the breakers are trying to find their way around objects on the shore.
A screenshot is posted, but on my pc, the texture stretched around a seemingly invisible box and then as it passed it, the texture shrunk back to normal and continued up to the shore. The screenshot shows just two boxes on that part of the shoreline, but further round to the right, a larger section of shore seemed to have more objects closer to the shore which could be why the breakers seem wrong at the shoreline.
Just a suggestion..."


Yes, I get those problems too.

The problem is not invisible objects but the way I've calculated the "U" coordinate of the "foam" or "breaker" texture. I think I've cracked the problem of getting the breakers correctly oriented to the shoreline but need to rethink the way I've calculated the final "U" coord. The present method uses the slopes of the heightmap in the X and Z directions to determine the orientation of the shoreline, and then uses this information coupled with the world XZ position of the current pixel to determine how far the pixel is across the breaker image. The method should work fine along straight shores with constant slope [Although I haven't actually checked that it does that - in an ideal world I would. Edit!!! OUCH!! Just spotted a silly error in that part of the shader code. Let's see if that error caused the problem. Edit2: Nope. It certainly made the problem worse - but the main problem is still there. ] but struggles with sharp bends - as you can see if you move the camera around the world.

You also get odd places where the heightmap is uneven which I think is the cause of the "invisible object" problem that you spotted.

I'm using as inspiration the effects shown in King's Bounty which has mostly got the details right (but even commercial games have visual artefacts and errors - see second screenshot from the same game):



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: 5th Sep 2009 18:12
Second screenshot for previous post.

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: 5th Sep 2009 18:26
Pincho Paxton

Quote: "Make Object terrain 1"


That is a command from the Advanced Terrain plug-in DLL which is now part of the DBPro language. If you haven't got it then you must either have a very old version of DBPro or perhaps your copy is corrupt for some reason. Download the latest upgrade, i.e. U7.4, from this page and your problems should be solved:

DBPro release details
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 5th Sep 2009 19:13
Oh.. OK.. I'm using the demo at the moment. Buying the full version on Monday.

revenant chaos
Valued Member
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 6th Sep 2009 15:57 Edited at: 6th Sep 2009 16:11
Hi everyone. I have been working on some modifications for Evolved's deferred shading, and am quite happy with my latest change so I figured I would post some screen shots.

I have modified the system to allow it to render objects with translucency, which is mainly intended for foliage objects.
Since deferred shading takes normals quite seriously, things like tree leaves or grass are drawn with only ambient lighting on their backside (from the light's perspective). The result often looks too dark, and (in certain circumstances) it can increase your awareness that the foliage is actually just transparent plane objects.

The problems are most aparent when the camera is looking at the sun, since the foliage will only be subject to ambient illumination (when the sun should be making the objects glow diffusely).

Attached to this post is the "Before" screen shot.

Attachments

Login to view attachments
revenant chaos
Valued Member
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 6th Sep 2009 16:08
And here is the "After".

Attachments

Login to view attachments
Alfa x
18
Years of Service
User Offline
Joined: 1st Jul 2006
Location: Colombia
Posted: 9th Sep 2009 23:59
really good modification.
The result look much more professional.
Does it runs at a good FPS?.
revenant chaos
Valued Member
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 10th Sep 2009 00:42
Quote: "really good modification. The result look much more professional. "

Thank you.

Quote: "Does it runs at a good FPS?."

Yes, It runs at a manageable FPS. In that screenshot, I was getting between 35 and 40FPS. I am not going to be using the D.O.F. or Glow effects that come with the demo (though it does work with them), so I have a few more FPS to spare. With this effect applied, it runs faster than when either the D.O.F. or Glow are a used alone.

For some reason applying the deferred shading to a scene seems to hit the performance to a certain degree, but then I can add quite a few more objects to the scene without much change in the fps.
For instance, the screenshots I posted had 6 trees (2 separate objects each), and 50 grass objects. Like I said that got me ~35-40Fps (with all the objects on screen), but in my actual project I have quite a bit more objects on the screen (anywhere between 250 and 450) and It still runs at 26-30FPS.

Keep in mind my main project has a custom made LOD/Object recycling system (so that most definitely has an effect) but it also draws the shadows as far as the camera can see so I would assume that is taking up most of the savings.
Alfa x
18
Years of Service
User Offline
Joined: 1st Jul 2006
Location: Colombia
Posted: 10th Sep 2009 16:46
Quote: "Yes, It runs at a manageable FPS. In that screenshot, I was getting between 35 and 40FPS. I am not going to be using the D.O.F. or Glow effects that come with the demo (though it does work with them), so I have a few more FPS to spare. With this effect applied, it runs faster than when either the D.O.F. or Glow are a used alone.

For some reason applying the deferred shading to a scene seems to hit the performance to a certain degree, but then I can add quite a few more objects to the scene without much change in the fps.
For instance, the screenshots I posted had 6 trees (2 separate objects each), and 50 grass objects. Like I said that got me ~35-40Fps (with all the objects on screen), but in my actual project I have quite a bit more objects on the screen (anywhere between 250 and 450) and It still runs at 26-30FPS.

Keep in mind my main project has a custom made LOD/Object recycling system (so that most definitely has an effect) but it also draws the shadows as far as the camera can see so I would assume that is taking up most of the savings."


The result is affordable for certain games, with a recycle system like yours. although, I think some FPS optimization could be better.

Congratulations. Your work is awesome.

I hope to see your main project. Do you have it in a web page?.
revenant chaos
Valued Member
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 11th Sep 2009 01:05
Quote: "The result is affordable for certain games, with a recycle system like yours. although, I think some FPS optimization could be better."

I think so too. While I am not entirely convinced that my lighting calculation is as efficient as it could be (currently looking into this), I think some optimizations/new features on Lee's end could benefit us all. Support for multiple render targets could give us the increase in performance that one would expect from a proper deferred shading setup. Evolved's shaders are quite efficient, and I have only been able to make the most minor of optimizations (which hasn't increased my fps).

I am not making anything which requires and extremely high FPS, and my GPU isn't the greatest (Geforce 9600GT), so I am confident that when this is finished anyone with a somewhat current GPU will be able to play it.

Quote: "Congratulations. Your work is awesome."

Thank you, although most of the awesomeness you see in those screens was downloaded straight from Evolved (shader-wise).

Quote: "I hope to see your main project. Do you have it in a web page?."

I hope you get to see it as well. I don't have a site setup yet, and probably wont for some time. I don't have a team working on this with me, so progress can be slow at times and I cant justify spending time maintaining a site since it would only take more away from my actual game. Though when it gets to an enjoyably playable state I will definitely start a WIP thread.
thenerd
15
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 11th Sep 2009 01:18
Quote: "GPU isn't the greatest (Geforce 9600GT) "


your gpu isn't the greatest? I still use a geforce 6200!!!


forever loading...
revenant chaos
Valued Member
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 11th Sep 2009 02:11 Edited at: 11th Sep 2009 03:52
Quote: "your gpu isn't the greatest? I still use a geforce 6200!!!
"
Yes, I said my GPU isn't the greatest. I didn't say my GPU was old.

Edit: Sorry, I just re-read my post and realized that it might me interpreted as being rude, and I hope you didn't take it that way. After all these forums aren't the best at conveying attitude.
thenerd
15
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 12th Sep 2009 16:58
i never interpeted that as rude.

a geforce 9600 is actually a very good gpu, considering a lot of people (such as me) have older cards...


forever loading...
The Viking
16
Years of Service
User Offline
Joined: 21st Oct 2008
Location: Asgard
Posted: 13th Sep 2009 17:28 Edited at: 13th Sep 2009 20:09
Hey all, I have been playing around with Dark Coder's water shader a bit, and have had an odd problem. It seems that no matter where I position an object, if the water is in sight, it will appear in front of it, even if the object is right against the camera, as in the screenshot. I also have the issue where the object gets "chopped" up, or poly's begin to disappear creating holes, you can see one in the screenshot, but if closer to the water level, it gets much worse. Does anyone have any clue why this is happening. I reduced the number of poly's of the water to make it more usable. Also the bottoms of the waves behind other waves seems to be visible in some cases, which i think is due to the lower number of poly's being used as when there is a higher number it doesn't seem to be present. Thanks all

EDIT: woops... sorry forgot to upload it... here's the screenshot

www.myspace.com/norseblod

Attachments

Login to view attachments
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 13th Sep 2009 20:06
What screenshot?

thenerd
15
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 14th Sep 2009 00:44 Edited at: 14th Sep 2009 00:45
Quote: "EDIT: woops... sorry forgot to upload it... here's the screenshot"

that screenshot.

on older comps it is all distorted like that, on mine the waves and reflection are all .


forever loading...
The Viking
16
Years of Service
User Offline
Joined: 21st Oct 2008
Location: Asgard
Posted: 14th Sep 2009 00:48 Edited at: 14th Sep 2009 01:46
Yeah... as you can see, the object appears behind the water, when it should in fact be seen infront of the water, not behind the horizon. The waves are ok... i am using a lower poly model to make them which made them seem a little more distorted... but the shape which is behind them is what is bothering me, because i cant get it to look like its in the water... it just looks like a giant standing at the edge of the world. And nah, my comp is pretty newish... not great but decently new.

www.myspace.com/norseblod
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 14th Sep 2009 15:13 Edited at: 14th Sep 2009 15:17
Looks like a Z clipping problem. Set camera range might help. the other thing is that you might have accidentally used 2 water models by mistake.

The Viking
16
Years of Service
User Offline
Joined: 21st Oct 2008
Location: Asgard
Posted: 14th Sep 2009 16:43
hmmm, i do have the camera range set. I do have 9 individual planes, so as i scroll along i can have the planes move, and hide and such. Though even with one water plane it still shows the object behind it.

www.myspace.com/norseblod
Colonel_Klink
17
Years of Service
User Offline
Joined: 20th Dec 2006
Location: Within the dark recesses of my mind
Posted: 19th Sep 2009 03:36 Edited at: 20th Sep 2009 04:23
Sorry for interrupting a really interesting thread, but I have a question regarding shaders applied to models with more than one texture map. Is it possible to apply shaders to individual faces on a model?

I have Dark Shader and have played around with it, but it appears to only apply a shader to the complete model, and not parts of it.
Thanks
Bob

Oh my gosh! He's wearing Full Metal Pyjamas!
--------------------------------------------
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 19th Sep 2009 17:25 Edited at: 19th Sep 2009 19:42
@GG
For the breakers, couldn't you do something along the lines of this:

- Take the modulus of the timer with the time between breakers, calling it 'delta'

- Sample the heightmap at the current position, and add 'delta' multiplied by a scale value to affect the distance between breakers.

- Take the modulus of this new value with the vertical distance between breakers.

- Make the pixel more opaque white depending on the final value. (So if the value is 0, it does not affect the colour, if it is the vertical distance, the colour becomes white)

The existing waves should help to add variation to the breakers, so that you don't need a texture.


edit:
I made a quick implementation. Replace the pixel shader function in the demo with this:


edit2:
Improved it so that the breakers fade in, instead of appearing:


It is a little bit pixelated, but nowhere near as much as it was before

revenant chaos
Valued Member
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 22nd Sep 2009 02:37
I am starting to worry about Green Gandalf, are you still around GG?
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 22nd Sep 2009 12:19 Edited at: 22nd Sep 2009 12:21
Colonel_Klink, I think you can do that if the object is divided in limbs (that could be the faces of a cube or any other subset of polygons), and then using 'set limb effect' for those limbs.
Also textures have much to say when deciding if a certain area behaves differently (for example a 'flat' region on a normal map or the typical specular map).

revenant chaos, just don't worry! I'm sure he will appreciate your interest when he comes back
Colonel_Klink
17
Years of Service
User Offline
Joined: 20th Dec 2006
Location: Within the dark recesses of my mind
Posted: 23rd Sep 2009 00:26
Morcilla, thanks. I thought that might be the case. I will just have to design and build my models with that in mind.

Oh my gosh! He's wearing Full Metal Pyjamas!
--------------------------------------------
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd Oct 2009 18:58
Quote: "I am starting to worry about Green Gandalf, are you still around GG?"


I'm sure you're not alone.

Apart from this quick visit (because it's raining and I was gardening today) I'm on holiday till Monday 5th October.
Alfa x
18
Years of Service
User Offline
Joined: 1st Jul 2006
Location: Colombia
Posted: 5th Oct 2009 16:56
Hi GG. ^^
How is the water shader going?. The progress has been superb and I'm eager to see the final result.

Thanks you so much for your support.

AlfaX
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 5th Oct 2009 21:39 Edited at: 5th Oct 2009 21:41
Quote: "How is the water shader going?"


It's not forgotten. I've tried so many variations of the basic idea that I need to stop and think for a while and assess what I've done [Edit and check a few other people's suggestions such as Diggsey's] - and there's suddenly a long queue of other queries as well.

Perhaps I shouldn't have gone on holiday ... ?
Monk
16
Years of Service
User Offline
Joined: 25th Sep 2008
Location: Standing in the snow =D
Posted: 6th Oct 2009 22:36
Quote: "Perhaps I shouldn't have gone on holiday ... ? "


Everyone's entitled a holiday =) Maybe you just picked a bad time....

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th Oct 2009 22:56
Quote: "Maybe you just picked a bad time"


Now we need a "When can Green Gandalf go on holiday?" thread. There's also the issue of how long for...

But before you all get too excited I should warn you that I've booked next year's holiday already.
Monk
16
Years of Service
User Offline
Joined: 25th Sep 2008
Location: Standing in the snow =D
Posted: 6th Oct 2009 23:06 Edited at: 6th Oct 2009 23:39
Quote: "But before you all get too excited I should warn you that I've booked next year's holiday already. "

You should probably warn people before it happens so they don't start worrying =P
Or you could sneak off quietly ...

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th Oct 2009 23:10
Quote: "You should probably warm people"


In a microwave perhaps?

[You can tell I've stopped thinking for the day - I can only read so much MS documentation in one go before I get severe brainache.]
Monk
16
Years of Service
User Offline
Joined: 25th Sep 2008
Location: Standing in the snow =D
Posted: 6th Oct 2009 23:39 Edited at: 6th Oct 2009 23:40
Quote: "I can only read so much MS documentation in one go before I get severe brainache"


Don't blame you, I'm getting brainache thinking about reading it But that could've been 5 hours of maths finally catching up on me....
Hence the loss of ability to spell ^^

_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 7th Oct 2009 22:16 Edited at: 7th Oct 2009 22:21
Hi guys,
I come from the "DarkGDK Realm" and I hope someone here can help me out with a shader
I know Shadow Mapping can be a complex subject, but I was following a tutorial for XNA and everything worked fine until now.

I can't really adress what's wrong, but I'll try to descirbe:

First of all, here's my shader:



Since DarkGDK commands are almost the same as DBPro, I'll post my code here. (Sould not be too hard to understand)



Now the problem is this:
The Depth-Map pass works fine, because I can see it in the pasted image when pressing '1'.
This image is then passed back to the shader (for use in second technique) through texture stage 1 of the objects. (texture stage 0 is the color-texture)
But the objects are not drawn after the second pass! (I can only see the small sphere that represents the light and has no effect assigned to it)
So I guess the problem is in the 'ShadowedScene' technique/pass!

Any help is greatly appreciated.

(Edit: Screenshot attached.)

Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.

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: 7th Oct 2009 23:54
Have you picked your way through that second technique?

For example, the whole scene is black (except for the light as you said). The first question to ask is "why?". Your shader initialises the scene to black - but could it be black for another reason? I suggest as a first step you try initialising it to some other colour, green for example (don't ask why green ). If the shader is doing anything then you should see green and black somewhere. Do you?

If you still see black perhaps the technique didn't compile?

Assuming the shader is actually doing anything then just go through the code line by line to see why it outputs black (or green as the case may be).

If you're still stuck I'll try to help - but it might not be quick (I'm not a GDK or C++ user).

In the meantime I have some questions about your demo:

1. Shadowmapping usually requires TWO screen projection matrices. One from the point of view of the camera and the other from the point of view of the light. Your code has two - but they are both the same, i.e.


Perhaps I'm missing something in your code?

2. What do the two expressions 1 << LightCam and 1 << UserCam do? (I think I can guess but I'd like to be sure.)
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 8th Oct 2009 00:14
Ok, thanks for you advice.
I changed the backdrop color to green
and the object's are not drawn after the second technique at all. (not even black)
So how do I check that the technique did not even compile? the errors-list is empty...

to your questions:
1. I know these are the same, I did it mainly for my understanding. When I'm doing the final touches to this shader I will replace these constant with just one.
One WVP-Matrix is enough here, because I'm switching cameras in between the techniques. (I think that's true, didn't have any evidence against that yet. prove me wrong )
2. This is to switch which cameras is synced. It's the same as SYNC MASK in DBPro, but you have to write it like '1<<CamID' instead of '1^CamID'.

Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Oct 2009 01:57
Quote: "and the object's are not drawn after the second technique at all. (not even black) "


But are they green? If they are green then they are being drawn - but not in the way you want.

Quote: "So how do I check that the technique did not even compile? the errors-list is empty..."


Don't worry - it does compile. Get a good shader editor/compiler such as Dark Shader (my preferred choice ) or FX Composer 1.8 (there's a more recent version available but since my first attempt at using it failed I can't recommend it yet).

Quote: "One WVP-Matrix is enough here, because I'm switching cameras in between the techniques."


I don't see how that can work. Am I missing something?

Quote: "but you have to write it like '1<<CamID' instead of '1^CamID'"


Surely you don't have to? I guess you're just bit shifting. Why not use 1 and 2 since those are the values of the expressions 2^0 and 2^1 (I assume you meant 2 not 1 ).
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 8th Oct 2009 02:44 Edited at: 8th Oct 2009 02:46
- The objects are not even green, they are just completly invisible, thus not drawn.

Quote: "I guess you're just bit shifting."

- well you're right. but anyway, i got this from another thread somewhere, and it works with my two cams
can it be that this has something to do with my problem?


Quote: "I don't see how that can work"

- Ok, I took a closer look at it and I think you're right.
That may be the problem. I thought the matrix (for the semantic in the shader) would be updated when I mask the views or something
How can I pass two individual WorldViewProjection-Matrices (for two cameras) to my shader???

(Edit: typos...)

Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Oct 2009 14:17
Quote: "- The objects are not even green, they are just completly invisible, thus not drawn."


But what DO you see? A black screen or a green screen or something else? If you colour a sphere green and set it against a green background you will just see green. The object is drawn but you can't distinguish it from the background so it seems to be invisible when it isn't.

What you actually see is an important clue to what is going on.

Quote: "can it be that this has something to do with my problem?"


I've no idea. What does the "<<" operator do in C++? If in doubt just use the constants 1 and 2 for cameras 0 and 1 and see if it makes a difference.

Quote: "I thought the matrix (for the semantic in the shader) would be updated when I mask the views or something"


I'm sure it is but that wasn't my concern. The shadow map creation step uses the projection matrix for the light to determine the depth and you say that seems to work in your demo. The problem is the final rendering technique. You need TWO projection matrices at the same time there I believe - one for the the main camera and one for the light. The shader needs to compare the final pixel's distance from the light with the value recorded in the shadow map - if it is greater than the shadow map value then it is in shadow. But it can only get the right shadow map pixel to compare with by using the light's projection matrix which I believe you have to pass to the shader manually. EVOLVED has a shadow mapping demo somewhere which illustrates this method.

Quote: "How can I pass two individual WorldViewProjection-Matrices (for two cameras) to my shader???"


This is how I've done it in a draft shader (it's not finished and has some errors which I haven't tracked down yet - it is loosely based on EVOLVED's demo).

Shader:



DBPro code:

_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 8th Oct 2009 14:42
Quote: "But what DO you see?"

I see just the backdrop color (no matter if it's green, blue, black...) and a little sphere (with no effect) that represents the light. So the objects with the effect applied simply have no color at all. Invisible.

Quote: "What does the "<<" operator do in C++?"

Well, I don't even know exactly. As you said I just use constants 1 and 2 now and it's the same.

Quote: "You need TWO projection matrices at the same time there"

Yes, exactly, that's the main issue I think. I know about Evolved's Shadow Mapping Demo (I once translated it, it's on the DarkGDK board). But I want to use my own shader, basically for customization and learning purposes. And his shader uses Normal Mapping and Shadow Mapping combined, so it's pretty complex and hard for me to figure out the essential steps.

Quote: "This is how I've done it"

You're just multiplying the View and Projection matrix there. To get a WorldViewProjection matrix you have to multiply the World matrix, too - right? Maybe I'm wrong but I guess that won't solve it either (tried a few things like that) because I don't know how to tell DarkGDK (DBPro in your case) to use the Light's view matrix!
I thought about just passing the Light position and rotation vectors to the shader, and calculate the matrix manually. Can you help me with this? What has to be multiplied with what?!

Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Oct 2009 15:09 Edited at: 8th Oct 2009 15:10
Quote: "You're just multiplying the View and Projection matrix there."


Yes, and you're probably right about the world matrix being needed as well. That could be the problem I had with the shader - it's over a year since I looked at it.

Quote: "But I want to use my own shader, basically for customization and learning purposes."


That was my reason too - and I didn't finish learning to my complete satisfaction. But your query is prompting me to have another look.

Quote: "because I don't know how to tell DarkGDK (DBPro in your case) to use the Light's view matrix!"


Just put the camera where the light is - I assumed that's what you'd done anyway.

Quote: "I see just the backdrop color (no matter if it's green, blue, black...)"


My reference to green was unhelpful. I was referring to my earlier suggestion to initialize the colour in the shader to something other than black (and preferably something other than a camera backdrop colour as well ). Have you tried that? What colour did you use? Did you see it in the final render?

Since I now know what your GDK code is doing I'll try translating it to DBPro and see what I get. That'll be quicker than me grappling with the GDK and C++ (I have both but am at a very early stage).

Edit - corrected typo.

Login to post a reply

Server time is: 2024-11-24 01:35:01
Your offset time is: 2024-11-24 01:35:01