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: 13th Dec 2008 23:40 Edited at: 16th Dec 2008 00:38
Quote: "I didn't think you could do that - I THOUGHT that shaders work on Mesh or the entire screen"


You can - see attached demo.

Edit Included the dba file this time.

Attachments

Login to view attachments
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 14th Dec 2008 03:31
@Green Gandalf - I think you forgot the *.dba file .. No Worries

BlobVanDam
16
Years of Service
User Offline
Joined: 26th Jul 2008
Location: one of Cybertrons moons
Posted: 14th Dec 2008 05:15
Quote: "
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. "


Now we're both confused!
With how DB works, I believe the shader would be applied to the plane mesh that is being rendered to camera 0, so I think the number of pixels it applies to is entirely dependant on the resolution of camera 0, not the 256x256 that I'm rendering my other camera. The mesh the shader is applied to isn't being rendered to my second camera obviously, as it's just a render of itself anyway.
And I'd like to see your demo, but as jason said, you seem to have forgotten the dba file
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Dec 2008 00:36
Quote: "@Green Gandalf - I think you forgot the *.dba file .. No Worries "




Just uploaded the zip file again - with dba included this time.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Dec 2008 00:49
Quote: "With how DB works, I believe the shader would be applied to the plane mesh that is being rendered to camera 0, so I think the number of pixels it applies to is entirely dependant on the resolution of camera 0, not the 256x256 that I'm rendering my other camera."


You could have the following sequence:

1. render a really complicated scene with lots of fancy shaders to camera 1 using a low resolution image, image 100 say
2. hide or exclude every object from the original scene
3. render a correctly positioned plain (or other object), textured with image 100, to camera 0.

No shaders need to be involved with step 3.

The demo does step 1. I'm sure you can figure out the rest.
BlobVanDam
16
Years of Service
User Offline
Joined: 26th Jul 2008
Location: one of Cybertrons moons
Posted: 16th Dec 2008 07:08
But the problem with that is that the scene is actually only rendered at low res. I actually want the main scene running at the higher resolution, I just don't want to have to apply that one shader effect to the whole screen, just the image. In your scenario, the main scene is being rendered to the low resolution map and just stretched out to the higher resolution isn't it?
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Dec 2008 11:09
Quote: "I actually want the main scene running at the higher resolution, I just don't want to have to apply that one shader effect to the whole screen, just the image."


You've completely lost me now. Which image are you referring to?

A scene is typically made up from a variety of images applied to various objects, with or without shaders applied to them. The whole scene is also stored as an image - and you can choose the resolution of that image as I've indicated. And you can apply a shader to that image if you want to (via a screen quad for example).

Quote: "In your scenario, the main scene is being rendered to the low resolution map and just stretched out to the higher resolution isn't it?"


If that's what you want - but there isn't much point in doing that.

In your original post on this topic you said:

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."


Sounds very like what you think I've done in the demo - except:

1. I don't really know what you mean when you say "it's running that shader for 1024x768 pixels instead of only the 256x256 it needs to". What shader?

2. If you want to render a 256x256 image to a 1024x768 screen image you're bound to get stretching and possibly some filtering. Why do you need a shader to do that?
BlobVanDam
16
Years of Service
User Offline
Joined: 26th Jul 2008
Location: one of Cybertrons moons
Posted: 16th Dec 2008 14:18 Edited at: 16th Dec 2008 14:19
ok, let me explain this again from scratch, because I know we're both confused here!

Camera 0 is obviously my main scene. Let's say this is being rendered to a res of 1024x768.

My Camera 1 is being rendered to a 256x256 image, and is used for my glow shader. This image is being textured to a quad over the screen on Camera 0.

I have a shader applied to this quad that applies my glow effect to it.

Since that quad in being rendered to Camera 0, and pixel shaders operate on every pixel of the object they're applied to, it is calculating that pixel shader for every pixel that quad is taking up on Camera 0, which in this case is 1024x768 pixels. So the resolution I'm rendering Camera 1 at makes no difference to how many pixels the pixel shader applies to, since the pixel shader and quad are not being displayed in Camera 1.

Hope that's a bit clearer
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 16th Dec 2008 15:34
Quote: "So the resolution I'm rendering Camera 1 at makes no difference to how many pixels the pixel shader applies to, since the pixel shader and quad are not being displayed in Camera 1."


It changes how many texels get rendered however, if your Camera 1 renders to a lower resolution image, then rendering that quad will be faster than if you used a higher res image, this is ignoring the render time for your Camera 1. Of course this speed difference is small and will only affect the sampling time of Camera 1's render target.

With a technique like bloom you could calculate the final blur result before displaying the final image over the main scene, however this requires another pass which could be slower than doing the final blur over the main scene, but you could always test this.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Dec 2008 20:41
Quote: "Since that quad in being rendered to Camera 0, and pixel shaders operate on every pixel of the object they're applied to, it is calculating that pixel shader for every pixel that quad is taking up on Camera 0, which in this case is 1024x768 pixels."


But to be useful you are presumably combining that low res image with the original high res image. Otherwise why have you got the high res screen image at all? I don't really see how you expect to avoid processing screen pixels for the final render. The rendering is faster if the images used in the rendering are lower res. You can easily test this for yourself by rendering a scene with various image resolutions, e.g. 1x1, 8x8, 64x64, 512x512, etc.

Bloom, like soft shadows and blur, can usually be rendered to a much lower resolution than the main screen resolution, so your final screen image could be some sort of combination of the main high res scene image and the various low-res bits used for special effects. This allows you to save some processing time as Dark Coder suggests. But in the end, the extra hassle might not be worth it as Dark Coder says. Just try it and see what happens.

Also, careful use of clamping and camera positioning might allow you to use a 256x256 bloom image as a high res image for the small part of the scene that needs bloom. Ditto with shadows possibly.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Dec 2008 21:24
Quote: "You can easily test this for yourself by rendering a scene with various image resolutions, e.g. 1x1, 8x8, 64x64, 512x512, etc."


Sorry, couldn't resist doing this myself.

The attached demo (hopefully complete this time ) clearly shows what Dark Coder and I have been saying. There is a gradual increase in performance as the resolution of the images used in the rendering falls - but after a point the images are so small that the actual final high res screen render dominates and very little performance increase is achieved. The results are bound to be system dependent.

My ancient PC gives the following FPS for the demo:

im2048x2048 104
im512x512 121
im128x128 128/9
im32x32 130/1
im8x8 131/2

Attachments

Login to view attachments
BlobVanDam
16
Years of Service
User Offline
Joined: 26th Jul 2008
Location: one of Cybertrons moons
Posted: 17th Dec 2008 05:25 Edited at: 17th Dec 2008 05:30
Quote: "Bloom, like soft shadows and blur, can usually be rendered to a much lower resolution than the main screen resolution, so your final screen image could be some sort of combination of the main high res scene image and the various low-res bits used for special effects. This allows you to save some processing time as Dark Coder suggests. But in the end, the extra hassle might not be worth it as Dark Coder says. Just try it and see what happens."


Well my bloom has to cover the whole screen, so it's a combination of the scene at whatever res, plus my low res bloom map ghosted over that.


Green Gandalf, thanks for the quick demo. I copied my shader over yours to see some results, since you program is doing exactly what mine is doing basically, minus the rendering time of the camera itself obviously. The results were not what I expected at all.
My theory was that the pixel shader would have been taking roughly the same amount of time to render the object regardless of resolution because the effect would apply to every pixel of the object, rather than just the pixels of the image (ignoring any sort of delays that may be caused by passing a high res image to the shader perhaps?), but your program clearly indicated that this wasn't so.

When I used your 8x8 image, there was no difference in rendering speed from disabling the shader altogether and ran at about 350fps (using my shader in place of yours).
Even up to the 512x512, it only went down to 314fps. It took the 2048x2048 map to really slow it down to 140 or so. So that does indicate that my initial assumption is wrong, or at least isn't as major a slowdown issue as I thought. I'm quite pleased with the results.


Thanks for the help guys, and for taking the time to mess with the idea and discuss it with me.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Dec 2008 11:13
Quote: "because the effect would apply to every pixel of the object"


I think that might be where you were going wrong in your earlier understanding. Objects don't have pixels - images, textures, bitmaps, etc, have pixels. To put it another way, if you make a DBP plain, make object plain 1, 100, 100 say, how many "pixels" do you think it has? I think you'll see the question has no meaning without reference to some images somewhere, i.e. object textures, screen image, etc.

Quote: "Thanks for the help guys, and for taking the time to mess with the idea and discuss it with me."


You're welcome. We all learn more effectively this way. I was only about 80% sure of what I was saying till I tried that demo. Now I'm about 99% sure - which means that there may still be some subtlety that I haven't yet grasped.
BlobVanDam
16
Years of Service
User Offline
Joined: 26th Jul 2008
Location: one of Cybertrons moons
Posted: 17th Dec 2008 12:22
By pixels I meant pixels it's rendering to the screen. I know an object itself isn't formed of pixels, but I meant the final draw. Doesn't a pixel shader apply to actual pixels of an object on screen, hence the name? So of course I mean pixels of the final screen image here. But doesn't matter now, my question has been answered now anyway, and for the better

Been a learning experience for me too. I know computer graphics very well, but I haven't done real-time graphics in a long time, and I've never played around with graphical effects like multiple cameras and shaders before. I don't know where I'd be without this forum. God bless the search function, huh?
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Dec 2008 13:28
Quote: "By pixels I meant pixels it's rendering to the screen. I know an object itself isn't formed of pixels, but I meant the final draw."


I see. The thing to remember is that there is a texture read step as well as a write. In the demo the saving was on the read side of the process. If you want to write to a 1024x768 screen I don't see how you can avoid writing to 1024x768 pixels.

Quote: "I don't know where I'd be without this forum."


You are not alone.
jig
15
Years of Service
User Offline
Joined: 24th Dec 2008
Location:
Posted: 25th Dec 2008 06:05
hi all
i speak english not very well.
some one help me . please
now i have file effect. example ---> Free Shaders Pack2006
1/ i doing my game. if i want to change model(obj.x) and texture in folder effect. how to do? because i don t understand file .dds
how to do? please help me.
2/ what is program for edit file effect?
3/did you see file--> Grass 1.0 [Ninja Matt].dsproj. how to use?

some one explain me .
thank a lot


jigme kokomi
Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 27th Dec 2008 19:45
@ jig

Use the command set object effect to apply an effect to an object.

---------------

I finally bought Dark Shader, and have some great ideas for some full-screen shaders. Are there any bugs I need to look out for, I am using the newest version of DBPro...

-= Out here in the fields, I fight for my meals =-
jig
15
Years of Service
User Offline
Joined: 24th Dec 2008
Location:
Posted: 28th Dec 2008 06:32
thank Chris K

You have file effect cloth ?

I need to use .

thank

jigme kokomi
Swamp donkey
16
Years of Service
User Offline
Joined: 29th Dec 2007
Location: Gothasoft
Posted: 29th Dec 2008 06:52 Edited at: 29th Dec 2008 09:31
Hey guys,
I've been tossing with this for a few weeks now and feel as i've reached a dead-end. Not wanting to give up, I have decided to asks a few questions.

I'm trying to pass texture/vertex color and alpha(transparency) to my shader, do my processing - then .output the tex/color/alpha back onto the object.

My attempts have failed and I know it's possible but examples from googling and reading some tutorials didnt help me much as i'd get one to work and not the other.. I was wondering if you might know of a simple example that inputs an objects tex/color/alpha into a shader then just simply processes it back out? Thats really all thats holding me up at this point as I have my shader doing everything else that is required.

Thanks for any advice you may have.

EDIT****

I've manged to get color/texture/alpha into the shader and process it. But now a new problem. I have many trees on my terrain. When i apply my shader to the tree leaf portion and i apply Set Alpha mapping On Obj to ANY object it is effecting my trees as well. This is horrible, after all this time I thought i had it licked

- vista / 4gb / 8800gts
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Dec 2008 13:03
Quote: "I've manged to get color/texture/alpha into the shader and process it. But now a new problem. I have many trees on my terrain. When i apply my shader to the tree leaf portion and i apply Set Alpha mapping On Obj to ANY object it is effecting my trees as well. This is horrible, after all this time I thought i had it licked "


Without seeing any code it's hard to say what you've done wrong.

Have a look at the attached demo to see if it gives you any ideas.

The scene consists of three objects: a textured sphere at the back with two textured plains in front of it. The plain on the left has simple alpha mapping applied with a shader whereas the one on the right is merely textured with the same texture (and responds to the changing angle in relation to the default light).

Alpha mapping can be tricky to get right because a lot depends on the render order of the objects - as an example try commenting out the indicated line in the dba code to see what can go wrong.

Attachments

Login to view attachments
Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 29th Dec 2008 14:39
@ Green Gandalf

Hi, I wonder if you could help with any ideas for this full-screen shader I am trying to make.

Download and run, to see where I am at so far...
Hold space to animate, and move the mouse around.

Basically I have something that generates a 256x256 'normal map' of the scene. The line that is coming out of the mouse draws a 'path' through the normal map - you will see that it roughly follows natural 'lines' on the screen - particularly if you spin the guy around then move the mouse over his face.

Now, the second part of the shader, I want to 'paint' the scene. Basically, I have a triangle strip object, which I want to render again and again. This is Brush.x in the folder. The vertex shader should position Brush.x in a path, then the pixel shader should render it with a colour picked from the original image (ie, the natural colours of the scene).

You will see in my code that I have faked an intermediate render target, however I am not sure that this is necessary. At the moment I am doing the normal map edge detect thing on all 256x256 pixels, but it only needs to be done on the 'kinks' in the brush stokes - which will probably be more like 10,000. Do you think I can just texture Brush.x with the image from camera 1 and then let it do everything?

The main thing I need help on is setting up the painting bit - how can I make Brush.x render 2000 times all over the screen, and what optimizations can I used (it doesn't need to do any zsort or or zwriting anything - it just needs to 'stamp' onto the screen thousands of times)

Anyway, any input would be great!

-= Out here in the fields, I fight for my meals =-

Attachments

Login to view attachments
Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 29th Dec 2008 14:41 Edited at: 29th Dec 2008 14:42
Here is what I am aiming for...



-= Out here in the fields, I fight for my meals =-

Attachments

Login to view attachments
Swamp donkey
16
Years of Service
User Offline
Joined: 29th Dec 2007
Location: Gothasoft
Posted: 29th Dec 2008 16:54
Thanks GG for the example think i learned something from it that may be useful. Going to give it a play around.

Also I've tried a few variants to Chris K's alpha sorting routine and really got some great results. Being away from Dbrpo for so long I really am rusty in some areas... Is there a way to position/rotate attached limbs after they have been glued to a parent? Thanks again.

Ps enclosed my original shader mentioned above.

- vista / 4gb / 8800gts

Attachments

Login to view attachments
Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 29th Dec 2008 17:03
Yeah, you just use offset limb

All these commands are in the help files under 'BASIC3D -> LIMB COMMANDS'.

-= Out here in the fields, I fight for my meals =-
Swamp donkey
16
Years of Service
User Offline
Joined: 29th Dec 2007
Location: Gothasoft
Posted: 29th Dec 2008 17:32 Edited at: 29th Dec 2008 19:14
Yah I knew about that command but that's not really the command I'm hunting for as attaching an object to a limb dosent make that object a limb itself leaving Offset Limb useless to me.

EDIT***

GG, I've been working with your shader example, seems to be exactly what im trying to do. Im trying to get it to carry over the vertex color0's ( which contain the transparency value as well ).. So far i've failed but not given up

- vista / 4gb / 8800gts
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Dec 2008 19:28
Swamp donkey

I've played around with your shader a bit. It seems to work fine as it is with my demo if I set "Out.color" equal to 1 (i.e. "float4 (1.0, 1.0, 1.0, 1.0)" ). I haven't yet tried adding vertex diffuse to the object and doing it your way.

In my demo the transparency is in the alpha component of the DDS image and is just black or white, i.e. fully transparent or fully opaque.

Have you got some simple dba code with your shader to illustrate your problem?
Swamp donkey
16
Years of Service
User Offline
Joined: 29th Dec 2007
Location: Gothasoft
Posted: 29th Dec 2008 21:25 Edited at: 29th Dec 2008 21:28
I really hate being a pest but Im so stumped on this and have spent so much time on it i hate to quit now.

GG would you mind doing me a huge favor, would you add to your sample fx 'COLOR0' in and back out? I need to read in the color0 register then write it back out to the pixel shader.

I just can't seem to get the correct structure myself. You have no idea how much your help here is appreciated. I'd be happy to compensate you for your time.

- vista / 4gb / 8800gts
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Dec 2008 23:33
Yes. Will look at it as soon as I can. Watching a film at the moment.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 30th Dec 2008 14:29
Quote: "GG would you mind doing me a huge favor, would you add to your sample fx 'COLOR0' in and back out? I need to read in the color0 register then write it back out to the pixel shader."


Try this.

The dba code below is the same as before - except vertex diffuse has been added to object 1 - and the diffuse colour has been set to full magenta with full alpha (i.e. no green).



The shader then reads the diffuse colour and multiplies this by the texture colour. The result is that the green component has been removed from the image - you should see black leaves with a red stem on the object on the left. You should be able to see the required changes to the shader code.



Save the shader code as simple alpha V2.fx.
The Viking
16
Years of Service
User Offline
Joined: 21st Oct 2008
Location: Asgard
Posted: 30th Dec 2008 17:35
Hey all, Im extremely new to shaders but really want to learn it, though free time is short. Ive been playing with some different bumpmapping shaders and have a few issues.

1) Some of my objects have the light sources coming from different angles yet there is only one light source i believe.

2) Confusion as to how to add more light sources. I have a slight (very slight) understanding of how to make the light range changable in DBP, but not how to add more and have each affect the objects.

Hope that makes sense. Thanks.
Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 30th Dec 2008 17:52
You need to edit the variables in the shader.

-= Out here in the fields, I fight for my meals =-
Swamp donkey
16
Years of Service
User Offline
Joined: 29th Dec 2007
Location: Gothasoft
Posted: 30th Dec 2008 17:56 Edited at: 30th Dec 2008 18:45
Outstanding GG! Should be able to control the alpha fade while still having a mild AlphaRef value in there.

I'm going to attempt to change it so I can feed the alpha ( transparency) value into the shader in real-time. This will allow me to fade in and fadeout without having to loop through the objects vertex and set the alpha value for each transition (which I found to be way to slow.)

I thank you for your help with that sample, it's clearly set me in the right direction and given me a new found interest in shader devleopment.

- vista / 4gb / 8800gts
The Viking
16
Years of Service
User Offline
Joined: 21st Oct 2008
Location: Asgard
Posted: 30th Dec 2008 19:39 Edited at: 30th Dec 2008 19:41
yes, I understand that, and I am still trying to learn how to write it, as i mentioned. I just don't know what any of the commands do, as how i'm basically learning by trial and error. My only thing thats REALLY bugging me is why the light source appears from different angles on my character, which is composed of separate objects. As you can see in the image.

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: 30th Dec 2008 21:29
Quote: "As you can see in the image."


I think so.

Do you mean, for example, that the two arms are lit differently?

How is the lighting applied?

Are you using the same shader copy for each limb?

Are the object's normals calculated correctly?

Have you remembered to transform to world coords before calculating the lighting in the shader?

Etc, etc.

Some code and media would help. Then we'd know what we are talking about.
Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 30th Dec 2008 21:30
Try messing about with set effect constant vector (I think that's what it's called) to change the light position. You need to look in the shader for it's name, probably "LightPosition".

-= Out here in the fields, I fight for my meals =-
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 30th Dec 2008 21:38
Quote: "Try messing about with set effect constant vector (I think that's what it's called) to change the light position. You need to look in the shader for it's name, probably "LightPosition"."


That's not his problem. I think the problem is that a SINGLE light source shows up differently on different parts of the character.
The Viking
16
Years of Service
User Offline
Joined: 21st Oct 2008
Location: Asgard
Posted: 30th Dec 2008 21:44 Edited at: 30th Dec 2008 21:46
sorry, i have a better pic too. but the shader which i am trying to use to figure out some of this is one of yours GG. Basically, what i mean is that one arm or leg will have a completely different lighting, as if a second light source is present. I will give you the code, but as said it was your shader, Great one!, but still want to learn how it is working.

EDIT: oh, and i was going to play and see if i could figure out how to get multiple lights... as you will see...

The Shader:


and in DBP:



I still do not understand what lots of the commands in your shader mean, but i am learning.

Thanks a ton.

Attachments

Login to view attachments
Swamp donkey
16
Years of Service
User Offline
Joined: 29th Dec 2007
Location: Gothasoft
Posted: 30th Dec 2008 21:55 Edited at: 30th Dec 2008 21:58
Hey GG, sorry to keep bugging you but I promise it'll stop soon :0

I'm merging the diffuse / alpha shader with the foliage wobble effect you posted awhile back. I'm really stuck on this as my attempts result in nothing.

I'm certain it's something that not defined right but ive tried almost every imaginable combination. I've attached the FX to this message with what i have so far. Was hoping a quick glance at it you may notice something out of place. other than that - don't worry with it as ive taken enough of your time as it is. Thanks once more master wizard Gandalf.

- vista / 4gb / 8800gts

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: 31st Dec 2008 02:22
@The Viking

That's an old shader of mine that you are using - and it has an error to compensate for an error in some of my normal map images.

Try changing this line:



to this:



However, looking at the shader code there seem to be some errors in the lighting calculation - it looks like a muddle between positional and directional lighting. It was originally written for a directional light. Which are you trying to use?
The Viking
16
Years of Service
User Offline
Joined: 21st Oct 2008
Location: Asgard
Posted: 31st Dec 2008 02:44
Well, i'm kind of wanting a few different things. First off, I just would like to know if it is possible to have more than one effect on an object, I tried it before, but i think it crashed, don't remember, haha.

Back on topic, I wish to learn both in a sense. I will be attempting to make a light similar to street lamps and household lights, then I will attempt to make something similar to sunlight, which is more of an endless light and no limits to the distance. Though, both obviously casting shadows. I know its a lot, but, one thing at a time.

Unfortunately, changing that part had no affect on the shader on my end. To make the normal map, I use Gimp's normal map plugin. If you were wondering. Also, each part of the body is a separate object, like each pant leg is a separate object, but they both are identical, and use the same texture and normal map.
Swamp donkey
16
Years of Service
User Offline
Joined: 29th Dec 2007
Location: Gothasoft
Posted: 31st Dec 2008 08:27
Just wanted to report back and say thanks GG.. With your help and many tutorials on the web I finally got this shader working as i wanted.

Happy New Year!

Ps: enclosed shot of the trees in action.

- vista / 4gb / 8800gts

Attachments

Login to view attachments
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 31st Dec 2008 08:49
That is SWEET! You keeping that one under wraps (understandable) or will you release that one?

--Jason

Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 31st Dec 2008 12:35 Edited at: 31st Dec 2008 13:03
Ok, hit something of a road block here.

I've got it doing the easy bit - a 'base' coat where it just does splats of the right colour; this doesn't require the normal map calculated.

Looks like this...


The problem is now I need to draw the long brush strokes. Basically I need the vertex shader to position a triangle strip on a path through the normal map - to do this, at the very least the vertex shader needs to read from a texture.

Is there any way of getting info from a texture to the vertex shader?

-------

OK, got it. The command is tex2Dlod, and it is SM3.0+ only.

-= Out here in the fields, I fight for my meals =-

Attachments

Login to view attachments
Math89
20
Years of Service
User Offline
Joined: 23rd Jan 2004
Location: UK
Posted: 31st Dec 2008 13:43
I don't think you need tex2Dlod, tex2D should be fine. But whatever you use, textures in vertex shaders require SM3.

Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 31st Dec 2008 13:53
Hmm, well for some reason tex2Dlod works for me and tex2D doesn't work...

It isn't liking reading from the set camera to image image though, anyone managed to get a vertex shader to read data coming from a camera?

-= Out here in the fields, I fight for my meals =-
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 31st Dec 2008 14:00
Quote: "Ps: enclosed shot of the trees in action."


That's very nice.

Thanks for reporting back - it's extremely satisfying to see people make such good use of one's help. Makes it all worthwhile.

Quote: "Happy New Year!"


And to you too!

@Chris K

I haven't had much time to look at your query. However, you seem to be making good progress on your own.

Quote: "Is there any way of getting info from a texture to the vertex shader?"


To read the texture directly in the vertex shader you need SM3 as you and Math89 have noted. However, there's nothing stopping you from reading the texture in DBPro and passing the results to the shader - and then using this in the vertex shader if you wish.

For example, your original code includes a section which reads some screen data into an array. You can pass that array to an array in the shader as described in the Dark Shader Help file (you should be able to read that even if Dark Shader itself doesn't run on your system). You could use the array info to drive different passes of the shader - each pass would access a different element of the array. In SM2 there is a low limit to the size of array - about 15 I think, but that should be sufficient to render a stripe.

Regarding SM3, I haven't used it because my machines are too old so I can't give much specific help - but DBP does support SM3 shaders if your GFX card is up to it. Dark Coder gave a good example of one some months ago (but I haven't seen it myself yet ).

Cheers for now - and Happy New Year.
Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 31st Dec 2008 15:32
Do you know how to pass info to the shaders as a bone animation matrix array?

I can't find any info on it in the help files.

-= Out here in the fields, I fight for my meals =-
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 31st Dec 2008 16:54 Edited at: 31st Dec 2008 16:58
I should - but I don't.

I think Van B posted a demo which did that about a year ago. I'll try to find the link.

Edit Here's the link:

fastbone shader demo
cjb2006
18
Years of Service
User Offline
Joined: 20th May 2006
Location:
Posted: 31st Dec 2008 19:20 Edited at: 31st Dec 2008 20:44
All right I'll say it: I love shaders.

All right I'll say it: I HATE shaders.

With 25 pages to this thread I'm sure my latest problem has already been covered but I can't find it. I'm attempting to adapt one of Evolved's old Bumpmap shaders into a real world state. The scenario is Bump mapping tree trunks. The shader gives a nice result (see attached project) but doesn't allow the instanced objects to be rotated (un-comment line 56 as indicated). In my mind I would like to model one eccentric tree that can be rotated and scaled to "represent" many different trees. In looking at this shader, I know enough to understand why this is happening. He calculates his lighting using the models normals, bitangents and tangets not their final rotated values. I'm dumb enough not to know the easy solution to this (if there is one). My proposed attempted fix will be to encode the rotation in the model itself. Since I would only be rotating on the y axis I could place that angle data in, say, position.w and read it from there to manipulate the tangent matrix vectors in the shader.

This seems like such a common problem that I believe I must be missing something obvious. Any ideas?

Attachments

Login to view attachments
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 31st Dec 2008 19:26
Um - I've said it before - I'm not a shader guy but I watch this thread.... I'm thinking maybe you should try using a separate texture that just contains the normals in it - then the model position is irrelavant.

--Jason

Login to post a reply

Server time is: 2024-11-24 12:26:29
Your offset time is: 2024-11-24 12:26:29