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
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 22nd Nov 2011 17:17
Quote: "I can't get it to work either "

Thanks, I thought it was my fault. I don't want to gime up again. There must be good shader programs compatible with Dbpro .

What I'm doing now, is using the example david w sent me, and just change images.

Quote: "I'm sure us two grumpy grandpas should be able to work this out between us.Are you interested? "


Thanks for your words of encouragement.Usually when I start something, I try to finish somehow.

Cheers.

I'm not a grumpy grandpa
DarkDISCUSSION
13
Years of Service
User Offline
Joined: 6th Jul 2011
Location: Ft Madison, IA
Posted: 23rd Nov 2011 19:52
What do you use to write a shader? C++? 3DS Max?

Kind Regards,
Captain Wicker aka DarkDISCUSSION
http://captainwicker.webs.com/
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 23rd Nov 2011 21:03
HLSL (High Level Shader Language)
JackDawson
13
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 31st Jan 2012 12:50 Edited at: 31st Jan 2012 12:57
I know this is a late response. But for those who do not know...

DarkShader here on this website can help you in writing some shaders. It will help writing in the HLSL shader language, which is a directX version of the Shader Language.

It does not write GLSL which is the OpenGL version of the Shader Language.

http://www.thegamecreators.com/?m=view_product&id=2078

This will also allow you to see the actual source code to the templates that it provides and you can change it if you want. Make some more Shaders based off their templates. And you can see it work in action before bringing it into your software.

Another Shader IDE is known as FX Composer which also allows you to write shaders in DirectX 9 and DirectX 10 as well as OpenGL.

http://developer.nvidia.com/fx-composer

Hope this info helps.

"Life is like a box of chocolates.. eat it before it melts."
nruser
16
Years of Service
User Offline
Joined: 22nd Dec 2007
Location: Serbia
Posted: 2nd Feb 2012 02:07
Can someone help me with this i want to achieve volumetric light effect from evolved's shadow mapping shader? My idea is to use light color and fill the light from light position to light range value, and every thing should work properly.
Evolved's shadow mapping shader projects a texture but that can be easily 'turned-off'. This effect is achievable with PS 2.0, i know because i have seen this in older games.
nruser
16
Years of Service
User Offline
Joined: 22nd Dec 2007
Location: Serbia
Posted: 8th Feb 2012 12:38
anyone, i still need help with this see http://forum.thegamecreators.com/?m=forum_view&t=177582&b=2 screenshots with rays are the effect that i want to achieve but they should be visible from any angle
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Feb 2012 13:41
You haven't been ignored. I'd like to know an efficient way of achieving those as well. (I feel a project in gestation ... ).
nruser
16
Years of Service
User Offline
Joined: 22nd Dec 2007
Location: Serbia
Posted: 11th Feb 2012 21:58
I have found a working shader and it is what i am looking for can you please make this shader work in dbp? See exe in attachement.

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: 11th Feb 2012 23:29
I would need to see some code and, preferably, a description of the method used.

By the way, the download seems to be corrupt and the brick.jpg file wouldn't extract correctly. However, I got it working by using a different brick image.

Nice demo but useless without code, etc.
nruser
16
Years of Service
User Offline
Joined: 22nd Dec 2007
Location: Serbia
Posted: 12th Feb 2012 20:41
see this link http://www.gamedev.net/topic/533694-god-rays/ i got this shader from there, it is from gpu gems 3 book you can find that part of the book on through google on the link it is god rays and in the book volumetric lighting
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 13th Feb 2012 02:09
nruser
16
Years of Service
User Offline
Joined: 22nd Dec 2007
Location: Serbia
Posted: 13th Feb 2012 20:27
that's the one
david w
18
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 13th Feb 2012 21:13
Alright you all have convinced me. I'm in on this one. Evolved has a shader that does this already but I think its part of his advanced lighting pack, and not really a stand-alone effect. I think however that we can use that effect along with the PDF paper as a starting point and really make good post-process LightScattering/God-ray shader.

I really think the community could benefit from this shader as I think there will be alot of demand for it.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 13th Feb 2012 22:00
Quote: "Evolved has a shader that does this already but I think its part of his advanced lighting pack, and not really a stand-alone effect."


I tried his demo but couldn't see the "light ray" effect. Perhaps I had the wrong demo. Could you provide a link?
James H
17
Years of Service
User Offline
Joined: 21st Apr 2007
Location: St Helens
Posted: 13th Feb 2012 23:43 Edited at: 14th Feb 2012 00:56
this is it seperate to adv lighting demo
http://www.evolved-software.com/shaders/LightScattering/LightScattering.zip
edit : this is what I get on my screen - you need to get up real close to the object, its not as good as in adv lighting and having breifly read whats wrote in gpu gems Im unsure as to what rays and shafts are in relation to light scattering. In the adv lighting demo from his site you can alter it to change the colour of the scatter from black

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: 14th Feb 2012 00:06 Edited at: 14th Feb 2012 16:25
Hmm. The one I have is called LightScattering too - but is very different (I got it from Evolved's Google pages site). Neither has lightshafts or rays.

[Edit Just checked the shader code. It uses PS3 and the machine I used doesn't support it. Must try harder. ]
david w
18
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 14th Feb 2012 18:37 Edited at: 14th Feb 2012 19:08
@GG here is a PS 2.0 version you may be able to increase the number of samples if you use PS 2.a/b but I think the results are nice with this version.

I tried to use the unroll(x) modifier, with the for/loop and also a while/loop. It did not work, so I had to resort to unrolling it manually. I think you will agree the results are fairly good. I don't think more samples would really get any better results.

The only improvement I can think of is to make the loop work but that is only code "looking tidy" thing vs. a functionaly mod. Because in the background the unroll should just do what I did only "for us".



I know its ugly but it works with ps 2.0 and the results are nice.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th Feb 2012 19:06 Edited at: 14th Feb 2012 19:10
Thanks.

That should be useful for those who only have PS2 - I have PS3 and 4 on my main machine but forgot I was using my old laptop when I tested the code before and that only supports PS2.

Edit It should be possible to combine the two into one shader with two techniques so the user's code can just use the technique supported by their hardware. I'll see if I can amend Evolved's demo to do that. It'll have to wait a few days though.
david w
18
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 14th Feb 2012 19:11
Its the loop that is not getting unrolled by the compiler, it should, but for some reason it will not unroll. Anyways it works with good results.

Can we say HLSL accomplished on this one? Or do we need to do more? (Evolved did it already!!!!!!!).

Hahaha. I'm always one step behind that guy!!!
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th Feb 2012 21:38
Quote: "Or do we need to do more?"


Probably. Haven't checked properly yet but I didn't see any shadowed shafts such as you might get from a window. His demo might be a useful starting point though.
nruser
16
Years of Service
User Offline
Joined: 22nd Dec 2007
Location: Serbia
Posted: 15th Feb 2012 00:49 Edited at: 15th Feb 2012 01:19
for light scattering shader david w posted just a few things

set SampleNum to 64 and Density to 0.64f

comment this line

and add this


change

to


change

to


this way it will be the same as original light scattering shader, and light shafts are more visible this way
nruser
16
Years of Service
User Offline
Joined: 22nd Dec 2007
Location: Serbia
Posted: 16th Feb 2012 21:00
when number of samples is reduced then screen becomes much brighter, when there is more or less then 64 samples some angles show trails from the effect how can i fix this?

is there a way to make more noticeable light beam with this shader?
nruser
16
Years of Service
User Offline
Joined: 22nd Dec 2007
Location: Serbia
Posted: 18th Feb 2012 18:35
Maybe i am asking too much, but still is there a way to use ssao with pixel shader 2, wanted to use evolved shader but my graphics card doesn't support vertex/pixel shader 3. Also if there is no way to port this to pixel shader 2, can this effect be achieved by using mask or lerp texture? i was thinking to add ambient occlusion map to my shader that supports diffuse/height/normal/specular/emissive maps
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Feb 2012 18:57
Quote: "wanted to use evolved shader but my graphics card doesn't support vertex/pixel shader 3"


It might be possible to convert it to PS2 by using extra passes. Won't know till I look at the code properly.

Quote: "i was thinking to add ambient occlusion map to my shader that supports diffuse/height/normal/specular/emissive maps"


You can add an ambient occlusion map easily - you just need to make sure you are using the correct UV coordinates for it. But if I've understood you correctly that is a completely different effect. As long as you use 8 (or fewer) textures and don't exceed the instruction count limits (per pass) it should be OK.
nruser
16
Years of Service
User Offline
Joined: 22nd Dec 2007
Location: Serbia
Posted: 18th Feb 2012 19:07
well i want to use ambient occlusion but i don't know does using a texture or evolved's shader will have same or at least close enough effect
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Feb 2012 21:53 Edited at: 18th Feb 2012 21:53
I don't think they are the same. Ambient occlusion refers to the fact that corners, hollows, alleys, etc, tend to be darker because they only receive ambient light from certain directions. It's different from shadow. Screenshot from Dark Lights demo:

Attachments

Login to view attachments
nruser
16
Years of Service
User Offline
Joined: 22nd Dec 2007
Location: Serbia
Posted: 18th Feb 2012 23:13
that is the effect that i want but when i want to apply ambient occlusion map to an object will that give the same effect, according to google images it is supposed to give some sort of self shadowing or something?
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Feb 2012 23:28 Edited at: 18th Feb 2012 23:31
That is what should happen if you have a more complicated object than a simple sphere or cube as in the following screenshot from one of my terrain demos:



This doesn't use Dark Lights - it just uses pre-calculated vertex shading stored in an extra UV channel. I use a shader to apply the shading. I haven't tried Dark Lights with this terrain yet.

Attachments

Login to view attachments
nruser
16
Years of Service
User Offline
Joined: 22nd Dec 2007
Location: Serbia
Posted: 18th Feb 2012 23:43
ok then so i should use both effects (ssao and ao texture applied to object) to get the full effect or just the ssao in ps2 version?
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Feb 2012 01:17
I'm not sure there's any difference between ao and ssao.
nruser
16
Years of Service
User Offline
Joined: 22nd Dec 2007
Location: Serbia
Posted: 19th Feb 2012 15:49
correct me if i am wrong but ao texture will not give the effect like on the screenshot with the sphere, but only on the model, but ssao will do entire ao scene, but may not be correct for more complex models, and that is where ao texture should be used
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Feb 2012 20:36
Oops! My post about self-shadowing was posted on the wrong thread. You'll find a demo you might be interested in buried in this:

http://forum.thegamecreators.com/?m=forum_view&t=194365&b=1

Quote: "correct me if i am wrong but ao texture will not give the effect like on the screenshot with the sphere, but only on the model, but ssao will do entire ao scene, but may not be correct for more complex models, and that is where ao texture should be used"


Not sure I understand what you mean.
nruser
16
Years of Service
User Offline
Joined: 22nd Dec 2007
Location: Serbia
Posted: 19th Feb 2012 21:05
ok never mind, can you convert evolved's ssao shader into ps2.0, also evolved uses to shaders one for ssao and one for blur, you can see this link http://www.gamedev.net/page/reference/index.html/_/technical/graphics-programming-and-theory/a-simple-and-practical-approach-to-ssao-r2753 it should help with this
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 20th Feb 2012 12:14
Hi there GG,
I reviewed your post about self-shadowing:

Quote: "It requires a special horizon map to be created from a suitable heightmap."


I've reviewed the example and the volumetric texture for the horizon map (spots hzmp.dds)

I have a couple of questions,

-Do you have any tips for generating this kind of texture given a normal map?

And,

-I see other two 'special' textures for that shader, "light lookup table2.bmp", and "atan.png", but I guess these are the regular ones to use for any object and/or normalmap, right?

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: 20th Feb 2012 13:23
Quote: "Do you have any tips for generating this kind of texture given a normal map?"


You need a heightmap to do it properly. At the moment I'm using a rather untidy program of my own to create the horizon maps from a heightmap. It uses the method of creating volume textures that Lee described in the Newsletter a while back - but needs additional code for the horizon calculations. It's a rather slow procedure as it involves lots of raycasts (a bit like a lightmap) but like a lightmap only needs to be done once. One day I'll tidy it up and post it (with explanations).

Quote: "I see other two 'special' textures for that shader, "light lookup table2.bmp", and "atan.png", but I guess these are the regular ones to use for any object and/or normalmap, right?"


Not quite. I used the first one in an early attempt to speed up the specular calculations in normal mapping but it isn't really worth including these days since GFX cards are so fast now. I'll remove that when I next amend the shader. I don't use it in my other normal mapping shaders now. By the way, I think the error I mentioned in the demo is the one you noticed some time back. As you know the fixes are simple - I just haven't got around to fixing this particular demo yet.

The second one, "atan.png", is a special texture I made myself for use with the horizon map. The horizon map consists of several layers. Each layer corresponds to a particular XY angle for the light (where Z is "up") and gives the horizon information for each pixel in the heightmap. That angle (a value in the range 0 to 360 degrees) needs to be scaled to the 0 to 1 range for the horizon map texture lookup. The atan texture merely provides that scaled angle from the input XY coordinates of the light direction (in tangent space of course ). It avoids the rather costly atan() HLSL intrinsic function - one case where the texture lookup IS worthwhile. I think I've left the original atan code in the shader for reference.

While I've been writing this I've realised I probably need to adjust the texture clamping used in the shader for the horizon map. Must remember to check that as well.
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 20th Feb 2012 16:17
I see. It sounds somewhat complicated.
I thought it could be a nice addition for planets, asteroids, cloud layers and the spaceship itself.
For example, it would nice to generate an horizont map for the Earth map, but I'm not sure that I've got heightmaps for all my normalmaps.
It would be nice to have an external tool doing the job. Anyway many thanks for the tips
I'll stay tuned and you keep on those shader advices

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 20th Feb 2012 17:44
Quote: "It sounds somewhat complicated."


It is - but the final shader is quite simple fortunately.

Quote: "For example, it would nice to generate an horizont map for the Earth map, but I'm not sure that I've got heightmaps for all my normalmaps"


It would be good to try this idea out with a test case.
McLaine
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location:
Posted: 23rd Feb 2012 14:59
Hi GG,

At risk of being told to read the thread, can you point me at a simple shader to add a glow around a planet?

I've tried your glow shader, and when I eventually got it to work (not your fault) I found that it adds the effect from the perimeter of the object inwards. Not really what I'm after.

I've tried about 5 different planet atmosphere shaders now, and all go to much more detail than I need, and thus are much more complex. I can't seem to figure out which constants I need to set in order to get them to work and it's taking an inordinate ammount of my time to try and work it all out.

I'm basically wanting a simple glow from the perimeter of the object outwards, with the ability to change the range and colour of the glow.

I'm not after anything fancy like light scattering or such. I just want to use shaders instead of a billboard plain for my atmospheres.

ope you can help. Reading through the mass of amazing work and info you've all done on these shader threads makes my brain hurt.

It's not my fault!
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 23rd Feb 2012 19:12 Edited at: 23rd Feb 2012 19:14
Quote: "can you point me at a simple shader to add a glow around a planet?"


Is this any good?

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: 23rd Feb 2012 19:13
Screenshot for glow effect.

Attachments

Login to view attachments
nruser
16
Years of Service
User Offline
Joined: 22nd Dec 2007
Location: Serbia
Posted: 23rd Feb 2012 20:14
you may want to look at render monkey gold coin shader that might be perfect for this
McLaine
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location:
Posted: 24th Feb 2012 12:08 Edited at: 24th Feb 2012 12:08
You sir are a Scholar and a Gentleman!

Thanks VERY much, that is perfect!

@nruser
I have RenderMonkey, and FX composer both. I'll take a look at the gold coin shader, so thanks for that.

I've allways been a gameplay over graphics kind of guy though, and I have limited time available for this hobby. Hence the appeal to you guys for help as I couldn't justify the ammount of time I was spending vs the end benefit trying to work it all out.

I will get the hang of shaders eventually.

Thanks again GG!

It's not my fault!
McLaine
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location:
Posted: 26th Feb 2012 16:54
Right, I plugged that in and it works as demo. Thankyou very much.

Only problem with it is that the glow changes wierdly from full to non existent as I move the camera around the planet.

I guess something needs to be added to the shader regarding camera position?

It's not my fault!
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 26th Feb 2012 20:42 Edited at: 26th Feb 2012 21:16
Quote: "Only problem with it is that the glow changes wierdly from full to non existent as I move the camera around the planet."


Doesn't surprise me. It was just a first stab at it to show you the basic idea. It's hard to guess in advance how any given shader is going to be used so I kept it simple and waited for questions - and here they are.

Quote: "I guess something needs to be added to the shader regarding camera position?"


Quite likely. I'll have a look and see if anything obvious springs to mind.

Edit Just added camera movement and I see what you mean. That wasn't supposed to happen. I'll see if I can find a fix and report back. That's blown another quiet Sunday evening.

Edit2 OK. Identified the source of the error. It was a math/logic error. Will try to fix it.

Edit3 Is this fixed version OK?

Attachments

Login to view attachments
McLaine
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location:
Posted: 27th Feb 2012 20:34
Awesome GG!

Nice one mate, thanks for taking the time.

It's not my fault!
cyril
17
Years of Service
User Offline
Joined: 6th Aug 2007
Location: 7 miles away from big ben
Posted: 7th Mar 2012 23:43 Edited at: 7th Mar 2012 23:54
I wasn't sure where to post this, but here seems like a good place, I recently being playing around with Nvidia's shaders to see whether they work in DBpro correctly and if it appears to look undesired effect. And attempt a tweak with the very limited knowledge I have with shaders. Along with many failures, I was able to finally get nvidia’s “ddgodray.fx” working correctly in DarkBasic Pro, obtaining the desired effect, and it was fairly simple change.

The Screen Shots below will show what was done, with the source code below each image. With a Zip attached to demonstrate the difference in two example programs.

Notice in this screenshot a dark grey (Near black) overlay where the rays are has no transparency:






Notice in this screenshot the dark grey overlay has been removed and the wall object texture can be seen through the god ray:







Edit: Trying to fix BBcode mistakes
Edit 2: BBcodes fixed

Attachments

Login to view attachments
mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 17th Mar 2012 09:15
Hello guys! Is it possible to rotate object\limb\part of limb using shader?
Brendy boy
19
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 17th Mar 2012 14:03
Quote: "Hello guys! Is it possible to rotate object\limb\part of limb using shader? "

yes, but in a case you want a different angle for every object/limb you'll have to have a separate shader for every object/limb (that could lead to slowdowns).

Dar13
16
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 17th Mar 2012 21:41 Edited at: 17th Mar 2012 22:59
Hey everbody, I need some shader help.

Mainly, it's with alpha blending between two different textures, the one that's applied to the model and a separate texture that I want to scroll over the model texture while maintaining the base model texture. Since I have absolutely no experience with shaders or HLSL, I've co-opted the DarkShader Scrolling Texture shader since it already has the basis. All I've done is add another texture(i think), and add alpha blending(I think).
This is the result:


So I've got DarkShader to recognize that the shader requires two shaders, and it even scrolls properly. However, the original model texture(which has transparency) is wiped out.

Here's the shader code:


Thanks for any help you can give!

James H
17
Years of Service
User Offline
Joined: 21st Apr 2007
Location: St Helens
Posted: 17th Mar 2012 22:47
Im no good either, but I merged yours with the existing blend shader in ds and I think this is what you want?

Login to post a reply

Server time is: 2024-11-23 21:32:45
Your offset time is: 2024-11-23 21:32:45