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
coolgames
18
Years of Service
User Offline
Joined: 26th Sep 2005
Location: Oregon, USA
Posted: 16th Apr 2008 02:38
Yes! Setting the transparency mode to "2" fixed the problem. It works perfectly! I've attached a screenshot. The meathod I'm using will work on any object. Of course it only works on flat ground right now, but I'll work out a way to have the shadow plane mold to any surface. I'm going to add blur to the shader now.

Here is the shader I used:

Attachments

Login to view attachments
coolgames
18
Years of Service
User Offline
Joined: 26th Sep 2005
Location: Oregon, USA
Posted: 16th Apr 2008 03:30
Just added blur!
This shader requires sm 2.0.

Here's a screenshot with a animated model. I'll need to do a little work to get the shadow aligned correctly on the ground, but it is very close!

New shader code:

Attachments

Login to view attachments
Pixel Perfect
17
Years of Service
User Offline
Joined: 21st Feb 2007
Location: UK
Posted: 16th Apr 2008 19:34
That's looking really good coolgames! This is acting on a single object just now, can the technique be extended to multiple objects?

No matter how good your code is, someone will improve on it
coolgames
18
Years of Service
User Offline
Joined: 26th Sep 2005
Location: Oregon, USA
Posted: 16th Apr 2008 20:08
It should. I'll write a little function library so that it is easy to add it to any object. I'm not sure how fast syncing a camera multiple times will be.
Pixel Perfect
17
Years of Service
User Offline
Joined: 21st Feb 2007
Location: UK
Posted: 16th Apr 2008 20:55
Quote: "I'm not sure how fast syncing a camera multiple times will be. "

No ... but it'll be fun finding out

I've not managed to get stencil shadowing working well with animated objects, especially if they have been scaled, so this might be the technique to use for applying shadows to them.

No matter how good your code is, someone will improve on it
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Apr 2008 21:15
coolgames

Glad it worked. Nice idea too. Look forward to seeing how this works out.

mr Handy
16
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 17th Apr 2008 16:40
Hi again!

I've just seen screen gallery , robot ilsand last pics,
and have question:

everybody must rmember evolveds first deferred shading, or at least parallax (defferred is more important).
So, on RobIsl screen i saw parallax, where wasnt any
specular on back, shadow shaded side. But
in eveolveds defferred sh demo specular was on unlitted
faces.

@Dark Coder or Green Gandalf
Can you see what wrong with specular part of Defferred Shading?

PS I cant upload DefShad for you - bugs with inet.

A door is a door is a door. Even a swinging one. =0
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 23rd Apr 2008 11:55
This thread gave birth to the idea of a SKETCHY shader:

http://forum.thegamecreators.com/?m=forum_view&t=128110&b=6&p=0

Is there already one that works with DB?

The effect could be that objects with a "crayon like" texture are applied with the "sketchy" shader to give a unique cartoony look!
coolgames
18
Years of Service
User Offline
Joined: 26th Sep 2005
Location: Oregon, USA
Posted: 26th Apr 2008 03:37
Ok. I've got a basic demo working. I have a simple room with some objects in it. There is a teapot floating in the center of the room. You can move the light around using the arrowkeys and enter/shift to move the light up/down.

Here's a screenshot:


I've attached the exe and media for you to try out. I'm not quite finished with the function library yet, but I will soon!

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: 26th Apr 2008 11:52
coolgames

The demo crashes here. It requires dx..._35.dll to run. It should only require dx..._31.dll.

Have you updated with the latest version of U6.7? That should fix all those unwanted dx references - unless you're using an add-in that needs it.

Screenshot looks nice though.
Chenak
21
Years of Service
User Offline
Joined: 13th Sep 2002
Location: United Kingdom
Posted: 26th Apr 2008 16:34 Edited at: 26th Apr 2008 16:40
runs here, but only at 40fps... I can run evolved's deferred shadows at 60+fps, dunno if you have it capped or something...

Looks good though, there is a bit of z-fighting but I've gotten used to that in dbpro
bergice
17
Years of Service
User Offline
Joined: 5th Jun 2007
Location: Oslo,Norway
Posted: 26th Apr 2008 17:05
Wow, i so want to learn how to write shaders XD
coolgames
18
Years of Service
User Offline
Joined: 26th Sep 2005
Location: Oregon, USA
Posted: 26th Apr 2008 17:10
It's using cloggy's d3d plugin to make the teapot object. That's probably the problem.

I think the reason it's running so slow is because I'm doing 20x20, or 400 raycasts each update. I think I need to lower the resolution of the shadow object.
Pixel Perfect
17
Years of Service
User Offline
Joined: 21st Feb 2007
Location: UK
Posted: 27th Apr 2008 01:55
Nice demo!

No matter how good your code is, someone will improve on it
Garzu
19
Years of Service
User Offline
Joined: 31st Oct 2004
Location: London
Posted: 29th Apr 2008 17:28
I need to dive into this 814 post thread.. it's time to learn shaders.

what I really need is a website or book with with very basic step by step guide.

I was in foyles, and all they had with shader or hlsl in the title was a book for directx10 edited by Wolfgang Engel.(I really need 9)

CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 30th Apr 2008 13:21
Is there anyone willing to convert the attached project into a dbpro compatible shader?

It is a simple yet effective ocean shader from ati.

There is always one more imbecile than you counted on.

Attachments

Login to view attachments
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 19th May 2008 11:41 Edited at: 19th May 2008 11:43
anyone ever thought of doing a shader that creates a kind of pencil-drawing style look in grayscale?
Lucka
19
Years of Service
User Offline
Joined: 1st Oct 2004
Location:
Posted: 9th Jun 2008 20:12 Edited at: 9th Jun 2008 20:13
Hello guys, I spent a lot of (good) time reading this trhead. I'm still looking for some tutorials, but what is clear is:
here I can find out someone can give me an aswer.

I'm playng with a really good darkcoder's FX for texture blend over a terrain.
But the question is for any .fx

Here is the .fx:



The fx "shade" the textures over the terrain, the light or the shadows depends from the normal of every face (i'm sure there must be an eng word that can explain that in a sec.. but.. )

What happens if I'd like to take control of the lightposition?

Lot of .fx have in the tweakables float4 LightPos, is possible to do something like that in a .fx that doesn't?

I mean.. the final look is like the light is coming (for example) from SW, 30° tall. How can I cange it?

Lucka - gawteam coder - www.gawgames.com
Toz
16
Years of Service
User Offline
Joined: 14th Oct 2007
Location: The Netherlands
Posted: 12th Jun 2008 16:36
That shader doesn't calculate the shadows itself, it only recieves them externally from the terrain model. The shadows are made together with the terrain with the advanced terrain commands. If you open Main.dbpro from Darkcoder's example and scroll down a bit you will see this:



You set the light direction by changing the second, thirth and fourth parameters of the Set Terrain Light command.

If you want to change the light direction in real time tough, you have to change the shader a bit.

For example: Diffuse = saturate(dot(IN.Normal, -LightDirection));

I hope this helps you.

Don't read this, read the above.
Math89
20
Years of Service
User Offline
Joined: 23rd Jan 2004
Location: UK
Posted: 16th Jun 2008 20:00 Edited at: 16th Jun 2008 20:14
Nvidia has released the first volume of the GPU gems book for free on their website, and a few chapters of the second one (3 chapters per week). I found this really interesting.


GPU Gems 1
GPU Gems 2

mr Handy
16
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 20th Jun 2008 16:52
Hello everyone!
I'm still struggling with shadows, and found a way (probably) to make ortho shadows.
So - at first i've downloaded Evolved's shader
http://evolveduk.googlepages.com/ShadowMapping.zip
and (using cloggy's DLL) set camera 2 (that renders shadow) to ortho mode. Shadow disappeared.
I really dont know what to do...

PS 19th was EVOLVED's birthday, CONGRATULATIONS, DUDE!!!

PPS recently i've wrote 3 letters to Evolved but still got no answer, so posted here.

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: 20th Jun 2008 21:15
Quote: "I'm still struggling with shadows, and found a way (probably) to make ortho shadows."


Give us a clue?

Quote: "and (using cloggy's DLL) set camera 2 (that renders shadow) to ortho mode. Shadow disappeared.
I really dont know what to do..."


If you mean what I think you mean then how would EVOLVED's shader work?

I assume you want shadows calculated as if the light were an infinite (or very large) distance away like the sun. I believe EVOLVED's shadow mapping shader assumes the light source is at a fixed point in or near the scene so you can sensibly calculate the distance of each rendered pixel from the light source and compare the distances of various points in the scene from the light. If the light source is a VERY large distance from the scene then these distances will all be the same (approximately) so the shader can't decide which points ought to be in shadow, i.e. the shadow map will probably look like a uniform colour.

If Cloggy's DLL gets around that when preparing the shadow map (I know nothing about his DLL) then you'd need to modify the shader to use that particular kind of shadow map.

A good start would be to upload examples of the two versions of the shadow maps: Cloggy's "ortho" one and EVOLVED's. You can do this by putting a "save image" command in an appropriate place in your code (but you won't need to do this every sync!). We might be able to see what you're dealing with then.
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 21st Jun 2008 13:18
i recently bought 2 shader books one of the are shaders for game programmers and artists that is really great by sebastian st laurent.
and i got very intrested in polynominal texture mapping.
it sounds like an better replacement for normal mapping.
as you with little code both bump and self shadow your object.
is there any samples of this for dbp before i trye to do one for dbp?
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Jun 2008 13:56
Quote: "i recently bought 2 shader books one of the are shaders for game programmers and artists that is really great by sebastian st laurent."


Yes, I learnt a lot from that book and still refer to it occasionally. Some of it makes more sense when you go back to it after getting some practice writing shaders.

Quote: "and i got very intrested in polynominal texture mapping.
it sounds like an better replacement for normal mapping.
as you with little code both bump and self shadow your object.
"


I saw that too but haven't tried it yet. I haven't seen any working examples for DBPro. Let us know how you get on.
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 21st Jun 2008 21:54 Edited at: 21st Jun 2008 21:55
have looked a bit in to it and if i do the shader and want to use it will i be forced to buy crazy bumps or write an new normals generator.
as it uses 2 types of normal maps ?
but looks awesome.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Jun 2008 22:22 Edited at: 21st Jun 2008 22:25
Quote: "have looked a bit in to it and if i do the shader and want to use it will i be forced to buy crazy bumps or write an new normals generator.
as it uses 2 types of normal maps ?
but looks awesome."


Have just refreshed my memory by looking at the book again. The short answer seems to be "YES".

This is what my copy of the book says:

Quote: "At the time of this writing there are no tools that can be used to generate polynomial textures. However, as use of this technique grows more widespread, such tools are bound to start showing up."


This is similar to the situation with normal maps (although there are now many tools available for this - but I haven't used them) and horizon maps which can be used for self-shadowing terrains etc (I haven't come across any generally available software for creating horizon maps). I've written my own DBPro programs to create normal maps from a given image and also to create the volume textures required by horizon maps. However, I keep fiddling with them and they are never in a final presentable form. I've posted a demo of one version of the self-shadowing shader somewhere on the forum.

If you know what you are doing you can do the same for polynomial textures (these are really two textures because each pixel requires 6 components of information). [I now recall why I haven't tried it myself. Yet another project for my retirement, perhaps?]

The two textures used by polynomial textures are not normal maps - but the idea is the same - i.e. a texture is a convenient way of storing numeric information required per pixel in the shader. The sky's the limit as far as what you choose to use that information for.

If you're up to the challenge, post your progress here and if you get stuck I might be able to help.
Try
19
Years of Service
User Offline
Joined: 16th Aug 2004
Location:
Posted: 21st Jun 2008 22:53 Edited at: 22nd Jun 2008 00:01
Hello there,
While I was wandering around the web, I just found this link:
http://www.hpl.hp.com/research/ptm/

There is a PTM (Polynomial Texture Mapping) builder on the site, but it is in its very early stage of development, RC3 actually
Just trying to help, hope it helps.

And take a look at this article, if you please
http://www.hpl.hp.com/personal/Tom_Malzbender/papers/PTM.pdf

Cheers,
-Try
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 22nd Jun 2008 00:08
must say that this looks more and more intresting as it states that you get good results on low end machines to.
wich means i must be better fps wise aginst normal maps.
i know gg i made my own normal map generator that i gave away for free in the wip a couple of days ago.
thanks try for the input.
o and one small thing evolved we love your generosity with your shader samples they have helped me alot.
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 22nd Jun 2008 02:01 Edited at: 22nd Jun 2008 13:14
edited new.........
ok i have managed to get an polynominal shader running in dark basic but its a bit weird still as i still suck at shaders.
but neads work on light positions and alot of other stuff.
i changed the object to an cube.
as i want to in the end get it to be like evolveds great normal mapping shader where you can have multiple lights.
its hard to compare the fps still as i havent got it to work right yet.
you can now move camera with the arrow keys.

Attachments

Login to view attachments
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 22nd Jun 2008 02:15 Edited at: 22nd Jun 2008 13:14
deleted------
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 22nd Jun 2008 15:54
ok here is wath i have done so far and it is far from wath i want.
so if evolved or green gandalf could help me out as this is my second shader ever and the first was not that much code.
its an polynominal shader that the goal is to get it to be like evolveds normal mapping shader with multiple lights and to be able to set range and all.
wath i have done so far is
working shader in dbp wich reacts to one single light that rotates around the cube.
al files neaded are included dbp and fx files and media.
dont judge me as this is one nights work and i aint that good with shaders yet.
please post the changes on the thread so that we newbies can see wath you do.

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 23rd Jun 2008 01:05
@Try

Thanks for the links. Looks like something might come of this for DBP.

@Cliff Mellangard 3DEGS

Quote: "i know gg i made my own normal map generator that i gave away for free in the wip a couple of days ago."


I missed that - you're ahead of me there.

Quote: "ok here is wath i have done so far and it is far from wath i want.
so if evolved or green gandalf could help me out as this is my second shader ever and the first was not that much code.
its an polynominal shader that the goal is to get it to be like evolveds normal mapping shader with multiple lights and to be able to set range and all.
wath i have done so far is
working shader in dbp wich reacts to one single light that rotates around the cube.
al files neaded are included dbp and fx files and media.
dont judge me as this is one nights work and i aint that good with shaders yet."


Why shouldn't we judge you? That is an impressive demo.

How can I help you? You seem to have the problem solved - or have I missed something?

Will look at your code and textures more carefully later. Did you create the "polynomial" textures yourself? (They seem familiar. )
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 23rd Jun 2008 18:41 Edited at: 23rd Jun 2008 18:45
no i wanted the shader to work in dbp and having it right before i started to try making an map generator for it.
i belive i can use the normals generator a large bit for this.
the textures are the ones from the book and i belive they are freeware ones as render monkey also have them.
about the shader so do i nead some help with setting an fixed light range and the possibility to have differrent light colors.
i will work on it to but would help if you are intrested in helping out as you are more experienced then me on shaders.
polynomial mapping shader was maybe wrong type of shader to do as my second attempt ever.
but i found shaders to be fun as they are small and compact ideal for my tiny bit of time nowdays.
as all my larger projects have halted lately.
the normals generator was my first almost finished project in about 2 years.
grunt for an dbp compo.
clifftris an tetris clone.
and an 3d snake game for another dbp competition.
are my erlier finished projects that i remember.
i have worked for about 2 years with an rts project i probably never will finish.
as its outdated mostly tech wise.
cheers

ps iam currently reworking the shader as i read that this type of shader was forced to get u and v data from tangent space thru the x and y components of the vector.
so have to add that in.
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 24th Jun 2008 23:33
yust downloaded evolveds shaders from his site and woowww.
he have optimized all of them as they run alot better and looks alot better now.
makes me start to wonder is there any reason to try to learn shaders with an guru like evolved around.
ok have looked alot on polymonal mapping and it struggles me to say that iam beaten as i cant figure out to get an proper light range on it.
as wath i can see all is done in tangent space and iam to crappy to get the gripps right now so have to get back to this shader later when i have learned alot more about shaders.
mr Handy
16
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 25th Jun 2008 17:36
@Green Gandalf

EVOLVED said, that setting camera to ortho mode disables depth part of shader. Set cam to ortho and "poof!" - no shadows!

So, does somebody know smth like shadow mapping shader that dont use depth or compatible with ortho cam?
Or infinite shadow mapping...
Or stencil with transparensy at least!

A door is a door is a door. Even a swinging one. =0
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 30th Jun 2008 20:18
i have some wonders about shaders written in c++ and assembler.
they are both saved as fx files ?
do the gfx software detect itself wich language the shader is in.
i know stupid questions but i yust ordered 2 books about assembler programming for newbies to understand the shaders written in assembler.
and wonder is the speed gain worth the hazzle of writting them in assembler?
cheers and thanks.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 1st Jul 2008 00:52
What book(s) did you get? I Mean, Assembly language is a term that is used to describe programming "machine code" in a manner slightly easier (and useful) for humans. Assemblers are like C++ compilers except the "language" is a somewhat friendly version of straight machine code - to make it easier to write machine code. For example - the concept of a variable or macro an assembler might have - but in pure straight machine code, these things aren't really tangible. Registers, stack pointers, etc.. maybe... but - I think you get this point by now....

but my concern is that each assembler is usually tailored around a specific CPU architecture - and in the case of a shader - would be the CPU on the graphics card - typically called the GPU. It has a machine language different than intel's x86 based architecture, the same as motorola nad old commodore machines had their own as well.

So my point is - I hope you bought a book on assembly language "newbies" for GPU shader programming.

Otherwise - you'll become a intel master - know what real performance is - and will never think highly of .net, c++, C let alone basic - once you see just how fast assembly/machinecode apps run.... It'll ruin you! You'll curse intel for not publishing ALL the machine code commands (as they reserve some docs for the big boys like microsoft) but you'll love AMD as they aren't as "CIA" about it like Intel! You'll learn EXACTLY how functions work - and when to use them - and when a goto is just better - and if you hate goto and gosub - STOP NOW! LOL

Have fun either WAY!

mov eax,1
cmp eax,bax
beq TheHardcoreProgrammingStartsHere
jsr RENDERMONKEY
ret

:TheHardcoreProgrammingStartsHere
xor eax,eax

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Jul 2008 19:58
Quote: "and wonder is the speed gain worth the hazzle of writting them in assembler?"


There is no speed gain - unless you can write shader ASM code more efficiently than the FXC shader compiler can.

I've often tried to re-write a shader to cut out an instruction or two only to find that the compiler converts them to the same code - because it recognises various shortcuts that I was unaware of or didn't think of.

My advice is forget ASM for shaders - it belongs to history. Stick to HLSL.
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 1st Jul 2008 20:24 Edited at: 1st Jul 2008 20:26
thanks guys as i couldt stop the order anymore from the book store so do i always have something to put under the chair if one of the legs break
i apretiate your advice both of you as i have used dbp for aprox 3-4 years but are still lost in alot of the programming world.
the books i rderred are .
"Windows Assembly Language and Systems Programming", Kauler, Barry

"Introduction To 68000 Assembly Language", Penfold, J.W./Penfold, R. A.

maybe it will help me understand some more.

i only payed 40 euros for both books with shipping
cheers

ps iam currently using rendermonkey are fx composer that much better?
mr Handy
16
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 2nd Jul 2008 12:09
hey hey somebody!
where to get deferred shading 1st (in original)???
.
.
.
is it available to crossover DOF and post-bloom?
what's better to make: single shader or just dba code for both?

|plz dont read below|
grr... i cant understand what to render first second etc...
the worse part of coding is to make all shaders work together...
i wanna get ultimate shader all-in-one bwa ha ha ha!!!
|so you've read this |

A door is a door is a door. Even a swinging one. =0
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 2nd Jul 2008 12:34
Quote: "My advice is forget ASM for shaders - it belongs to history."

I don't know, if you're experienced with writing optimized assembly code and know the microarchitecture of the target GPU, then it's no doubt possible to write code better than the FXC shader compiler can. But then one has to ask themselves if it's really worth it.

dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 3rd Jul 2008 19:19
I noticed my clipping plane either doesn't do anything or is rather broken when dealing with objects that have shaders applied(an advanced terrain in this case), I could write clipping plane code in my shader as it's easy for a water shader but is there any fix for this or is it a bug with DBP(U6.9)?

Bad Monkey
17
Years of Service
User Offline
Joined: 1st Jan 2007
Location:
Posted: 15th Jul 2008 08:17
So, I've looked around and found some of evolved shaders. I've been playing with his "Flashlight" shader, and it is pretty cool.

But, I've run into some problems. It seems that the shader is intricately linked to the textures. For instance, in the code it shows three textures:



There are three indices for three different textures to be mapped to the object. The light map texture, the diffuse texture, and the flashlight texture.

Now I can get this shader to work on simple objects that have only these three textures, in that exact order. But I can't get the shader to work on anything complex, Like an fpsc level. Now I assume that an fpsc level (compiled by version 1.09), has many more layers of textures than just three, so I assume that is what's causing the problems.

So I was wondering if there was any way to rewrite the shader code to allow for complex scenes with an unknown amount of textures?

Here is the complete fx code:



I don't think I need to attach any media, because that isn't what I think the problem is, but if you need me to then tell me.

Thanks for any help.


Visit my website:
http://www.artistsareus.com
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 15th Jul 2008 08:36
You're confusing textures with texture stages, FPSC levels I doubt will use any more than 2 texture stages(but many limbs/textures), one for the diffuse map and a lightmap, the issue is possibly the order these are in. Try reversing the declaration order of the 'LightmapTX' and 'BaseTX'.

Sid Sinister
18
Years of Service
User Offline
Joined: 10th Jul 2005
Location:
Posted: 15th Jul 2008 08:54 Edited at: 15th Jul 2008 08:55
Thought you guys would enjoy these links from Trogdor who just posted this in Geek Culture:

Quote: "GDNet is hosting a complete PDF versions of ShaderX2 books "Shader Programming Tips and Tricks with DirectX 9.0" and "Introductions and Tutorials with DirectX 9.0" from Wordware Publishing.

Shader Programming Tips and Tricks with DirectX 9.0
http://www.gamedev.net/reference/programming/features/shaderx2/Tips_and_Tricks_with_DirectX_9.pdf

Introductions and Tutorials with DirectX 9.0
http://www.gamedev.net/reference/programming/features/shaderx2/Introductions_and_Tutorials_with_DirectX_9.pdf"


"If I have seen a little further it is by standing on the shoulders of Giants" - Isaac Newton
-Computer Animation Major @Baker.edu-
Bad Monkey
17
Years of Service
User Offline
Joined: 1st Jan 2007
Location:
Posted: 15th Jul 2008 09:33 Edited at: 15th Jul 2008 09:35
Quote: "You're confusing textures with texture stages, FPSC levels I doubt will use any more than 2 texture stages(but many limbs/textures), one for the diffuse map and a lightmap, the issue is possibly the order these are in. Try reversing the declaration order of the 'LightmapTX' and 'BaseTX'."


Thank you. That worked great. But now the light maps are completely overblown. It seems that there might be some over saturation (or something like that) happening in the shader fx.

I see this code:



There is the command:

OUT.Diffuse=saturate(0.015f+mul(Wnor,LightPos)*0.015f);

Is this command making the level overblown with white? Or is it some other command?

Here is a pic to show what I mean:




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: 15th Jul 2008 09:55 Edited at: 15th Jul 2008 09:56
Try changing the last line in the PS() function to: return float4(Texture*min(LightM+FlashLight,1.0f),1);

Bad Monkey
17
Years of Service
User Offline
Joined: 1st Jan 2007
Location:
Posted: 15th Jul 2008 10:07 Edited at: 15th Jul 2008 10:08
I changed the code so now it reads:



But now the textures are gone. It looks like this:



It's an odd 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: 15th Jul 2008 10:48
Try changing that 1.0f to float3(1.0f) then :p, and is the source of that white-out where a light is? And not the flashlight/torch, in which case you might not able to remove that, due to the effect using multiple passes and they just add on top of each other, you might have to settle for reducing the brightness of the light. If this is the case then my earlier suggestion will have no effect on this.

Bad Monkey
17
Years of Service
User Offline
Joined: 1st Jan 2007
Location:
Posted: 15th Jul 2008 18:15 Edited at: 15th Jul 2008 18:27
Quote: "Try changing that 1.0f to float3(1.0f) then :p, and is the source of that white-out where a light is? And not the flashlight/torch, in which case you might not able to remove that, due to the effect using multiple passes and they just add on top of each other, you might have to settle for reducing the brightness of the light. If this is the case then my earlier suggestion will have no effect on this."


Sorry for not making that clear last time. Yes, the lights that are overblown are the pre-rendered lights from fpsc. It is the light map that is getting overblown, not the flashlight fx. The flashlight fx is still working normally, except for the extremely overblown pre-rendered scene.

If I turn off the object flashlight shader, then this is how dark the scene is supposed to look:



I'm going to see if I have to re-render the scene so that there are no lights for the light mapping. I will see if that works or not.

[EDIT: ] So I just took all the light maps and I darkened them by 75 percent. That worked to bring the scene back down to normal.


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

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-07-05 19:28:53
Your offset time is: 2024-07-05 19:28:53