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
mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 6th Feb 2009 22:54
Ummmm....no. I didnt meant that. OMG how bad I'm at explanations,
but this time i'll do it

Sooooo, imagine plain floor,
and a small red sphere in the middle.
Then two small green spheres at diagonal corners of plain.
Sphere positions like 3 dots on dice now.
Using one cubemap i want to make static! reflection for
two green spheres.
Of course, their cubemaps will be different.
I can make map using two cubemaps, but i want one
because it static and limit of cubemaps is 10 AFAIK...

well...
thats why i've said about copying maps,
like if use camera to image,
i can paste image, get it and make some pervertions with it,
but it seems that i cant paste cubemap.
puff!

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: 7th Feb 2009 00:31
I'm still baffled because you've contradicted yourself again.

You say this in one place:

Quote: "Using one cubemap i want to make static! reflection for
two green spheres."


That says ONE cubemap to me.

But your very next sentence says:

Quote: "Of course, their cubemaps will be different."


How can "they" be different if there is only ONE???????

You also say:

Quote: "I can make map using two cubemaps"


What does that mean?


Do you mean you have ONE scene and want to find the DIFFERENT reflective cubemaps for each object? For example, your first green sphere will have one cubemap rendered from the scene, and the second will have another. YOU WILL NOT HAVE ONE CUBEMAP, YOU WILL HAVE SEVERAL.

You also talk about copying and pasting images. What exactly are you trying to do?
mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 7th Feb 2009 00:47
I know that i must have two!
the point of all this word-mess is somehow COPY cubemap to
image.
Once cubemap is copied, i can render original one
more time, but it will not affects to the copy, right? so copy it again to 2nd image , then render
original again, then copy it to 3rd image............

ps sorry for confusing errors earlier

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: 7th Feb 2009 01:15
Why don't you use different ID numbers - one for each object and its cubemap (or group of objects)?

Why are you wanting to "copy" these different cubemaps?

If you have 100 objects you will want 100 cubemaps - unless you reduce the number by using the same cubemap for objects which are close together.

Of course there will be a limit to how many you can have - there will be a limit imposed by video memory and there may also be a DBPro limit which I'm not aware of (you mentioned a limit of 10 for something).

Quote: "Once cubemap is copied, i can render original one
more time"


Why do you want to do that if nothing has changed in the scene?

I won't be able to do any more on this tonight. Hopefully all will become clear tomorrow.
mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 7th Feb 2009 01:23
The night is loong))
But even if there is no limit of quantity of cubemaps,
i cant create 100 cameras for them...
btw, if dynamic cubemap rendered only once, will it
affect on perfomanse when 'idle', or it will be same if i
load cubemap.dds and apply it?
Wow we found some clues to understand each other)

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: 7th Feb 2009 10:29
Quote: "The night is loong"


Yes it is. While I was having my morning cup of tea today I realised what you were probably trying to do. My brain was benefiting from a healthy dose of mulled wine when I posted last night.

Do you mean you want to use a single cubemap image ID but keep replacing that image with an updated one viewed from each object in turn - but make sure that each object is rendered using its own version of that same image?

If so, I'm sure it can be done but is likely to be VERY slow. I'll try to produce a demo along those lines later today. If that IS what you want and it works then we can think about optimizing it.

It's an interesting "challenge".
mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 7th Feb 2009 12:59
me have this power-up too!

Quote: "
Do you mean you want to use a single cubemap image ID but keep replacing that image with an updated one viewed from each object in turn - but make sure that each object is rendered using its own version of that same image?"


Well yes. I must make some test to find out limit of cubemaps.
If limit of ~10 is true then making 100 cubemaps
will be impossible, and in that case we must find any way
to make it.

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: 7th Feb 2009 15:11 Edited at: 7th Feb 2009 15:12
Quote: "If so, I'm sure it can be done but is likely to be VERY slow."


Hmm? Written my first demo of this idea and got an instant BSOD.

Image:



MS error reporting says it was caused by my AV software.

We'll see.

Attachments

Login to view attachments
mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 7th Feb 2009 17:08
The way you choose lies through many dangers,
and you may fall on the way.

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: 7th Feb 2009 18:29 Edited at: 7th Feb 2009 20:16
Well. I've got rid of the BSOD - and the basic method works except for one VERY annoying fact.

I can't get set image colorkey to work with images created using set camera to image. Once I've solved that I should have a demo to show you.

I'll post a query on the main DBP board.

Quote: "The way you choose lies through many dangers,
and you may fall on the way."


True - but I haven't given up yet.

Edit Got a working demo now - but it is very inefficient. Will post it this evening when I've cleaned it up a bit.

2nd Edit Here's the demo. It is very very slow - but it "works". Suggestions for speeding it up welcome.

3rd Edit Todd Riggins pointed out how to simplify the camera rendering on the following thread:

set camera to image and transparency

Didn't speed it up though.

Attachments

Login to view attachments
Monk
16
Years of Service
User Offline
Joined: 25th Sep 2008
Location: Standing in the snow =D
Posted: 8th Feb 2009 13:03 Edited at: 8th Feb 2009 13:04
Im not entirely sure what you were aiming for, because when i ran yours i got 0 fps and about 25 secs between each frame...
Just a point though, you're trying to save two bitmaps with the same filenumber (4), and when i took out all the hide and show objects in your code, i got 52 fps with 5 spheres, and about 15 with 20, without any apparent loss of anything....

p.s the majority of my lost fps was due to the saving, loading and pasting of images, not the syncing...

mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 8th Feb 2009 13:23
AFAIUnderstand your demo,
it renders cubemap for object and then
object itself...
It is true fatality for any PC
But idea is genious!
As far as demo using save-load files in each loop (sometimes they left in folder & sometimes not) it speed would be x2 or more slower. I've got 1 fps.

So there is no way to save cubemap itself?
Maybe...Lee would be generous to add this feauture?

A door is a door is a door. Even a swinging one. =0
mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 8th Feb 2009 13:26
Oh oh oh
If you're mentioned,
that I've said
Quote: "As far as demo using save-load files in each loop (sometimes they left in folder & sometimes not) it speed would be x2 or more slower. I've got 1 fps."

This means even without save-load this demo would be
slow because of multiple screen renders.

A door is a door is a door. Even a swinging one. =0
Monk
16
Years of Service
User Offline
Joined: 25th Sep 2008
Location: Standing in the snow =D
Posted: 8th Feb 2009 13:33
Well i remmed out the save and loading and got from 0 to about 5 fps, and then remmed the hide and show and got upto 15 fps so i dont know whats happening...

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Feb 2009 13:37
Quote: "Just a point though, you're trying to save two bitmaps with the same filenumber (4)"


No I'm not. Image 4 (not file 4) is repeatedly re-used to save memory. Also, using Todd Riggins suggestion, the repeated save and loads are no longer needed but have no real impact on performance as it happens.

Quote: "and when i took out all the hide and show objects in your code, i got 52 fps with 5 spheres, and about 15 with 20, without any apparent loss of anything"


That's because in that demo it's very hard to see the differences between the different cube maps applied to each sphere. I think it's a waste of processing power to try to calculate separate cube maps for each object as done in the demo - I was merely showing how it COULD be done.

I could probably have made the effect more obvious by placing a few other fixed objects around the scene - if they were positioned correctly you would see them on the surface of some objects but not others.

Quote: "p.s the majority of my lost fps was due to the saving, loading and pasting of images, not the syncing..."


Yes, I haven't tried to break the time down. I'll look into that and see if that is the main problem here too. I don't have save/load anymore so your finding suggests it's paste image that's the problem which wouldn't be surprising.

I couldn't see any other way of rendering each sphere using separate updated versions of the same cubemap image. The demo allows more or less any number of spheres - but you need only one section of cubemap image memory to do the job. I'm sure that if you had 100 reflective objects you couldn't have 100 separate cubemaps. This demo shows you can - but only by updating and re-using the same image memory.

The use of paste image was just a lazy hack because I couldn't be bothered to use full-screen shaders. It's much easier to get the pixel alignment right by using paste image.

Perhaps I should give it a go now that the basic logic of re-using image memory is in place.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Feb 2009 13:43
Quote: "So there is no way to save cubemap itself?
Maybe...Lee would be generous to add this feauture?"


Yes - and volume textures too. I forgot to ask for those features when Lee asked for suggestions at the Convention. Perhaps I'll come prepared to the next one.
Monk
16
Years of Service
User Offline
Joined: 25th Sep 2008
Location: Standing in the snow =D
Posted: 8th Feb 2009 14:30
Oh, it was just a few things i spotted, but i no very little if anything about shaders, and one day i might get time to read this thread...

Todd Riggins
20
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 8th Feb 2009 17:47 Edited at: 8th Feb 2009 19:03
Hi, I wanted to see why there isnt any speed difference with the set camera to image method. Taking a look now...

Where does "make dynamic cube map #, #" come from? It isnt highlighted ... cant find it in the help files... yet... eventhough it works " render dynamic cube map " ?? Are these new ? I never seen them before... (jeah, Im a dynamic cube map making noob) - " sync camera 1 " ??? Man , I've been left outta of the loop...

Edit: * This is different then what I thought you wanted at first in the other thread. So my suggestion may or may not have been for the best here.

Also, The "Sync Camera" command threw me off at first as the word "camera" doesnt highlight in `sync camera` for me, but works. Where are you finding these commands? They are not in the latest documentation???

Inspirational Music: Descent ][ Redbook Audio CD Soundtrack
mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 8th Feb 2009 18:56
Quote: " Are these new ? I never seen them before... "

Yes it is new undocumented commands (for now)

sync camera 1 is same as sync mask 2^1:fastsync AFAIR

A door is a door is a door. Even a swinging one. =0
Todd Riggins
20
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 8th Feb 2009 19:04
Ah, thanks mrHandy.

Inspirational Music: Descent ][ Redbook Audio CD Soundtrack
mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 8th Feb 2009 20:02 Edited at: 8th Feb 2009 20:08
@GG
btw, if you can ask Lee for new commands,
please dont forget to ask for smth like
save cubemap to image cubemap id, image number
because if he will add only smth like
save cubemap to file cubemap id, file
we would be used to load just saved cubemap
back to application and this will be perfomance hit.
So, we need both of these commands.

PS what if...such commands already exists,
but undocumented? Sure, Lee likes to surprise people,
like Todd
EDIT
and me

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: 9th Feb 2009 00:16
Todd Riggins

Quote: "Also, The "Sync Camera" command threw me off at first as the word "camera" doesnt highlight in `sync camera` for me, but works. Where are you finding these commands? They are not in the latest documentation???"


They are the new commands that came with Dark Shader. Some of them may have been incorporated into DBPro, but I'm not sure. If you don't have Dark Shader but the program runs then it sounds as if they have been incorporated - but you'll need the keywords file, ShaderData.ini for them to be highlighted in the editor. Here's the only documentation I have (apart from some additional stuff in the Dark Shader Help file):

Todd Riggins
20
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 9th Feb 2009 03:30 Edited at: 9th Feb 2009 03:31
AH cool. Yes I have Dark Shader. I had to rewrite what you have there like other keyword files. Some reason the '*' and not having '==' to seperate the keyword and description wouldn't work for me. Mabie because Im using Synergy. But thanks!



Inspirational Music: Descent ][ Redbook Audio CD Soundtrack
mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 10th Feb 2009 02:47
If you remember Evolved's shaders,
he used to calculate world space texture
using two cameras - 'grey' and funny 'checkers'
but why two cameras to make WS map?
Can it be just one?

PS i've tried to calculate WS in 'grey' map,
but its not calculating, only
if 'grey' pixel passed to camera and then to map
and then to WS part...

A door is a door is a door. Even a swinging one. =0
Math89
20
Years of Service
User Offline
Joined: 23rd Jan 2004
Location: UK
Posted: 10th Feb 2009 11:38
He uses 2 renders because each render could only have 255 values for each colour (which is certainly not enough to store the world position). In the newest versions of DBPro, it is no longer a problem.
I changed his deferred shading in order to get more accuracy with only one render, and I will probably post it as soon as I finish the DBPro library to handle different types of light with the deferred shading.

Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 10th Feb 2009 16:15
Sweet. Good work Math89.

-= Out here in the fields, I fight for my meals =-
mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 11th Feb 2009 11:01
@Math89
I can only say "WOW!!!" and wait for your post

A door is a door is a door. Even a swinging one. =0
mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 12th Feb 2009 01:27
What are these commands exactly do?

faceforward(n, i, ng) - returns -n * sign(dot(i, ng))

lit(n dot l, n dot h, m) - returns lighting intensities for diffuse and specular lighting given the dot products of the lighting vectors. (scalars only)

smothstep(min,max,x) - returns a smooth value between 0 and 1 when x is between min and max. returns 0 if x is less than min, returns 1 if x is greater than max.

ddx(x) - returns the change in the texture coordinate when the screen pixel coordinate's x value is incremented by one.

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: 12th Feb 2009 21:41 Edited at: 12th Feb 2009 21:51
Several Edits Later: Finally got my quote tags in the right places

From the MS DX9 SDK:

Quote: "faceforward (DirectX HLSL)
Flips the surface-normal (if needed) to face in a direction opposite to i; returns the result in n.

ret faceforward(n, i, ng)

This function uses the following formula: −n × sign(dot(i, ng)).

Parameters
n
[in] The resulting floating-point surface-normal vector.
i
[in] A floating-point, incident vector that points from the view position to the shading position.
ng
[in] A floating-point surface-normal vector.
Return Value
A floating-point, surface normal vector that is facing the view direction.
"


I guess that could be useful for making sure that polys are lit from both sides - otherwise polys lit from behind wouldn't get lit.

The smoothstep function uses simple linear interpolation between 0 and 1 when the x value lies between min and max. For example, if min = 100, max = 500, then

smoothstep(100, 500, 50) = 0 (because 50 is less than 100)
smoothstep(100, 500, 200) = 0.25 (because 200 is one quarter of the way between 100 and 500)
smoothstep(100, 500, 450) = 0.875 (because 450 is 87.5% of the way between 100 and 500)
smoothstep(100, 500, 800) = 1 (because 800 is greater than 500)

This command is useful for things like fog or where you want a smooth transition betwen two colours.

I think you've miscopied or misquoted the ddx description. Here's what the MS DX9 SDK says:

Quote: "ddx (DirectX HLSL)
Returns the partial derivative of the specified value with respect to the screen-space x-coordinate.

ret ddx(x)

This function computes the partial derivative with respect to the screen-space x-coordinate. To compute the partial derivative with respect to the screen-space y-coordinate, use the ddy function.

This function is only supported in pixel shaders.

Parameters
x
[in] The specified value.

Return Value
The partial derivative of the x parameter."


I can see why you find that confusing - they've used "x" in two different senses, i.e. the screen-space coordinate x and the argument of the ddx function.

My understanding of this command is that it works as follows. Suppose, for example, you want to know how much an object's world-space position changes from one screen pixel to the next. Then your pixel shader would need to be passed a suitable variable such as "float4 wpos : texcoord3;" from the vertex shader. In the pixel shader you could use "float3 xChange = ddx(wpos.xyz);". How you might use that information is another matter entirely - and I haven't used it so I can't guarantee that I've got it right . I'm sure it's useful for creating all sorts of unspeakably cool effects - but I haven't seen it used yet.

Hope this helps.
mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 15th Feb 2009 20:18
Oh, thanks a lot! now i think i should download directx sdk to prevent such questions

And kind a tech question -
is it avaliable to pass variable (any type of float)
from vs to ps NOT using texcoord
,
like i want to pass depth float.
now im using struct
float DEPTH:texcoord1;
but IMHO depth is not a texcoord,
and shouldnt take one tex stage.

BTW what types of passing floats exists?
i know two - using texcoord to pass float from vs to ps
and in compile part i can add tex name in PS brackets,
to pass it to ps for saving code lines, if several techniques
are same exept texture name.

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: 15th Feb 2009 21:11
The semantic "texcoord" is used for passing any float, not just texture coords. I guess it goes back to the origins of shaders where they probably were texture coords. The graphics pipeline is constructed to blend 8 textures in a sequence - a "cascade" - of 8 blending stages 0 to 7. I assume the 8 texcoords available, i.e. texcoord0 to texcoord7 were originally intended to be the UV coords of those 8 textures. However, from SM2 upwards they can be used for any floats (positive or negative), e.g. position, colour, fog, depth.
mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 15th Feb 2009 23:37
so there is no other way to pass floats from vs to ps?
kinda global variables or smth?

like
global float f;
vs f=1;
ps use f;
the end

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: 16th Feb 2009 00:43
I don't believe so - but there a few semantics you can use as well.

The shader below just colours the object bright purple. This is done by passing red and blue from the vertex shader to the pixel shader where they are added together with the UV coords to give the final colour. I've chosen to use the "color0" and "color1" semantics for this but you could have used "texcoord1" and "texcoord2" instead. If you choose to use the color variables then you need to remember that each component is clamped to the range 0 to 1.

You also need to make sure that your application and shader don't assume the color variables are used in the final blending (unless that's what you want of course ).

mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 16th Feb 2009 01:18
wow, so usefull!

i wanted to pass float with depth,
and now i think it is possible using color.
just rescale depth to 0-1 range...

btw, texcoord limit is 8, and color limit is...?
or tex+col<=8?

Why do you have not wrote an encyclopedia of shaders already?

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: 16th Feb 2009 11:52
Quote: "i wanted to pass float with depth,
and now i think it is possible using color.
just rescale depth to 0-1 range..."


Why not use one of the texcoord variables?

Don't forget that each texcoord variable holds up to four floats - so you can pack four separate single floats into a single texcoord and unpack them in the pixel shader. To have full access to each component you need at least SM2. That means you can pass at least 32 individual float variables plus a few via the color variables. I'm not certain, but I think there are 4 color variables (color0 - color3) available. There may also be a few others you can access such as fog (I'm guessing now and will need to check ).

Simple example using two float2s:



Quote: "Why do you have not wrote an encyclopedia of shaders already?"


Time.

I have thought about writing a simple guide, with lots of examples, specifically for DBPro. I would probably want to sell it if there was sufficient interest.
Try
20
Years of Service
User Offline
Joined: 16th Aug 2004
Location:
Posted: 16th Feb 2009 12:52
Quote: "I would probably want to sell it if there was sufficient interest."

Would defenitely want to buy it...

I'm looking forward to it

Cheers,
-Try
mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 16th Feb 2009 22:48 Edited at: 16th Feb 2009 23:07
Such book will be very handy.
I think it would be popular even outside of TGC!
edit
about texcoords - 10x man, you've opened my eyes!!!
waah i'm stupid

A door is a door is a door. Even a swinging one. =0
Irradic
18
Years of Service
User Offline
Joined: 1st Jul 2006
Location:
Posted: 26th Feb 2009 15:22 Edited at: 26th Feb 2009 15:32
Hello,

is it possible to combine a Normal Map shader with a fast bone component ? My attempts so far have been unsuccessful.
I want the Normal Map shader, which i'm using in this project, to offload the animation from the cpu and let it be handled by the GPU instead. If somebody could offer me a working solution I would be giving him the Battlemaiden character pack in return for the work.
Help would be highly appreciated ! Thanks

Attachments

Login to view attachments
James H
17
Years of Service
User Offline
Joined: 21st Apr 2007
Location: St Helens
Posted: 26th Feb 2009 17:00
Go here http://evolveduk.googlepages.com/Postprocessing.html and download the deferred shading demo. There is a shader in the deferredshading2/fx/bone directory called normalmap.fx. This should suit your needs - they are all shaders for bones in there
Irradic
18
Years of Service
User Offline
Joined: 1st Jul 2006
Location:
Posted: 26th Feb 2009 17:21
@James H - Thanks. I'm aware of the Evolveds Deferred Shading Demo.
But I need this specific normal map shader edited, it has some extras which I need.

mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 10th Mar 2009 01:59 Edited at: 12th Mar 2009 13:56
agrhhhh
i cant figure out, how to rotate cubemap by x y or z in skybox...
need help

edit: me as usually forget about matrices in DB code, so everything ok now)

A door is a door is a door. Even a swinging one. =0
mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 16th Mar 2009 09:06
Example by Green Gandalf - how to make two samplers in a single technique


A door is a door is a door. Even a swinging one. =0
AtomR
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Portugal
Posted: 16th Mar 2009 23:55 Edited at: 16th Mar 2009 23:57
For the hundreth time i'm trying to wrap my head around writing shaders. So i'm following a tutorial for fx composer that starts with writing a shader that colors an object with one color. Then the next one adds texture and its like with very basic steps. The problem is I followed the tutorial but i don't get the result i should.
Here is the shader:

It should paint a texture on the object but all i get is this.

I've tested it and the problem isn't with the objects UVs. Can any of the shader gurus tell me what is wrong coz i can't tell :/

Take care
AtomR

Attachments

Login to view attachments
mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 17th Mar 2009 00:49
Err dont use FX composer - only for debug! It's very stupid program, but better than Mental Mill anyway)

Just look at posted code above! You have missed some data, and some of your code is kinda weird.

A door is a door is a door. Even a swinging one. =0
AtomR
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Portugal
Posted: 17th Mar 2009 01:01 Edited at: 17th Mar 2009 01:03
Can u elaborate? Not to sound rude and unapreciative but stupid program and weird code doesn't really help :/

I know that not all .fx works with dbpro but for now i'm just concentarting on understanding shaders. I'll worry about converting to dbpro when i can actually understand how they work. Thanks

-Edit-
I've tried replacing code with more conventional code. For example:
texture tileTexture: Diffuse;
with
texture tileTexture < string ResourceName = ""; >;
and
output.texCoord.xy = input.pos.xy;
with
output.texCoord = input.pos;

But the result is the same in either case.

Take care
AtomR
mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 17th Mar 2009 01:46
Okay...
1. Every FX works with dbpro until FX have some additional commands, like GUI scripts for 3ds max or FX composer.
2. Catch this and use as base of any new shader:



A door is a door is a door. Even a swinging one. =0
AtomR
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Portugal
Posted: 17th Mar 2009 11:09 Edited at: 17th Mar 2009 11:10
Ok based on your base shader i could deduce what was wrong.
My vertex shader was doing:
output.texCoord = input.pos;
This was atributing texcoords based on positions instead of actual uvdata. So i added
float2 uv:TEXCOORD;
to the vertex shader input struct and then
output.texCoord = input.uv;

Thank you, mrHandy.

Take care
AtomR
mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 17th Mar 2009 12:18
Also you should notice that some parts of shader are case sensitive, but i dont remember exactly. My example shader wont work if code is capitalized.

Plus if you want to use parts of EVOLVED's shaders, mine shader base 100% compatible. Your shader not, corrections needed.

A door is a door is a door. Even a swinging one. I always wanted to take part in my life. Here, have a piece of gum. I've played Gulman 3D part 2!
AtomR
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Portugal
Posted: 17th Mar 2009 18:10
Well, the reason I want to learn this is so i don't have to use parts of anyone else's shaders Or at best so i can understand how other ppls shaders work and adapt it to my need. But that's a long time away But shaders are the future and I really really want to catch up with the trend.
What confuses me a lot is world space, object space, tangent space, view space etc. I know what they are but i don't know when to choose one over the other. Once i wrap these around my head everything else will just fall into place... or not.
But as we speak i've done a shader that adds a texture, ambient light and a point light to an object I r happy.

Take care
AtomR
Monk
16
Years of Service
User Offline
Joined: 25th Sep 2008
Location: Standing in the snow =D
Posted: 19th Mar 2009 18:56
Would anyone be able to explain shaders to me? Or point to somewhere that can tell me how to implement shaders to objects.

Im not really interested in writing my own shaders yet, I dont understand enough, but when I look through other peoples code, I dont understand the important stuff.

If possible, I could do with some help on why people use commands like set vector4, set effect constant vector etc...
And also, if i were to use someone else shader, how would I use it and apply it to an object?

Im sorry, Im completely new to such things and really havent had the time to read all 28 pages, I only got to page 6, and didnt understand anything =(

Thanks

Login to post a reply

Server time is: 2024-11-24 12:14:33
Your offset time is: 2024-11-24 12:14:33