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
chunks chunks
17
Years of Service
User Offline
Joined: 2nd Jan 2007
Location: ackworth uk
Posted: 25th Aug 2008 16:04 Edited at: 26th Aug 2008 00:43
almost got it at least it`s sparkling now just need to sus out the light .

getting a bit used to fx composer too , like how you can quickly change values and see it instantly.


see attached for finished shader+example ,thanks to gg for the help.

toshiba satellite 1.6 core duo + nvidia geforce go 7300
windows xp pro.

Attachments

Login to view attachments
AtomR
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Portugal
Posted: 27th Aug 2008 22:22
Heya,
Shader noob here. I once altered DarkCoder's texture blend shader to use the 6th texture as a lightmap. And now I need to have a shader that will, regardless of what texture my model has, color/tint that texture a certain color. And here I'm thinking that its as simple as adding a light map to a preexisting texture. So I pick up darkcoder's shader again and set out to alter it to "lightmap" one single texture. But the texture comes out black all the time



just when i thought i was getting the hang of this it bytes me in the ass

Take care
AtomR
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 27th Aug 2008 22:33
I'm pretty sure the error there is you use using the .rgb at 'cloudscolor.rgb', unless I'm mistaken this can only be done on lines such as 'float4 BaseMap = tex2D( BaseSampler,IN.UV0);' where the sampler is assigned on the same line as when the float4 in this case is declared, by default you have to use .xyzw, or .xyz here.

This might not be the issue but that's all I see from a first glance, you might want to check and output any shader errors so you can see the error(s) yourself(which can be done using native DBPro).

Math89
20
Years of Service
User Offline
Joined: 23rd Jan 2004
Location: UK
Posted: 27th Aug 2008 22:40
The problem may be the IN.Diffuse variable. In order to get the vertex colour in the shader, you need to change the fvf format of your object, and then, change manually the colour using the vertexdata commands.

AtomR
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Portugal
Posted: 27th Aug 2008 22:54
I've used
BaseMap.rgb *= IN.Diffuse * cloudscolor.rgb;
BaseMap.rgb *= IN.Diffuse * cloudscolor;
BaseMap.rgb *= IN.Diffuse;

all these return a black texture. I'm starting to think the in.difuse is the problem. Where is that value coming from? The object? Is it possible the object has difuse values = 0?

How can I output shader errors within dbp?

Regarding your comment where we can only use .rgb while declaring the float4, I don't know tbh. I've used
BaseMap.rgb *= IN.Diffuse * (Layer5Map.rgb *LM_Multiplier );
to apply lightmap to your original texture blend shader. And it works. *let me try without the .rgb see if it works* Yep works either way.

Take care
AtomR
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 28th Aug 2008 00:14
AtomR

If you merely want to use a single colour for tinting the texture then you don't need your object to have vertex diffuse colours - just declare a new variable (a "tweak") at the top of the shader, e.g.



and then use it just as you've used the variable In.Diffuse. That way you only have one variable that you might want to set in DBPro.

If you really need each vertex to have its own diffuse colour then you'll need to do what Math89 suggested - plus what you were doing before.
AtomR
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Portugal
Posted: 28th Aug 2008 10:58
Oh I missed Math89's post. Must have happen while i posted mine.
It's working now. As you said GG just removed the in.difuse and kept the cloudscolor variable. I could have sworn i had tried that before but the truth is it never worked before so i'm probably mistaken.
Thank you guys for your precious help ^^

Take care
AtomR
AtomR
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Portugal
Posted: 28th Aug 2008 17:08 Edited at: 28th Aug 2008 20:23
Ok, that is almost what i want.
Look at the attached pic.
The top is my original texture and the bottom is more or less the result I get with the shader with the following trasformation:


Quote: " float4 PS_TextureBlend(TextureBlend_Output IN) : COLOR
{
float4 BaseMap = tex2D( BaseSampler ,IN.UV0)*cloudscolor;
return BaseMap;
}"


How could i get the texture to come out like the one in the middle? I may have phrased it wrong when I said i wanted to tint it. Maybe its best said like give it a hue? Not sure but u see what i mean in the pic.
Is it a simple calculation? Or will that require a lot more complex algorythm?

Thx

Take care
AtomR

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: 28th Aug 2008 19:16
Quote: "Not sure but u see what i mean in the pic."


Yes.

Quote: "Is it a simple calculation?"


Yes.

Quote: "Or will that require a lot more complex algorythm?"


Depends on how experienced you are.

You will be most of the way there when you've described precisely what you want - then all you have to do is translate your precise description into code. After all, code is nothing more than a translation from your own language into the machine's language.

To take your example, the third image has just removed the green and blue from the image so it just looks red. But I guess you only want it to look red when the overall brightness is dark.

So, you need a calculation which measures the overall brightness of the texture pixel. See if you can do that. Let's call it "float brightness" - and assume you've arranged for it to be in the range 0 to 1.

Then, you need to decide how to modify the calculation you used for your third image. You probably want the final pixel colour to be somewhere between the original colour ("float4 originalColour" say) and the red tinted colour ("float4 tintedColour" say).

If "brightness" is 1 then you want the original colour, if it's 0 then you want the tinted colour. For values inbetween just use the "lerp" intrinsic function:



You already have tintedColour and originalColour (under other names ) so all you have to do is to decide how to calculate the float "brightness".

Something along those lines should work.
AtomR
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Portugal
Posted: 28th Aug 2008 21:09
Ok i like doing stuff in steps. so before going headlong into the calculation of the brightness i wanted to make sure i could make the shader work with a constant number so i tried

Quote: "
float4 BaseMap = tex2D( BaseSampler ,IN.UV0);
float4 FinalColor = lerp(cloudscolor,basemap,0.5);
BaseMap *= FinalColor;
return BaseMap;
"

And this does not compile. I remove the line with the lerp command and it compiles.
As far as i know (which is very little) that lerp line should find me the color that is halfway between couldscolor and basemap color, correct?

Take care
AtomR
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 28th Aug 2008 22:36
Quote: "Ok i like doing stuff in steps."


Good idea - sorry for the delay in getting back, I'm cooking supper.

Here's your problem:

In one place you have



in another



Check the case of all your variable names. HLSL is case sensitive for variable names, but not for semantics. For example,



and



are equally acceptable.

This sort of detail is hard to find in the documentation (if you can find it ).
AtomR
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Portugal
Posted: 28th Aug 2008 23:14 Edited at: 29th Aug 2008 01:08
Quote: "Check the case of all your variable names. HLSL is case sensitive for variable names, but not for semantics. For example,"


Well, thank you very much for that little piece of valuable info ^_^
You've actually helped me in two cases. One is that the code now compiles and the other is why I wasn't being able to control the tint color from within DBPro. Was sending the variable in lowercase when the shader has capitals

There is a bitersweet taste to the fact that this shader now works. On the one hand it does not do what I'm looking for. On the other hand it does another very very cool effect where the higher the intensity (or brigtness as u called it earlier) the lesser the saturation of the texture.

Quote: "float4 BaseMap = tex2D( BaseSampler ,IN.UV0);
float4 FinalColor = lerp(cloudsColor,BaseMap,Intensity);
BaseMap *= FinalColor;
return BaseMap;"


Which, coupled with a very simple sin function, produces the effect as shown in the attachment, of clouds dissipating


-Edit-

Sorry. My mistake. I had float4 BaseMap = tex2D( BaseSampler ,IN.UV0)*cloudsColor; so it was being painted from the start. Now its working more like I want it but with very dull colors. I want it more vibrant. I'll have to check it out l8r. I'm tired and my head actually hurts from trying to wrap itself around this. Tomorrow is a new day.
Thx for the help, m8.

Take care
AtomR

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: 29th Aug 2008 01:15
Quote: "On the one hand it does not do what I'm looking for."


I'm not surprised.

I wondered earlier why you included the final multiplication:



I didn't call "FinalColor" that by mistake you know.

Try the following instead of your code:



or even



Of course, you still need to replace "0.5" by the brightness variable calculated per pixel (your screenshot suggests you used the same value of brightness throughout the image).

Quote: "On the one hand it does not do what I'm looking for. On the other hand it does another very very cool effect where the higher the intensity (or brigtness as u called it earlier) the lesser the saturation of the texture."


That's one of the joys of playing with shaders.

Here's the final code I had in mind including the brightness calculation (you'll have to check consistency of letter case and spelling etc)



I expect at least one question from that snippet.
AtomR
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Portugal
Posted: 29th Aug 2008 02:37 Edited at: 29th Aug 2008 12:37
On my last attempts I was getting the brightness from the BaseMap alpha channel. But as I said previously the result is a very bland color.

I can't compile your last code snippet. I have looked thoroughlly for letter casing and spelling error and can't find any. I'm tired so I may be missing them but tomorrow morning i'll look again.
From what I can understand u are multiplying BaseMap rgb components by .33(3) which means that your gonna get the same color only darker? Nah that can't be it. Brightness has to be a value between 0 and 1.

HMMM! So, just out of curiosity, if any color component assumes values 0 to 1, what values does the end color assume? 0 to 1 aswell? Or can't we talk about one single value to determine a color in HLSL like we do in DBP?

Take care
AtomR
CSGames94
16
Years of Service
User Offline
Joined: 27th Dec 2007
Location:
Posted: 29th Aug 2008 07:18
Anybody know how to get fullscreen shaders working in Dark Shader because I had them working before, then I figured out how to pass light to the normal mapping shader, then the fullscreen shaders stop working. And I don't have a clue why it isn't working now. But everytime I run the example code it works, but then when I try to put it into my project it 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: 29th Aug 2008 12:39 Edited at: 29th Aug 2008 12:40
AtomR

Quote: "I can't compile your last code snippet. I have looked thoroughlly for letter casing and spelling error and can't find any. I'm tired so I may be missing them but tomorrow morning i'll look again."


I think I need to see your whole pixel shader. I tried to follow your style of coding, but might have made an error.

Here's the complete pixel shader I was using plus a screenshot of some tinted and untinted clouds. I think that was the effect you were originally after.

Pixel shader:



Screenshots:



Quote: "Nah that can't be it. Brightness has to be a value between 0 and 1. "


Quite right. The line you refer to is calculating the average brightness. Since there are three colour components they are each multiplied by 1/3 and then added together. This is the same as adding the three together and then dividing the total by three. The code I used is just a coding shortcut. The quantity "0.33333333.xxx" is a float3, i.e. (0.33333333, 0.33333333, 0.33333333) - this works because "0.33333333" is just a float1 so its 1st (only) component can be accessed using "0.33333333.x". Hence to get three copies of the first component I just repeat the "x"'s.

Quote: "I can't compile your last code snippet."


Afterthought: what shader version are using for compiling? I suspect that ".xxx" trick I've used requires PS2.

If you are going to do much with shaders then you need something like Dark Shader - that will give you error messages which help diagnose compilation issues.

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: 29th Aug 2008 12:46
Master13

I think we need a bit more to go on. You are obviously doing something different in your code, so without the working and non-working versions to compare we can't tell you much.
coolgames
19
Years of Service
User Offline
Joined: 26th Sep 2005
Location: Oregon, USA
Posted: 31st Aug 2008 06:18
I've been working on a shadowing method for shadowing vegitation on a terrain. I've attached a demo exe. Right now it doesn't cast shadows onto the terrain itself, but only onto other vegitation. You can press enter to view the depth map. This is pretty gpu intensive, but looks pretty cool. I'm running this at about 15-20 fps on a Geforce 8400 GS.

Attachments

Login to view attachments
coolgames
19
Years of Service
User Offline
Joined: 26th Sep 2005
Location: Oregon, USA
Posted: 31st Aug 2008 06:20
Here's a screenshot:

Attachments

Login to view attachments
Math89
20
Years of Service
User Offline
Joined: 23rd Jan 2004
Location: UK
Posted: 31st Aug 2008 12:25
Hmm, less than 1 fps on a geforce 7600...

AtomR
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Portugal
Posted: 2nd Sep 2008 18:58 Edited at: 3rd Sep 2008 12:52
Sorry it took me so long to reply but last friday my modem stoped working and i finally managed to borrow another modem.

The shader is now working

This is not "my way of coding". I just altered Darkcoder's shader so its more his way then mine. I don't know shaders well enough yet to have a way of coding

Why is it that the texture looks low res now? :/



Take care
AtomR

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: 3rd Sep 2008 00:14
Quote: "Why is it that the texture looks low res now? :/"


Hard to say without seeing comparable "before" and "after" images side by side.

Glad you got it working (more or less).

P.S. Could you fix the tags on your post, i.e. code instead of quote? (Done it myself before now. )
Bad Monkey
17
Years of Service
User Offline
Joined: 1st Jan 2007
Location:
Posted: 3rd Sep 2008 02:04 Edited at: 3rd Sep 2008 02:23
I thought I would just post to report how far I've come into shaders. I've been developing a demo game showing a lot of evolved's shaders. Here is the url:

http://www.artistsareus.com/sellingmedia/darkhills.htm

Some Pics for those that don't like clicking links:






Visit my website:
http://www.artistsareus.com
coolgames
19
Years of Service
User Offline
Joined: 26th Sep 2005
Location: Oregon, USA
Posted: 3rd Sep 2008 02:42
Okay. I got my shadow grass engine thing to work at a hopefully more decent framerate. For the grass, I was using a seperate instance for each single patch. I changed it so that more than one patch was contained into a single object. Reducing how many objects there are from 1000 to 150. I've attached the new demo. You can set the resolution of the shadow map, and how far the shadow map can see.

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: 3rd Sep 2008 12:37
Bad Monkey and coolgames

Some fine demos there.

Coolgames, your demo runs at about 5 to 9 fps on my dinosaur so it will probably be OK on modern machines. Only problem I noticed was that you could see the grass suddenly "growing" as you moved the camera forward. Can that be fixed? Beautiful scenery though, nice work.
AtomR
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Portugal
Posted: 3rd Sep 2008 12:49 Edited at: 3rd Sep 2008 17:47
I don't know if this is a good method or not but what i usually do for fading leaves/grass is edit mipmaps manually in an image editor. I make it so that the leaves gradually fade more and more and the last mipmap is just a 2x2 transparent texture. It give a quite nice fade effect.

Only problem is that u can't manually set the leaves to fade out when u want but rather when the graphics cards decides its time to change mipmap texture. So that means that if your objects slow your computer u can't reduce the draw distance but instead have to reduce foliage density.


-EDIT-
Fixed my /quote to /code tabs.
Regarding the problem on my pic i think its not a problem with the shader. I've tested with my previous version and I still get that pattern on the texture when there was any 2 days ago. I'll have to check what's wrong with either drivers, DX or the card itself.

Take care
AtomR
James H
17
Years of Service
User Offline
Joined: 21st Apr 2007
Location: St Helens
Posted: 3rd Sep 2008 14:00 Edited at: 6th Sep 2008 17:37
AtomR - I have similar problem, though I can live with it for now as I`m building a scene with non shader options, attatched is something I would like to see developed further, I`m just a little snowed under with real life right now. Use "-" & "=" to alter the relevant value. Note that on other cards this too has issues with regards to the fade value being affected by distance, and the only mipmaps used are generated by DBP. In addition to this the overall appearance of the texture is not the same as it was originaly.
Perhaps the answer lies in the mipmapLODbias area - I seem to recall reading this term several times in help documents but anything I have tried in the past simply fails. Obviuosly I have no clue what I`m doing. Here is a vid on youtube of what it should look like(vpoor quality): http://uk.youtube.com/watch?v=aLEjx4T2tuk
download dbp files & media : https://forumfiles.thegamecreators.com/download/1523990
James H
17
Years of Service
User Offline
Joined: 21st Apr 2007
Location: St Helens
Posted: 3rd Sep 2008 14:10 Edited at: 6th Sep 2008 15:35
Youtube alters the quality so attached is what it appears like on my machine

Edit: I forgot to add that cjb2006 wrote the shader with help from the community, I just added to a couple of lines and as the results dictate I think I`ve gone about this the wrong way, so when I said "develop further" I really meant "would like to see the correct method/be pointed in the direction of"

Edit: oh dear, it would seem that when I tested on sm2.0 ati cards the fx file wasn`t the same - it still had 1.4 for the pixel shader - it only works succesfully when 2.0 is in place! So it does work - guess the trick is to darken the texture a little before hand

Attachments

Login to view attachments
BlobVanDam
16
Years of Service
User Offline
Joined: 26th Jul 2008
Location: one of Cybertrons moons
Posted: 8th Sep 2008 20:22
Little help - I'm trying to apply a glow/bloom shader to just one object, not the whole screen. Is there a simple way to do this? I'm actually considering just getting DarkShader now if that helps. It looks like it might be better for full screen type effects, and might do what I want.
chunks chunks
17
Years of Service
User Offline
Joined: 2nd Jan 2007
Location: ackworth uk
Posted: 10th Sep 2008 03:17
another shader i`ve edited from the render monkey IridescentButterfly example ,still not working quite correctly seems to muddle the base texture up..

anyways take a look ...

chunks

nvidia geforce 8600gt + amd athlon 64
windows xp pro.

Attachments

Login to view attachments
wh1sp3r
21
Years of Service
User Offline
Joined: 28th Sep 2003
Location: Czech republic
Posted: 13th Sep 2008 10:54
Could you recommend me any good book for beginner ? With working examples in dbpro ? Thank you


PS: Real programmers aren't afraid of math!.
Lover of games
19
Years of Service
User Offline
Joined: 17th Apr 2005
Location:
Posted: 24th Sep 2008 14:58 Edited at: 24th Sep 2008 15:11
I've been learning shaders my self, got a book on it and everything. i wanted to know how you'd fade into a render target, like you know how some movies fade in, i guess what i'm asking is making a fad in filter.

EDIT: I tried it my self and got this weird looking thing. not sure if that's even an effect or a mistake but looks cool.

"Originally I was going to have a BS on it but you know how that would be. I can't walk around with the letters BS on me." More or less a qoute by Syndrome from Jack, Jack, attack

Attachments

Login to view attachments
mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 29th Sep 2008 09:09 Edited at: 2nd Oct 2008 09:10
@DC
thanks for shadow shader, its good-looking!
(but have some problems with self-shadowing)

EDIT

@all

btw, how to turn ghosting in shader?
and can i use 8bit alpha from texture? (i mean smooth alhpa)

i know that i must write smth in compile part of shader,
so could you help me?

EDIT

@Green Gandalf
Just saw your nice 'smooth alpha' shader, but when I wrote code from copile part to my shader, smooth alpha didn/t work.

A door is a door is a door. Even a swinging one. =0
BlobVanDam
16
Years of Service
User Offline
Joined: 26th Jul 2008
Location: one of Cybertrons moons
Posted: 2nd Oct 2008 19:10
Is there any other method to do a cartoon outline than the basic method as used by the ultimate shader pack version? All it does is extrude the geometry and invert the face normals. It looks fine for most circumstances, but for what I'm doing, my object is interacting a lot with the environment, so the cartoon outline is often clipping through objects and looking a bit nasty. It's hard to avoid this happening, so is there another way to fix this? I don't care if the shader is more complex, this thing is only designed for one particularly fast machine anyway
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 2nd Oct 2008 19:21 Edited at: 2nd Oct 2008 19:22
The wiki page on it describes a screen-space way to do it, of course it doesn't give exact implementation details but I'm sure you can find resources on the Sobel Edge effect and can quite easily create a stepped texturing effect(scaling the colours, casting to int etc).

BlobVanDam
16
Years of Service
User Offline
Joined: 26th Jul 2008
Location: one of Cybertrons moons
Posted: 2nd Oct 2008 20:39
hmm I wonder how well that would work on one object though? I'm not applying it to the whole scene unfortunately. Worth a try though. Thanks I'll look into that. Shouldn't be too hard if I break it down into each element
CSGames94
16
Years of Service
User Offline
Joined: 27th Dec 2007
Location:
Posted: 12th Oct 2008 04:23
Using the bloom Shader in Dark Shader, how do you make specific parts on a object glow?
AtomR
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Portugal
Posted: 27th Oct 2008 01:59 Edited at: 28th Oct 2008 16:46
I've added fog to my version of Texture blend shader (i'm very proud of myself ^^). But i want more Is it as simple adding exponential fog as it was adding linear fog? Better yet, what is exponential fog? Fog that starts off as thin but gets exponentially thicker as it reaches the maximum distance?

-EDIT-
Another question. We can only have 8 textures per object correct? Is that a Direct X limitation or a darkbasic limitation? Just curious about that. My goal is to have a terrain shader that includes texture blend, shadow mapping, fog and bump mapping.
Best way would obviously be to have 1 bump map per texture but with an 8 texture limitation that's not possible unless u go with 3 textures + 3 bump maps and 2 masks. One way of doing it could also be if we reduce the color depth of the textures. Say, instead of having a bitmap where each pixel could have R(255)G(255)B(255)A(255) we could divide each component into R(127)R(127)G(127)G(127)B(127)B(127)A(127)A(127). Where we would get the info for the texture from the first half of each component and then the bump map from the second half of each component. Granted texture quality wouldn't be the best but maybe the effect would compensate.

-EDIT-

I still believe the previous method can be implemented. Just haven't wraped my head on how it would. But another way of doing it would be to have a black and white bump map and use the alpha channel to store that bw bumpmap. Wouldn't be as good looking as a normal map but it would preserve the original texture quality and add a bit of bump

Take care
AtomR
BlobVanDam
16
Years of Service
User Offline
Joined: 26th Jul 2008
Location: one of Cybertrons moons
Posted: 13th Nov 2008 16:03 Edited at: 13th Nov 2008 16:17
edit: nevermind, I just solved my own prob
chunks chunks
17
Years of Service
User Offline
Joined: 2nd Jan 2007
Location: ackworth uk
Posted: 18th Nov 2008 19:57
here`s a object brightness shader i did following the shader tut`s from the convention vids .

usually i just edit shaders but following this video i wrote it from scratch and i now understand them much better , the vid is highly recommended .

nvidia geforce 8600gt + amd athlon 64
windows xp pro.

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: 18th Nov 2008 21:05
Quote: "here`s a object brightness shader i did following the shader tut`s from the convention vids "


Yes. Mike's presentation was very good.

Glad to see you're writing your own from scratch - that one's a good way to start.
darkvee
19
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 26th Nov 2008 23:25 Edited at: 27th Nov 2008 05:43
Hi this is Vee
I want to know how to make this shader. How do you make the height map, and then convert it to a normal, so its a normal map generator on a shader?

here is what I have now for the shader.



or
http://img34.picoodle.com/img/img34/3/11/26/f_normalm_0187534.jpg

Vee
BlobVanDam
16
Years of Service
User Offline
Joined: 26th Jul 2008
Location: one of Cybertrons moons
Posted: 27th Nov 2008 08:34 Edited at: 27th Nov 2008 08:45
I've been working with this environment bump map from the ultimate shader pack, and I'm trying to get a second set of UVs in there so I can use my lightmap, except the shader stops working with any attempt I have at getting the second UV set into the pixel shader.
As you can see I've already added the second UVs to the input, but every time I add an extra TEXCOORD to the output, it stops working. I thought it was a limitation of the pixel shader version, so I tried up to 3, and it still wouldn't allow it, and FX Composer didn't seem to see a problem with adding the extra TEXCOORD, but in DBP nothing I do will work. What am I doing wrong?



edit: Don't worry, I figured it out. Basic problem of being a float3 instead of a float2
And it took me two days to notice this. Learning the hard way!
BlobVanDam
16
Years of Service
User Offline
Joined: 26th Jul 2008
Location: one of Cybertrons moons
Posted: 6th Dec 2008 07:00
Ok, I've got another problem now. I've got a skybox, and I'm using the evolved pixel shader to texture it with a cubemap I have. I'm doing it this way because later on I'm going to do some fade and other fancy colour effects on it. That all works fine. The problem is that now I want to be able to rotate the cube map, but I can't get that to work with a TexCUBE lookup.



I tried many things, but I couldn't get anything working. I just don't know what format to store the additional rotation in or where to add it to make it work properly. I tried doing it in both the PS and VS with the OUT.View/IN.View, but it didn't work for me. I was trying stuff with a basic float3, but I have a feeling that is wrong, and anything beyond that is probably a bit beyond my knowledge.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th Dec 2008 22:09
Quote: "The problem is that now I want to be able to rotate the cube map, but I can't get that to work with a TexCUBE lookup."


Interesting question. Haven't tried this myself so the following immediate thoughts come with a health warning.

0. A skysphere would probably be simpler - but then you would probably need a different cubemap.

1. I assume you are rotating the skybox at the same time in the same way? If not you could get strange results.

2. Assuming you are rotating the skybox as well then you probably need to calculate the corresponding rotation matrix (this will be a 3x3 matrix - but stored, IIRC, in the upper left 3x3 part of a matrix4 with zeros in the unused cells) and pass this to the shader using set effect constant matrix (the shader will need an appropriately declared matrix of course - "rotationMatrix" perhaps?).

3. Then add a bit of code to the pixel shader to apply the rotation to the view vector, i.e. something like



You may find it worthwhile browsing through the 3Dmath commands - there might be something useful there.

But then again, there might not.
BlobVanDam
16
Years of Service
User Offline
Joined: 26th Jul 2008
Location: one of Cybertrons moons
Posted: 13th Dec 2008 16:11
I have a question to the programmer/s of DBPro and anyone else who knows a bit.
In a programming language like C++, would there normally be a way to apply a shader directly to an image rather than an object? So you can just use it to directly manipulate images rather than apply it to an object? Because I've been thinking, when I have a camera rendering to an image, and I want to say for example blur the camera image for a bloom effect or something, that is being applied to every pixel of the object, right? So if I'm rendering the camera to a 256x256 image and texturing to a plane that covers the whole screen at 1024x768, it's running that shader for 1024x768 pixels instead of only the 256x256 it needs to.
Now I might be way off course here, but that's what I'm thinking. If this is so, then a lot of performance could be gained for that type of effect if you could for example load a pixel shader and apply it to an image either manually, or automatically every frame like a regular object without the extra.
Someone tell me if I'm just crazy here. I don't claim to be an expert on any of this, it's just been bugging me for a while.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 13th Dec 2008 17:54 Edited at: 13th Dec 2008 17:54
Quote: "Because I've been thinking, when I have a camera rendering to an image, and I want to say for example blur the camera image for a bloom effect or something, that is being applied to every pixel of the object, right? So if I'm rendering the camera to a 256x256 image and texturing to a plane that covers the whole screen at 1024x768, it's running that shader for 1024x768 pixels instead of only the 256x256 it needs to."


Interesting question.

Depends on what image ("surface") you are rendering to with the shader.

You're going to want to put something on the screen at some point - but I guess before you do that you can work with lower resolution images as you suggest. In other words, do all your complicated rendering, blurring, bloom, etc, using low resolution cameras other than the screen image (camera 0). Then at the end put the final image on the screen without any additional processing. Of course if you do that for the whole screen then you don't really need 1024x768 resolution do you?
BlobVanDam
16
Years of Service
User Offline
Joined: 26th Jul 2008
Location: one of Cybertrons moons
Posted: 13th Dec 2008 18:08
Well obviously I want my main program running as high res as I can, since it looks nicer and my computer can general handle it with ease. But when you've got an intensive effect like a high quality blur with many samples, you really start to see a performance hit when you up the resolution, when if it were only applying the shader to the same size image regardless of camera 0, it doesn't matter so much.
But if it's not necessary to run my bloom shader for every pixel on the screen, then there's no reason I'd need to drop the resolution of my main program.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 13th Dec 2008 18:28
Quote: "But if it's not necessary to run my bloom shader for every pixel on the screen, then there's no reason I'd need to drop the resolution of my main program."


True - but then what do you mean when you say:

Quote: " So if I'm rendering the camera to a 256x256 image and texturing to a plane that covers the whole screen at 1024x768, it's running that shader for 1024x768 pixels instead of only the 256x256 it needs to."


If the shader is rendering to a 256x256 image you don't have a problem do you?

The shader will be rendering to whatever image your rendering camera is rendering to.

Perhaps I've misunderstood what your problem is.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 13th Dec 2008 20:24
I didn't think you could do that - I THOUGHT that shaders work on Mesh or the entire screen... but I'm NOT the expert in this topic for sure!
--JAson

Login to post a reply

Server time is: 2024-11-24 13:33:37
Your offset time is: 2024-11-24 13:33:37