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
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 15th Jul 2008 19:34
Dunno how I missed it, remove the line 'LightM=LightM+LightM+LightM+LightM;' in the same PS() function.

Bad Monkey
17
Years of Service
User Offline
Joined: 1st Jan 2007
Location:
Posted: 15th Jul 2008 20:57
Quote: "Dunno how I missed it, remove the line 'LightM=LightM+LightM+LightM+LightM;' in the same PS() function."


That works too. But the flashlight doesn't really appear like a normal flashlight. It only seems to add it's white color to the level, instead of adding 'light'. So what ends up happening is when I shine the flashlight into really dark corners, the darkness doesn't get to where I can see the corner, all that happens is the darkness gets whitewashed with the flashlight.

Is there any way to change the shader so that it actually brings out the dark corners? Or would I just have to create a level that is all one ambience?

Thanks.


Visit my website:
http://www.artistsareus.com
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 15th Jul 2008 21:12
@Sid Sinister - Nice links above - thank you - Archiving copies for future reference.

dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 15th Jul 2008 22:34
You are doing this with the original shader right? I.e. only removing that one line, and not my aforementioned change, if so it should work, post an image if not as there's only so much I can guess without trying.

Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 16th Jul 2008 17:31
thanks sid for the links
Bad Monkey
17
Years of Service
User Offline
Joined: 1st Jan 2007
Location:
Posted: 16th Jul 2008 19:01 Edited at: 16th Jul 2008 19:02
Quote: "You are doing this with the original shader right? I.e. only removing that one line, and not my aforementioned change, if so it should work, post an image if not as there's only so much I can guess without trying."


I am using the original shader with only that one line removed. Everything works, but it just doesn't look like a real flashlight.

Like when I shine it into dark areas of my level, those dark areas don't get brighter, they just get 'whiter'. I have attached an image of what I mean.

I was just wondering if there was any way to improve the shader to act more like a real flashlight; something that illuminates even the darkest parts of my level?

Thanks for all your help.




Visit my website:
http://www.artistsareus.com

Attachments

Login to view attachments
Bad Monkey
17
Years of Service
User Offline
Joined: 1st Jan 2007
Location:
Posted: 16th Jul 2008 19:20 Edited at: 16th Jul 2008 19:21
Here is an image where I am shining my spotlight into a dark corner. But there isn't any change.




Visit my website:
http://www.artistsareus.com

Attachments

Login to view attachments
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 16th Jul 2008 19:27
Well it's hard to say without having the media to test it, you could experiment with it, as you only really need to modify the 1 line: 'return float4(Texture*(LightM+FlashLight),1);'.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Jul 2008 20:36
Quote: "Here is an image where I am shining my spotlight into a dark corner. But there isn't any change."


Perhaps because the corner is too far away from the flashlight?

The pixel shader you posted a few posts back uses an attenuation calculation which presumably depends on the distance the pixel is from the light. Look at how that is calculated in the vertex shader and you'll probably find a shader constant you can adjust. Might be called "lightRange" or something like that.

Some of your problems might arise from the fact that that shader uses an old PS version, such as PS1.4 (if I recall correctly). Any reason why you can't use PS2? PS2 is more flexible.

Bad Monkey
17
Years of Service
User Offline
Joined: 1st Jan 2007
Location:
Posted: 18th Jul 2008 03:12
Quote: "dark coder: Well it's hard to say without having the media to test it, you could experiment with it, as you only really need to modify the 1 line: 'return float4(Texture*(LightM+FlashLight),1);'."


Yeah, I changed that line and it works a lot better now. Thanks.

Quote: "Green Gandalf: Perhaps because the corner is too far away from the flashlight?"


lol. I'm not that noobish. I realize now that the light mapping is the problem. It's not the effect that I want to acheive. I want to have total darkness with the level and the flashlight is the only source of light.

So I'm going to re-do my graphics so I can have more control over the shader fx and lighting. I'll experiment more with the other shading effects like relief mapping, and see what I can come up with.

Quote: "Some of your problems might arise from the fact that that shader uses an old PS version, such as PS1.4 (if I recall correctly). Any reason why you can't use PS2? PS2 is more flexible."


I'm still learning shaders. I've been reading this thread (up to page 10 so far), and other internet sources. I've started only recently too.

Is there any way to change the shader effect to use ps2?


Visit my website:
http://www.artistsareus.com
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Jul 2008 13:03 Edited at: 18th Jul 2008 13:04
Quote: "lol. I'm not that noobish. I realize now that the light mapping is the problem. It's not the effect that I want to acheive. I want to have total darkness with the level and the flashlight is the only source of light."


Sounds like you don't need the light map.

Quote: "Is there any way to change the shader effect to use ps2?"


Very simple. Just change this (and similar lines below them)



to



(although you can probably keep vs_1_1 - it's the pixel shader that is more important).

I don't think anything else needs to be changed but haven't checked carefully. The advantage of PS2 is that more functions are supported like the power function which is useful for specular reflection - and more instructions are allowed. Otherwise it's not a big deal. However, I have a feeling that some newer GFX cards no longer support the various PS1 versions - and it's been dropped from the more recent updates of DX9 which is one reason why DBPro still uses an earlier version.

Quote: "I'm still learning shaders. I've been reading this thread (up to page 10 so far), and other internet sources. I've started only recently too."


We all are to some extent - and we now have PS3, and soon PS4, to learn.

You've done well to read through as much as you have on this thread - it is getting a bit unmanageable now. Perhaps someone will have time to condense it to a series of tutorials ...
Bad Monkey
17
Years of Service
User Offline
Joined: 1st Jan 2007
Location:
Posted: 19th Jul 2008 01:50 Edited at: 19th Jul 2008 07:01
I am finding that the books posted above by Sid Sinister are very good. They do require a great bit of knowledge about the C language, but that's not a big problem.

They have many chapters devoted to shadows and lights. They also talk about fog effects and other things related to shaders.


Visit my website:
http://www.artistsareus.com
Bad Monkey
17
Years of Service
User Offline
Joined: 1st Jan 2007
Location:
Posted: 20th Jul 2008 02:56
I was looking at the other shaders by evolved, and was wondering about his relief shader.

Can it have more than six lights? Like 25 lights? If the lights are just being rendered by the shader then is there any hardware limitation on the number of lights that can be rendered? It seems that I could just make as many rendering passes as I want and have as many lights as I want in the scene.

Here is the code to his relief mapping:



As you can see, if I'm not mistaken, he has six lights and a flashlight that uses a cube map for a filter. Then he has different rendering techniques dependent on the number of flashlights the programmer wants in the scene. All I would have to do is make more techniques for more lights. Unless there is a hardware limit to lights even when using a shader.


Visit my website:
http://www.artistsareus.com
Bad Monkey
17
Years of Service
User Offline
Joined: 1st Jan 2007
Location:
Posted: 21st Jul 2008 08:27 Edited at: 21st Jul 2008 08:28
Ok, I'm getting the relief map shader to work great for the effect that I want.

Here's a shot:



Also, I've been wondering about shadows. If I use the set object shading on command, would it interfere in any way with the shader I am using?


Visit my website:
http://www.artistsareus.com

Attachments

Login to view attachments
Math89
20
Years of Service
User Offline
Joined: 23rd Jan 2004
Location: UK
Posted: 21st Jul 2008 11:17
The command for shadows, is Set Shadow Shading On. It will work but these shadows aren't great and they wont blend nicely with your lights.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 22nd Jul 2008 14:06
Bad Monkey

Quote: "Can it have more than six lights? Like 25 lights? If the lights are just being rendered by the shader then is there any hardware limitation on the number of lights that can be rendered? It seems that I could just make as many rendering passes as I want and have as many lights as I want in the scene."


Good question. I think the answer is "yes" (but I haven't tried). It would be a very long shader since it couldn't use loops - if you wanted 25 lights you'd need 25 copies of each individual vertex and pixel shader. Food for thought though. I suppose there has to be a limit somewhere. Why not try it and see?
Xlaydos
20
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 22nd Jul 2008 19:03 Edited at: 22nd Jul 2008 19:20
Hi, i have a few questions

Is there anyway to pass a pixel shader just to an image, which can then be pasted to screen. Or would i have to use a textured plain and lock that to the screen?

I am confused with how variables work. Is there someway to declare variables as global? I get strange results unless the variables are declared inside the function.
Edit: I found out about global and local variables but this shader gives me strange results. It should make it blue, but it comes out black? (Its an edited version of the shader on pg.3)



Also, is it possible to pass a vector using "Set Effect Constant Vector" to an array? Would i just use it like this:


Thanks
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 22nd Jul 2008 19:42
Xlaydos

The problem with your "blue" shader is that floats are restricted to the range -1 to 1 if you compile using PS1.1 so the result of the test is 0 - hence the black colour. If you compile using PS2 your shader works fine, i.e. use the following:

Xlaydos
20
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 22nd Jul 2008 23:36 Edited at: 23rd Jul 2008 00:19
Ah-ha i see I'm glad it wasn't something really obvious i missed

Thanks a lot

Hmm still having problems with arrays.

How do you create arrays, add array elements, and get array size in hlsl? Nothing i try seems to work...
Chris K
20
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 23rd Jul 2008 14:41
Uh, you normally don't need arrays... what are you trying to do?

-= Out here in the fields, I fight for my meals =-
Xlaydos
20
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 23rd Jul 2008 14:45
I was experimenting with a way to represent 2D Metaballs. (http://www.niksula.cs.hut.fi/~hkankaan/Homepages/metaballs.html)

As they are very slow to draw if you rely on the CPU and calculating distances, i thought i would try drawing them on the GPU to save cpu power for other sources as i will be using no other shaders in my game. Maybe this is a silly idea?

I wanted an array so i could add metaballs at will from runtime.

Thanks
Irradic
18
Years of Service
User Offline
Joined: 1st Jul 2006
Location:
Posted: 27th Jul 2008 01:55
Hi, I need some help with this shader. I wanted to implement a second Normal map channel for high frequency detail. Now I managed to make the first normal map tile able, but no matter what, the second normal map isn't being displayed. Probably it has something to do with the blending of the two maps, but I don't have much of a clue when it comes to shaders. I removed the lines that caused errors in the compiler, so now I just basically have a tile able normal map.
I would very much appreciate it if some body could help me out.
What I'm basically trying to do is, have 2 normal maps, i.e. 1 for larger details and 1 scale able/ tile able normal map with high frequency detail like clothing patterns\ pores etc...



Thanks !
mr Handy
16
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 6th Aug 2008 13:20
Hi!
Long time no see!

I was playing with shaders, and wanted to make
shader working like "making terrain from height map".
So, how it must work:

So the problem is that tex2d command seems to be out of place here.
But how can i pass float from height map to vertex shader?
I thought its simple...
I'm full of hope of help!

A door is a door is a door. Even a swinging one. =0
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th Aug 2008 13:33 Edited at: 6th Aug 2008 13:34
Quote: "So the problem is that tex2d command seems to be out of place here.
But how can i pass float from height map to vertex shader?
"


You cannot do a texture look-up in the vertex shader in PS2 or below, only in the pixel shader. I believe you might be able to do something like that in PS3 (or PS4?) - but I haven't investigated because I don't have PS3/4 capable hardware yet (and I'm not sure whether it's supported by DBPro).

Quote: "I thought its simple..."


Yes, it would nice if it was that simple. But it isn't ...

The only thing I can suggest is that you supply the height values to the vertices via the DBPro vertexdata commands. Could be slow though depending on what precisely you are trying to do.
mr Handy
16
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 6th Aug 2008 14:16
So.....bad
Maybe somehow pass float back from pixel part?
------
And i forgot to ask about world coords.
I wanted to rotate world coords (see attached pic)
and use new world.x.y.z as UV coords,
i'm sucsessfuly using original world coords for mapping now (left part of pic).
Yes, i know, i can texture it in external program, but i need to
project map using rotated world!!! coords, see right part of pic.
(as you see coords not depend on how box moving)

PS thans for help, GG!

A door is a door is a door. Even a swinging one. =0

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th Aug 2008 15:30
Quote: "I wanted to rotate world coords (see attached pic)
and use new world.x.y.z as UV coords,"


Why?

I don't really understand what it is you are trying to do - world coords have THREE components whereas objects usually have only TWO UV coords. Perhaps you could explain more carefully?

When you move or rotate an object you don't usually need to change the UV coords unless you are trying to achieve a special effect. If that's the case you need to give more details.
mr Handy
16
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 6th Aug 2008 16:07
Hm...well, yes, i think i must ask more clearly!

So, if you saw picture, there was cube that have checker map projected onto it(3-side projection:xy,xz,yz), depends on polygon's normal. i've used following code to check polygon's direction (may contain errors =) )
---
if (dot(abs(IN.Normal),(0,1,0))<0.75) //check if poly facing up or down
{ OUT.Texture=float2(World.x,World.z) }; //projecting map using xz world coords
---
...and two more times for 1,0,0 and 0,0,1 axis vectors accordingly.

So, i can rotate or move box as i wish, but texture will project like cube map. You can see attached picture. There is a ball, that have only one (XZ) world projection, and when its moving, UV scrolls! Like in terminator 2, when cop raises from 'checker' floor
So, checker map projected on ball using XZ, but now i need to turn XZ on 30' or 60'! (see first pic, right part)

PS. kick me if i didnt explained again

A door is a door is a door. Even a swinging one. =0

Attachments

Login to view attachments
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 6th Aug 2008 16:33
Not sure what you're doing but remember IN.Normal will be in homogeneous space, meaning the normal for a given vertex will remain the same no matter how you rotate the object, its limbs etc. The world matrix contains this info and to get its world normal you need to multiply it by this, once done you only need to compare the 'y' component value of the transformed vector(normal), if it's above .75 or whatever other slope you wish to check against then that's the same as you're almost doing now, but you save using dot product.

mr Handy
16
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 6th Aug 2008 16:57
geez...thanks man, optimizing is always very important!
---
Hmm...let me explain using 3ds max.
1 make cube
2 apply checker material
3 apply UVW mapping modifier
4 set planar projection from z
5 activate gizmo
6 rotate gizmo 45' by x axis.
7 place gizmo at 0,0,0
8 see first result
9 move object in XZ dimension
10 place gizmo at 0,0,0
11 see second result

So, i can make this effect using shader, but only "planar from z"
I need rotate gizmo, that represents world in shader.
...see?

A door is a door is a door. Even a swinging one. =0
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th Aug 2008 18:21 Edited at: 6th Aug 2008 19:58
Still not sure what you're trying to do. Are you saying that you want the checkerboard map on the sphere to scroll correctly when the plain is rotated [referring to your second uploaded image] ?

I think DC's suggestion allows the texture to scroll correctly when the target object rotates, but doesn't allow for the possible rotation of the cube map. I guess that would need another rotation matrix to be passed to the shader explicitly from DBPro.

Edit Still not sure what you are doing precisely. If the object moves without rotating then its normals will be unchanged in either object or world space coordinates - but the positions of the map on the two spheres are different in your second image.

Edit2 Is the attached what you are trying to do - except it doesn't have the extra rotation needed if the plain rotates?

Attachments

Login to view attachments
mr Handy
16
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 7th Aug 2008 10:44 Edited at: 7th Aug 2008 10:48
I've made some explanation video.

So, first video represents world 3-way projection, and when cube moves, projection tied to world coords and stays straight XYZ.
That's i have in my shader now.

The second video represents world 3-way projection that rotated, when all objects are not moving.
(But, if box will be moving anywhere, it will be mapped as in first video, but with world rotation)
That's what i want to achieve.

Thats wery weird effect...dont you think?
But if its done, we can make shadow projection!
So thats all for shadows!

10x for taking part in that experiment

A door is a door is a door. Even a swinging one. =0

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 7th Aug 2008 14:38
For some reason I can't play those .avi files. The Windows "Help" site says

Quote: "You've encountered error message C00D11B1 while using Windows Media Player. The following information might help you troubleshoot the issue."


Needless to say, the "following information" didn't help.
mr Handy
16
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 7th Aug 2008 17:12
GG!
please visit http://www.codecguide.com/download_mega.htm and install KLMCP - IMHO the best free codec pack, including Cyberlink DVD codec.


A door is a door is a door. Even a swinging one. =0
Zubby1970
AGK Backer
16
Years of Service
User Offline
Joined: 22nd May 2008
Playing: AGK Studio Always
Posted: 7th Aug 2008 18:47
is there a shader pack other than the shaders that come with dark shader?

There can only be one
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 7th Aug 2008 21:00 Edited at: 7th Aug 2008 21:00
@mrHandy

Thanks, I'll give that link a try.

Zubby1970

Look at the sticky threads at the top of the Work In Progress board - or do a search of the whole forum for ultimate shader.
mr Handy
16
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 8th Aug 2008 15:28
GG (and DC), I found a link to good shader site. Hope you'll be interested at it. (site non-eng but dont be scared)
Author's gallery:
http://www.steps3d.narod.ru/screenshots.html
PS try all links for sources
---
But hope you'll help me with my current shader experiment

A door is a door is a door. Even a swinging one. =0
mr Handy
16
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 11th Aug 2008 08:40
Guys! I know it's simple for you.
http://evolveduk.googlepages.com/ShadowMapping.zip
So it's shadow mapping shader. To make ortho shadows, i've changed FOV of second cam to 360.203 (see this trick in last newsletter).
But, that made me to move camera back by 75000, and shadow disappeared. I suppose i need somehow to adjust depth, make it between 74000 and 75000. Or maybe something more. But 360.203 degrees is real ortho and can render depth! Any ideas what i'm should change in source?
10x

A door is a door is a door. Even a swinging one. =0
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 11th Aug 2008 10:02 Edited at: 11th Aug 2008 10:05
I made this shader(attached) for my compo entry(well it's not exactly the same), it's truly orthographic, however it's a bit more than just shadow mapping as it uses 2 projections for near and far objects, it's a bit complex to setup but it's most useful for outdoor scenes, I didn't spend ages tweaking the values for this sized scene so you'll have to modify a few values for it to work on a different scaled one, namely lines(21-24, 139 and 144).

[edit] This requires U7.0b and a SM2.0 card to run.

And Dmitry K wrote the orthographic function, though I changed it to be more useful.

Quote: "But 360.203 degrees is real ortho and can render depth!"


That's not orthographic, just a very low FOV as I assume the 360 bit just wraps around, take this for example:



The size of the object changes based on the camera distance, this shouldn't happen if it were orthographic.

Attachments

Login to view attachments
BlobVanDam
15
Years of Service
User Offline
Joined: 26th Jul 2008
Location: one of Cybertrons moons
Posted: 20th Aug 2008 16:37 Edited at: 20th Aug 2008 17:55
Well this thread is too long, and I'm just getting started.
I've got the Ultimate Shader pack, and it's quite awesome, but now I want to learn how to write them, because I want some specialized stuff. Right now I'm tweaking the cartoon shader. I've already adjusted the line thickness and messed with removing the map to fake the toon shading. What I want to do instead is replace it normal shading (preferable phong though if it's not too difficult), and then posterize that to give the simplified shading instead.

I've got FX composer. Is that any real use to me? I know that files made with it require a lot of tweaking to work, but the comments in the cartoon shader indicate that was started in fx composer. Is it worth me trying to hack together bits of other shaders, or should I just learn to write them from scratch? I'm a decent programmer, but I'm worried the math understanding is a bit much for me.


edit: ok, I'm making progress on my cartoon shader. But I'm having problems with the posterizing. I figure the way I need to do it is with the Normal, but I don't know how to do that
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 20th Aug 2008 20:30
Quote: "ok, I'm making progress on my cartoon shader. But I'm having problems with the posterizing. I figure the way I need to do it is with the Normal, but I don't know how to do that "


Welcome to the thread!

Sounds like you've made a good start. Messing around with existing code is a good way of learning how things work - and most of us probably started that way.

Someone can probably help you - but what do you mean by "posterizing"?
BlobVanDam
15
Years of Service
User Offline
Joined: 26th Jul 2008
Location: one of Cybertrons moons
Posted: 21st Aug 2008 17:12 Edited at: 21st Aug 2008 17:27
Posterize is a standard graphical effect where you effectively cut down the color depth. So instead of being a smooth gradient from 0-255, it would only have maybe 4 stages of colour. But I've abandoned that idea now. I've decided to do it a different way.

At the moment I'm reprogramming the shader pack bloom shader. Making some decent progress I think.
I've simplified it from 2 extra cameras, 3 objects, 3 images, and 3 shader effects (with 5 passes) down to 1 extra camera, 1 object, 1 image, and 1 shader (1 pass). It's working well right now.
My problem is that it doesn't seem to allow my if statement. It works with one float4, but not the one I want, so it's not a syntax error, it's clearly something I don't understand about how pixel shaders work.

This is just the pixel shader section
float4 temp;
float4 color = 0;
float tempx;
float tempy;

for(int x=1; x<5; x++) {
for(int y=1; y<5; y++) {
tempx = x;
tempx = (tempx/150);
tempy = y;
tempy = (tempy/150);
temp=tex2D(screen,IN.Tex+float2(tempx,tempy));

if (temp.r < 0.5f)
{
color+=temp;
}
}
}
(this is being done with PS 2_0 and VS 2_0, in case it makes a difference)

Can someone more experienced tell me why this doesn't work, but if I make the if statement work on the color variable instead, it compiles no prob. I've been coding pixel shaders for one day, so I'm sure there's plenty wrong with this!
If you omit the if statement altogether (but keeping the code within it), it's a 16 point blur (it's not offset correctly yet). It adds up 16 offset colour values (then divides by 16 later) to do a one pass blur. That works fine. But what I'm trying to do now is check the pixel value first and below a certain threshold, make it black, so only the bright areas get a glow.
I've got a good tutorial pdf from another thread, and many other sites to learn from, but there's only so much I can do after one day!
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Aug 2008 20:05
Quote: "Can someone more experienced tell me why this doesn't work, but if I make the if statement work on the color variable instead, it compiles no prob. I've been coding pixel shaders for one day, so I'm sure there's plenty wrong with this!"


That code compiles and runs fine here. (Whether it does the right thing is another matter. )

So the problem must be in the rest of your code - that snippet is not the whole pixel shader for example.

Why not post the whole shader? Then we can see where the problem lies.

Quote: "I've got a good tutorial pdf from another thread, and many other sites to learn from, but there's only so much I can do after one day!"


Indeed.
BlobVanDam
15
Years of Service
User Offline
Joined: 26th Jul 2008
Location: one of Cybertrons moons
Posted: 21st Aug 2008 20:17
I could post the whole shader I just didn't because of the setup required in Dark BASIC to use it as it was intended, but I suppose it doesn't make much difference.



I hope I copied that right. I had changed it in the meantime.

Also, I just made my own version of the cartoon shader. It's based off the ultimate shader pack one, but I changed it so it didn't mess with the textures (or maybe it was just that I was using it wrong at the time), and changed the lighting model.
The current one lights it based on the fully lit texture multiplied by the toon texture.
My one uses the lighting of the scene (colour of the light, and the ambient), and lights it based on that, while keeping the toon shading. So now the toon will actually go between fully lit by the current light, and lit by just the ambient light. Works better for what I'm usingf it for, but it's just an alternative
I'll probably put that up soon too if anyone's interested.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Aug 2008 20:44 Edited at: 21st Aug 2008 20:45
Quote: " color = color/16;"


Exactly as I thought.

You've exceeded the maximum number of instructions by including that extra instruction so it won't compile.

You can avoid that by either:

(1) looping over a 3x3 grid rather than 4x4

or

(2) splitting the pixel shader into two passes so each pass is within the required instruction count. You would need to use alpha blending with simple addition of the two outputs to get your desired result.
BlobVanDam
15
Years of Service
User Offline
Joined: 26th Jul 2008
Location: one of Cybertrons moons
Posted: 21st Aug 2008 20:55
Thanks
Since I'm new to pixel shaders, and just tinkering in Notepad, I don't really know all of the limitations and differences between versions.
I'll give the 3x3 thing a try and see how that goes.
chunks chunks
17
Years of Service
User Offline
Joined: 2nd Jan 2007
Location: ackworth uk
Posted: 25th Aug 2008 11:13
hi ive been trying to edit the glitter shader from rendermonkey to work in db.

im a shader newbie ,ive got some of it to work like the light and the object color but im not getting any glittery sparkles.

Also when the objects rotated it`s got a culling issue i think.

attached is the project ,shader and screen of original in render monkey.

if someone could please point in the right direction.

many thanks Chunks

toshiba satellite 1.6 core duo + nvidia geforce go 7300
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: 25th Aug 2008 13:29
chunks chunks

There are a number of issues with that shader - I'll see if I can fix it for you.

The main problem is that RenderMonkey works with the transpose of various matrices so statements like



need to be replaced by



Another problem is that you've transformed all your vectors into screen projection space coords whereas lighting calculations usually need to be done in one of the unprojected coord systems, i.e. object, world or view. That will cause the problems when you rotate the object. I usually use world space coords because I find it less confusing - I just need to think where lights, objects, etc, are in the "world". That doesn't suit everyone though.

Not sure what the problem is with the glitter itself - but it might be a side effect of the same problem. I'll get back when I've done some testing.


You've made a good start though - I usually find RenderMonkey shaders confusing and awkward which is why I stick with DarkShader, FX Composer and, of course, DBPro. But RM does have several nice demos - but they all need a fair bit of work to get them runing correctly in DBPro.

chunks chunks
17
Years of Service
User Offline
Joined: 2nd Jan 2007
Location: ackworth uk
Posted: 25th Aug 2008 13:37
thanx man ,i find fx composer very difficult i`ll have to look into it ,read the docs.

is there any reference to the commands anywhere ?

i found out what mul does from this thread somewhere.

thank chunks

toshiba satellite 1.6 core duo + nvidia geforce go 7300
windows xp pro.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 25th Aug 2008 13:50
Here's a revised version of the shader which looks right when you rotate the object. It fixes the main issues with the world coords and lighting but not the glitter. I've marked the changes in the code.

See if you can get the glitter fixed. Post back if you're still having problems.

For reference you could start here:

HLSL Intrinsic Functions

Attachments

Login to view attachments
chunks chunks
17
Years of Service
User Offline
Joined: 2nd Jan 2007
Location: ackworth uk
Posted: 25th Aug 2008 14:08
thanks again i will ,think these shaders are great....


chunks

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

Login to post a reply

Server time is: 2024-07-05 19:46:31
Your offset time is: 2024-07-05 19:46:31