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: 2nd Nov 2007 18:58 Edited at: 2nd Nov 2007 19:31
That's a very complicated shader for what it seems to do - one reason why I write them myself rather than rely on things like RenderMonkey or Mental Mill. I suspect a lot of the code in that shader isn't being used at all!

Unfortunately, it's written for Shader Model 3 (SM3) and none of my machines will run it so I can't test any suggestions I make. However, before making any changes we need to know what you mean by "UV mapped". Most objects have at least one set of UV coords and hence are "UV mapped". I suspect you mean it has an ADDITIONAL set of UV coords, possibly for something like a light map - but your post doesn't say.

The shader expects to receive FOUR sets of UV coords - but as far as I can see it only uses the first. If your object is lightmapped with an extra set of UV coords the shader will need to be modified so it uses BOTH sets - and does the lightmapping correctly.

At first sight the shader just seems to be doing standard normal mapping so there is no obvious need to use SM3. Could you export it as SM2? At least I could test any suggestions I make.

Even if you made the appropriate changes in the shader, you'd still need to make sure that the textures were correctly assigned to stages in DBP. What code did you use?

If you can tell me what sets of UV coords your object has - and what they are for - I might be able to suggest changes for the shader (but you'd have to test it ).

Perhaps I ought to pass round a begging-bowl so I can upgrade to a modern machine.

Edit *** CORRECTION ***

Ignore what I said about SM3 - that shader is actually written in SM2 although it asks to be compiled as SM3, so I can (and have) tested it! (But I needed DarkSHADER to do it. )

I still need answers to my questions about UV coords and light maps - otherwise I'll still be guessing ... but I should be able to suggest (and test) changes for you along the lines of my suggestions on the other thread.
Alsan
19
Years of Service
User Offline
Joined: 20th May 2005
Location: Germany - Nähe Kassel
Posted: 2nd Nov 2007 19:34 Edited at: 2nd Nov 2007 21:58
Hi, thanks for your help.

Yeah, I already guessed the shader is quite long and complicated for what it does. That's the biggest con of those programs. Maybe I'll learn to write them myself, it's surely not bad to know HLSL in times where a object has 15320 different shaders on it.

With UVMapped I mean, that I unwrapped the model in Bodypaint so I can texture it. I have only one set of UVs for both color and normal map, the model is not lightmapped (it's a .x file, as far as I know that doesn't even support multiple UV sets)

The shading itself works fine as you can see in the picture:



Only the UV is screwed up.

I'm afraid I can't provide a SM2 version, there's no option to do that in Mental Mill. /edit: Great.

Quote: "Perhaps I ought to pass round a begging-bowl so I can upgrade to a modern machine. "


You should sell your terrain shader, that's a great piece of code.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 2nd Nov 2007 21:47
Quote: "Only the UV is screwed up."


OK, I see. I was barking up the wrong tree. Are you using one texture or several?

I can't see why the UV coords should be screwed up for one object and not another.

A thought: are you sure the UV's are not screwed up for primitives as well? If you were using simple textures you might not have noticed. I'll try to find time to investigate this myself later this evening. I'm sure it has a simple explanation ...
Alsan
19
Years of Service
User Offline
Joined: 20th May 2005
Location: Germany - Nähe Kassel
Posted: 2nd Nov 2007 22:00
First of all, I'm very glad that you help me.

Quote: "Are you using one texture or several?"


Only one. Here's a "presentation" of the model I made some days ago (the texture wasn't final at that point):

http://jaf-entertainment.de/Misc/Render/Axt/Render.jpg

Quote: "A thought: are you sure the UV's are not screwed up for primitives as well? If you were using simple textures you might not have noticed. "


I guess the UVs are "resetted", so you wouldn't notice that on primitives as they are already in this "resetted" state when you create them. (Hard to explain ^^)

PS: Is the red in my signature too flashy? Don't want to annoy someone.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd Nov 2007 00:14
You are absolutely right. For some inexplicable reason the shader DOES reset the UV values!

Here's where:



Try changing those lines to:



i.e. so that they don't change the UV coords. There may be other things that need changing - but try that first.

That's a good example of the redundant code in that shader.
Alsan
19
Years of Service
User Offline
Joined: 20th May 2005
Location: Germany - Nähe Kassel
Posted: 3rd Nov 2007 00:36 Edited at: 3rd Nov 2007 00:36
Yes, if I change those lines it works, and it looks good.

Thank you very much!

But even I as a shader n00b can see that the produced code isn't very good.. I think I'll try to learn HLSL in the future or just use the available shaders.

Irradic
18
Years of Service
User Offline
Joined: 1st Jul 2006
Location:
Posted: 5th Nov 2007 16:01 Edited at: 5th Nov 2007 16:04
Today I have a new shader challenge. Actually it's something I've been thinkig of quiet a while already since this would have quiet an impact on the workflow and texture work.
The game I'm working on has mostly outdoor city environments.
http://bp1.blogger.com/__wry3Pd2xEg/Rw16ZjeAEhI/AAAAAAAAACM/GmQolPPO6EE/s1600-h/Image2.jpg
So far I've been mapping whole buildings on a single texture (1 building= 1 texture). I'm not really a friend of tileable textures, without dirt they simply look too clean, with dirt you just get a horrible tiling effect. However there are disadvantages to using a single texture, mostly on detail loss and texture size.

My idea was to have a tileable base texture (brick,concrete or whatever) and have an extra dirt/grind texture layer (which is not a tilable texture). The dirt texture could probably also include the baked lightmap. This should be possible with a single uv ? Since all the models have been unwrapped.
I'm using Evolved's 6 lights Normal Maps Shader.
I would be thankfull for some input concerning this matter.
Thanks !
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th Nov 2007 00:15
Quote: "My idea was to have a tileable base texture (brick,concrete or whatever) and have an extra dirt/grind texture layer (which is not a tilable texture). The dirt texture could probably also include the baked lightmap. This should be possible with a single uv ?"


Yes - if you can get the lightmap to use the same UV coords as the texture. No obvious reason why you can't - except for lightmapping software limitations I suppose.

The main problem I can foresee is that the dirt texture probably needs to be as detailed as the base texture - but it might work. If the dirt texture is too small the dirt will look like a smear rather than bits of dirt. If all the lighting is in a pre-baked lightmap you just need to blend three textures. In fact you might be able to do it with the fixed function graphics pipeline and not need a shader at all (this is a bit of a guess - but I do know that a pure shader soluton would be easy ).

Perhaps the set blend mapping on command is all you need? Might be worth experimenting with that first.

Looks like tomorrow evening can be written off now.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th Nov 2007 00:58
Well, the attached is the best I can do with the set blend mapping on command.

Looks like you can't scale the textures separately.

But you can easily in a shader - even with only one set of UV coords.

You'll have to wait till tomorrow, though.

Attachments

Login to view attachments
Irradic
18
Years of Service
User Offline
Joined: 1st Jul 2006
Location:
Posted: 6th Nov 2007 01:23 Edited at: 6th Nov 2007 01:32
My only thought was, if the base texture and normal map, let's say a brick texture, was tiled on the object how would the dirt map be projected on the object ? If it is using 1 UV, would the dirt map be tiled as well ? Because the idea was to have the base color map tiled, and the dirt map as a single map using the unwrapped UV coords.
If this would be integrated in the shader it would react to the shader lighting which is set for the environment. If using set blend mapping on I would have to recreate the shader lighting with the engine lights, if i'm correct. So I would prefer a shader solution.
I have attached evolved's shader if you want to give it a try.
I've been playing around with it,but so far I wasn't able to make the dirt map show up at all.
Thanks for time GG.

EDIT: Haha, you already came up with something while I was writing my post. So you encountered the texture scalability problem, which concerns the question I was asking about the tilable base texture and dirt/light map. However I do need the normal mapping for the environment
Take all the time you need, thanks a lot for the help

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: 6th Nov 2007 22:41
@Irradic

Try this. The textures are obviously crude - but I hope the demo gives you an idea.

Attachments

Login to view attachments
Irradic
18
Years of Service
User Offline
Joined: 1st Jul 2006
Location:
Posted: 6th Nov 2007 23:52
Incredible Gandalf, can't thank you enough. I see that the tiling is being handled by the uvtile values, looking forward to do some test later this day.
Thanks again
Mike Inel
21
Years of Service
User Offline
Joined: 14th Feb 2003
Location: Sa upuan ko po...
Posted: 9th Nov 2007 06:24
Just wondering if zsorting of a single object has been solved before...
"set object transparency id,5" doesn't work since it does zsorting by individual objects... Besides that, dbpro shadows appears on top of objects that are set in that transparency mode...

I remember someone who managed to do that in hlsl, but i can't find the thread anymore... There are some hlsl commands that were inserted i think...

I attached a pic to see what i mean about the single object zsorting prob... The body and the hair are in a single object...

Attachments

Login to view attachments
game master 07
17
Years of Service
User Offline
Joined: 26th Feb 2007
Location: Maryland
Posted: 10th Nov 2007 18:15 Edited at: 10th Nov 2007 18:16
Ok heres my situation. I need a water shader where I can change the color of the water. I need it to look like sewer water with a brownish color. I have looked and looked but the only water shaders I can find are crystal clear. I decided to post this question here because in the thread that I started http://forum.thegamecreators.com/?m=forum_view&t=117704&b=1
I didn't get any responses as to where I could find a water shader that lets you change the color. I am hoping that someone here could please please help me out! It would make me very if you did!

gm07
Mike Inel
21
Years of Service
User Offline
Joined: 14th Feb 2003
Location: Sa upuan ko po...
Posted: 11th Nov 2007 02:13
This is all i can think of... An edited Evolved's "Water Terrain" shader...
I'm not really good helping people, but at least i tried. ^_^
(See attachment)

Attachments

Login to view attachments
game master 07
17
Years of Service
User Offline
Joined: 26th Feb 2007
Location: Maryland
Posted: 11th Nov 2007 03:22 Edited at: 11th Nov 2007 04:03
Thats exactly what I needed! Thanks alot! You are a life saver!Not the candy.LOL

gm07
game master 07
17
Years of Service
User Offline
Joined: 26th Feb 2007
Location: Maryland
Posted: 11th Nov 2007 04:08
I just made a neat thing with the shader by changing the colors in the R,255 B,255 G,255 code to just red and it made the shader look like blood! Just thought id share a pic of it!


gm07
Mike Inel
21
Years of Service
User Offline
Joined: 14th Feb 2003
Location: Sa upuan ko po...
Posted: 11th Nov 2007 04:17
Red sea! lol
Glad that helps!

Inspire
17
Years of Service
User Offline
Joined: 23rd Dec 2006
Location: Rochester, NY
Posted: 15th Nov 2007 03:02
Wow, that looks sweet!

Nemesis_0_
20
Years of Service
User Offline
Joined: 26th Dec 2003
Location: Canada
Posted: 17th Nov 2007 19:29
ne1 here good with legal talk? in like the FX composer eula it says something about derivatives being released royalty free but then something else that i dont understand being not royalty free... can anyone explain this simply to me... the shaders that u can access with fx composer... are they royalty free? or do you have to change something about them to use them royalty free? or will u get sued if u release a commercial product using them?
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 20th Nov 2007 23:57
hi
could anyone explain this command please?

what does 2^1 mean actually?

and also what difference does it make here?


I need to ask here because ive problems with water shader, Thanks in advance
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Nov 2007 22:46 Edited at: 21st Nov 2007 22:49
"2^1" is a standard DBP arithmetic expression which means "2 to the power 1", i.e. just 2 in fact.

The two commands you refer to are just telling DBP to sync different cameras - each camera is "flagged" by a different power of two, so your first snippet is just syncing camera 1 (the power).

In the same way, your second snippet is syncing cameras 1 and 2 (i.e. 0x00000006 is just hex code for decimal 6 which, in turn is just 2+4, i.e. 2^1+2^2, i.e. cameras 1 and 2 (the two powers)).

If you wanted to sync cameras 2 and 5 you could use any one of the following:



or



or



or, if you prefer binary,



followed by a sync in each case.

The choice is yours.

The first option makes the connection with the camera numbers more obvious, but is very slightly less efficient because a tiny bit of extra calculation is involved. It's certainly useful if you're using several cameras because you can tell at a glance which cameras are being used in any particular sync - and very useful if you return to the code later or are trying to show people what to do.

The sync mask command doesn't perform the sync itself. Typically your code might have something like:



The final sync syncs camera 0 - i.e. prepares the final screen image which is what you actually see. The other syncs just prepare various images which can be used in various ways in the code.

Hope all this makes sense.

Edit Corrected arithmetic error.
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 22nd Nov 2007 14:55 Edited at: 22nd Nov 2007 15:12
Thanks for the help that sure made things very clear for me

EDIT:
An other question, i tried to combine evolved water shader with the above colored water shader(which includes fog when you go below water)..I mean it has now 3 techniques, however it just doesnt work, can anyone see what is wrong in it?
Here is the shader:

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 27th Nov 2007 21:35
@CuCuMBeR

One problem is that you have declared a variable that you don't use:



But I think you meant to use it here:



and here:



What software are you using to debug your shaders? Dark Shader or FX Composer would pick up that problem straightaway.

I haven't checked that the shader actually works as intended.
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 28th Nov 2007 00:06
Hmm...It doesnt give error anymore, but i just cant set up the textures and cameras
Aaaanyhow thanks for the help
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 11th Dec 2007 20:15 Edited at: 11th Dec 2007 20:28
It appears I'm in need of shader help, as I have no idea why my code doesn't work and have spent quite a while trying to debug it(though I don't call dodging the illegal op very effective).

The code below is my attempt at making a planetary ring shader(so the planet can cast shadow on the ring), it works(in theory) by finding the distance from the light source to the pixel and planet, dividing them(to find the difference ratio), then multiplying that to the planet's position thus projecting the planet to the pixel's distance and comparing the planet's radius to the distance between the projection and the pixel. If it's below the radius it currently makes the RGB 0.0 and leaves the alpha thus creating shadow, however for some reason the shader always crashes when it gets to the condition, I can only assume I'm going wrong somewhere with the vectors.



[Edit] In the above code I assumed that the .w float of a float4 is the length of the vector, but as there's a length() function I'm probably incorrect there, either way it still doesn't work.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 11th Dec 2007 22:33 Edited at: 11th Dec 2007 22:36
dark coder

Good to see you having a go at this.

Just had a quick look at the code. The following changes (marked "// **GG") should allow it to compile and hence not crash DBP. (I think we ought to ask Lee to make sure DBP doesn't crash just because the shader doesn't compile. There might be a way of doing that already - just need to remember to check sometime. ).



I think this is functionally equivalent to what you were doing. Whether it works as you intend it to is another matter.

For example, I guess your vector LightPosition is measured in World coordinates. However, your shader code compares this with the pixel's position in Screen coordinates. The vertex shader has to output the Screen position of a vertex (among other things) - i.e. WorldViewProjection is shader shorthand for the following transformations of the object's own vertex coordinates: (i) first transform the object's internal coordinates to the World coordinates (this measures how the vertex is positioned, scaled and oriented in your scene); (ii) next transform the World coordinates to the camera's View coordinates (i.e. measured from the camera); (iii) finally Project the view of the scene onto the screen. My guess is that you might want to think about replacing my variable sPos (i.e. screen position) with wPos (i.e. world position). This will require multiplication by the World matrix rather than WorldViewProjection. But I'll leave you to ponder that for a while.

The other changes I've suggested fall into three [EDIT four!!] groups:

1. I've inserted default values for your input variables - you've given them non-standard semantics which will probably just be ignored (this change might just be cosmetic - I'd have to do a bit more checking to be sure).
2. I've replaced "Name" by "ResourceName" in the texture declaration - this is almost cosmetic again. It just allows me to test the shader in both DarkShader and FX Composer. DBPro accepts either.
3. I've added several changes to allow the pixel shader to access the screen position output by the vertex shader, essentially just adding a second copy of the original calculated vertex screen position. Pixel shaders can't access variables with the POSITION semantic.
4. There are some obscure rules limiting what you can do with w coordinates in calculations in PS1.1 - hence the final change to PS2.

Hopefully those changes will stop it crashing. Next comes the fun part.

Have fun.
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 12th Dec 2007 01:02
Could anyone implement light direction to this normal mapping of evolved ?

dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 12th Dec 2007 09:46 Edited at: 12th Dec 2007 09:48
Thanks for the help GG:

Quote: "1. I've inserted default values for your input variables - you've given them non-standard semantics which will probably just be ignored (this change might just be cosmetic - I'd have to do a bit more checking to be sure)."


If I change them to literals like in your code I can no longer change the values from my code as I believe on the left you have the constant the shader uses internally and on the right you have the constant the application can see, this makes sense for ASM shaders where you must have c0,1,2 etc for the constants.

However I got some progress done with your help, I found that if I pass IN.Position to the pixel shader "OUT.sPos = IN.Position;" it seems to work correctly, multiplying it by WorldViewProjection/World/WorldIT/WorldInverse etc all result in incorrect rendering.

But I'm having issues with dividing it seems, I'm first calculating the distance between both the pixel and planet to the light source(which I believe works) in the below code:



If I then output the pixel using:



It creates a slight gradient fade between light and dark as expected as the planet is quite large, as seen here:



However if I output the pixel using:





I get a sharp transition between light and dark, when it should blend. I've tried multiplying the ratio by 0.1, 0.01 etc but the brightness almost seems like it's being cast into an integer where the ratio variable is either 0 or 1, this shouldn't be the case as all variables in these operations are floats and the above DiffuseMap.rgb *= Px_Dist_L - Pl_Dist_L works fine. It may be hard to see in the screenshot as I reduced the image size, however there is no transition between the light and dark at all.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th Dec 2007 14:06
dark coder

Quote: "If I change them to literals like in your code I can no longer change the values from my code as I believe on the left you have the constant the shader uses internally and on the right you have the constant the application can see, this makes sense for ASM shaders where you must have c0,1,2 etc for the constants."


No, that's wrong I'm afraid.

If you want to change the values using DBP just use set effect constant float or set effect constant vector as illustrated in the numerous shader demos on this site (and this thread).

Quote: "I found that if I pass IN.Position to the pixel shader "OUT.sPos = IN.Position;" it seems to work correctly, multiplying it by WorldViewProjection/World/WorldIT/WorldInverse etc all result in incorrect rendering."


That's interesting. I'm not sure off-hand why that should work (and am not convinced it does work) - I didn't check the details of what you were doing carefully yesterday. I concentrated on getting a functioning shader which you could amend as necessary. Seems like you are making good progress now.

Quote: "I get a sharp transition between light and dark, when it should blend."


I'll try to find time later today to look into this more carefully. However, for now, you might consider what the following lines actually do:



You have assigned a float4 to a float in the first two lines. I think what happens is that the first component, i.e. the x coordinate, ends up being assigned to the floats. Hence I believe your code is equivalent to the more transparent which makes it obvious that your "distance" could be negative



The line I corrected was merely to get your shader compiling, I didn't attempt to modify what it was apparently trying to do. If you are trying to get the distance between the planet's position and the light's position you shouldn't be doing that in the shader anyway, and certainly not in the pixel shader. You'll be calculating the same distance for every pixel unless the shader compiler can extract common code and pre-calculate it befiore the object is rendered. I usually play safe and calculate things like that ONCE per sync in DBP and pass the result to the shader using set effect constant float. More importantly though, if you want distance you need to calculate something like



(except that I think you need World space coords as I mentioned yesterday - I suspect the difficulties you experienced are a result of you doing the wrong calculation).

If you're still stuck I'll try to sort this out properly later - I'm sure that what you are trying to do is easy to achieve and is a nice idea.
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 13th Dec 2007 00:27 Edited at: 13th Dec 2007 00:34
Thanks for the help!, it turns out that all my issues were caused by me sending the shader constant values to the wrong shader(slaps forehead), once I fixed that everything started falling into place and you were right about getting the pixel's position, I just had to multiply it by the World constant.

Anyway I'm pretty chuffed at my result(though not the time it took me to fix the issue ), the complete shader code is below for anyone to use and it's well documented(at least I think it is)so you can implement it easy enough.



Here's a pic of the result in my engine:



Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 13th Dec 2007 01:12
Excellent work!

That's another great example of a shadow shader in action.

Quote: "it turns out that all my issues were caused by me sending the shader constant values to the wrong shader(slaps forehead)"


That's the sort of error we all make - and it usually takes ages to track down for the simple reason that when we read the code we read what we intended to write. It's only when we check every step for what we expect against what we get that we can isolate it.

Programming is fun - but very infuriating at times. But when it finally falls into place ...

Two very small comments: (1) the distinction between umbra and penumbra seems rather small. Could you enlarge the penumbra area somehow? (I think this echoes an earlier comment of yours.) (2) The shadow seems to tail off rather abruptly - as if the "sun" is too close and/or too big (but my ignorance of astronomy might be showing there ).

But what you've done is impressive - and the code is simple to follow. Nice job.
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 13th Dec 2007 06:58 Edited at: 13th Dec 2007 06:59
Quote: "the distinction between umbra and penumbra seems rather small."


The penumbra width if anything is slightly wider than in real-life, here's a huge Cassini pic of Saturn(6 meg) HERE, for that screenshot I increased the size of the rings, however the distance between Saturn and the sun is accurate.

Quote: "The shadow seems to tail off rather abruptly"


The penumbra fades off linearly, however I plan to implement a shadow texture map lookup, as in that above Cassini pic you may notice the atmosphere affects the penumbra's colour.

Now I just need to get my Saturn looking as good as in that picture.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 13th Dec 2007 12:33
dark coder

There's nothing wrong with your image - I was just being stupid. I was assuming, for no obvious reason other than early onset dementia ( ), that the light source was in the plane of the rings.

And, given the sun's distance from Saturn, there would be virtually no penumbra as you say.

Oops!
TinTin
18
Years of Service
User Offline
Joined: 16th May 2006
Location: BORG Drone Ship - Being Assimilated near Roda Beta (28)
Posted: 13th Dec 2007 15:08
I agree with GG that looks awesome, well done.

That was the good news, now for the bad....

The rings around your panet show the background stars twinkeling through, (I hope this was meant) if gives the rings a translucent feel which I like. The problem is, that in the shadowed area, these stars seem to be missing, infact the whole shaddow appears to blacken out everything it touches, It don't look right (may require a tweak).

Anyway, I'm in the process of developing a shader tool that displays the Tweakable Constants a shader uses and what variable type it is. (link to source code)

http://www.thegamecreators.com/?m=codebase_view&i=3c7cccc1b0fc1e04d7091c367a5b40c2

Anyone can see that there are spaces (omissions) on the variables, I'd be happy to recieve any info on what they should be etc...

To use, compile and stick the .exe on your desktop. drag your .fx file onto the .exe and it should display the constants, it should also point out any errors in the .fx file.

Cyberspace was becoming overcrowded and slummy so I decided to move. These nice chaps gave me a lift.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 13th Dec 2007 19:16
Quote: "The rings around your panet show the background stars twinkeling through, (I hope this was meant) if gives the rings a translucent feel which I like. The problem is, that in the shadowed area, these stars seem to be missing, infact the whole shaddow appears to blacken out everything it touches, It don't look right (may require a tweak)."


Well spotted - I hadn't noticed that. I think we'll have to wait for dark coder to explain why you can see them twinkling through at all. The shader doesn't touch the alpha component so it shouldn't make any difference. Perhaps nothing is twinkling through the ring and what we're seeing are just bright specks in the ring (i.e. large asteroids, etc) - so they would be darkened by the shadow?
TinTin
18
Years of Service
User Offline
Joined: 16th May 2006
Location: BORG Drone Ship - Being Assimilated near Roda Beta (28)
Posted: 14th Dec 2007 16:53 Edited at: 14th Dec 2007 16:54
Quote: "Perhaps nothing is twinkling through the ring and what we're seeing are just bright specks in the ring (i.e. large asteroids, etc) - so they would be darkened by the shadow?"

I didn't think of that... hehe
Just have to wait and see what Dark Coder has to say.... Dark Coder!.... (sigh!, where is the developer when you need them?) hehe

Cyberspace was becoming overcrowded and slummy so I decided to move. These nice chaps gave me a lift.
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 14th Dec 2007 17:09
TinTin is correct, the stars do get drawn before the ring, as does the planet's atmosphere but you can't really see that there. This is because of Z Sorting errors, when I have multiple planets/moons on screen you often get certain Z Sorting errors so I had to disable Z Depth for closer objects and all sorts of tricks so it looks semi-correct. However my game would be so much easier to make if you could specify specific draw orders in DBP.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th Dec 2007 18:57
Quote: "TinTin is correct, the stars do get drawn before the ring"


But that takes us straight back to TinTin's comment:

Quote: "The rings around your panet show the background stars twinkeling through, (I hope this was meant) if gives the rings a translucent feel which I like. The problem is, that in the shadowed area, these stars seem to be missing, infact the whole shaddow appears to blacken out everything it touches, It don't look right (may require a tweak)."


If the stars were drawn first why can we see the ones through the lit parts of the rings, but not through the shadowed bits?
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 14th Dec 2007 20:48 Edited at: 14th Dec 2007 21:02
Quote: "If the stars were drawn first why can we see the ones through the lit parts of the rings, but not through the shadowed bits?"


Pure chance that there were no stars there.

[Edit]

Actually there is one(very top left of the shadow), here's the original:



[Edit again]

Here's a version with correct Z sorting, though I haven't tested iit with multiple planets yet, and my ring shadows!



Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th Dec 2007 22:20
Quote: "Pure chance that there were no stars there.

[Edit]

Actually there is one(very top left of the shadow), here's the original:
"


I decided that the chance of that was too remote - and, yes, I did miss the Lone Star (it is just visible in your original image).

Nice images. I hope we see more shaders and demos from you.
Pharoseer
17
Years of Service
User Offline
Joined: 21st Feb 2007
Location: Right behind you
Posted: 30th Dec 2007 01:38 Edited at: 30th Dec 2007 01:38
Hey everybody,

I may have overlooked this, but just in case it hasn't already been mentioned here it is. I found a complete HLSL Reference (through 3.0). It has some info on the ASM portion as well to help give a more solid understanding of what's going on. I started working with shaders about a week ago and with everything that Visigoth, Green Gandalf and the rest of you have posted I feel I've made some significant progress. I hope this helps!

-Frank

http://www.paradoxalpress.com/LayoutSamples/HLSLReference.pdf
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 30th Dec 2007 01:54
david w
18
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 4th Jan 2008 12:16
Ok I am going to take the plunge and learn. I realize that I cant do it all in just DBP any longer.
TVB
16
Years of Service
User Offline
Joined: 7th Dec 2007
Location: China
Posted: 4th Jan 2008 12:23 Edited at: 5th Jan 2008 06:37
Thanks for all the tutorials and help.I am working on shaders for DarkBasicPro.
david w
18
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 16th Jan 2008 21:50
How hard would it be to make an normal mapping shader have black be transparent.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Jan 2008 17:56 Edited at: 18th Jan 2008 17:57
Quote: "How hard would it be to make an normal mapping shader have black be transparent."


Shouldn't be very difficult. Would the black be part of the main texture or the normal map texture?

You could try something like the following in the pixel shader:



This snippet assumes that the relevant texture is being sampled by the sampler "baseSample" and that its value is stored in the variable "colour". The next line then calculates the sum of the RGB components and tests to see whether it is less than 0.001 (I'm assuming the smallest non-zero value is about 0.00392, i.e. 1/255). If it is less than 0.001, i.e. black (or nearly so) then it clips the result, i.e. doesn't render it so you see what was rendered underneath.

You might need to fiddle with some other things but try that first.
david w
18
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 20th Jan 2008 09:03
@gg thank you will, give it a shot.
Ian T
22
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Around
Posted: 22nd Jan 2008 17:30
Could someone point me in the right direction re: adding a pixel shaded fog component to an existing shader - specifically one that works on a flat plain EG one of evolved's water shaders? I need it to fade out nicely, and I've seen it done before but can't seem to find any existing shaders with a fog component for reference. I know it involves multiplying the output color value by something relating to the distance from the camera and the fog color, but I'm honestly not sure where to start with the mathematics. Any help would be greatly appreciated
James H
17
Years of Service
User Offline
Joined: 21st Apr 2007
Location: St Helens
Posted: 22nd Jan 2008 20:59
change your fx file at the end to this and alter fog start,end,color values - its from evolveds water shader with only these changes
its a quick fix - only basic control I`m afraid

//--------------
// techniques
//--------------
technique ReflectRefract
{
pass p1
{
fogenable = 1;
FogTableMode = 3;
fogstart = -1750;//starts behind camera with negative value
fogend = 1750;
FogColor = {0.9, 0.9, 0.9, 1.0};//rgba 0.0-1.0

VertexShader = compile vs_1_1 VS();
PixelShader = compile ps_2_0 ReflRefr();
}
}
technique Refract
{
pass p1
{
fogenable = 1;
FogTableMode = 3;
fogstart = -1750;
fogend = 1750;
FogColor = {0.9, 0.9, 0.9, 1.0};

VertexShader = compile vs_1_1 VS();
PixelShader = compile ps_2_0 Refr();
}
}

Login to post a reply

Server time is: 2024-11-24 17:50:29
Your offset time is: 2024-11-24 17:50:29