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 / Setting the Constant Register of Pixel Shader

Author
Message
Bulleyes
23
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 7th May 2003 21:45
Hi, how do I set the Constant Register of a Pixel Shader in DBpro? I can't find such command in the help. Don't tell me DBpro doesn't have any way to do this (that will be bad)? Or possibly, any undocumented commands for this?
Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
Bulleyes
23
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 8th May 2003 18:12
Hmmm.... nobody knows this? I can't believe it.

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 8th May 2003 21:55
Raven answered a question like this a few days ago.

I have no knowledge about shaders themselves, but I can tell you that there are no hidden shader commands.
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 8th May 2003 22:25
set vertex vector [shader],[constant address],[vector],[size]

i don't have pro installed at the moment so i can't tell you that is it word for word, but i think that is the command and you'd use it like



i know that the commands might be off a little bit cause i don't have them right infront of me - but that should work with a vector no problem ... here's a shader to test it with



that should do nothing but normalise the vectors of the object based on your vector constant ... thats if i've done that right lol
i'm so used to having the manuals infront of me to look up the names so might be a tad wrong - but i think it should be fine

good enough for you to get the idea of howto use them

Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?
Bulleyes
23
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 9th May 2003 15:26
Erm... thanks for the info, Raven. But, actually I am asking about setting the constant register for PIXEL SHADER, not vertex shader. (Hehehe... I can hear a big ooops.)

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 9th May 2003 18:25
not really... its the same deal i'm working on a small demo right now of bumpmap shadow shading (in dbpro) uses Pixel&Vertex Shaders.
should be ready in about 3-4hrs
i'm not rushing anything i just want it working right... i'll post up once i'm finished.

its nothing fancy just the earth & moon spinning both bump mapped (with a shader) which has additional shadowing plus a basic "fur" shader is used to create layered cloud cover
if i can be arsed i'll make the sun from a fire shader set, but i probably won't even bother with a sun.

Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?
Bulleyes
23
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 10th May 2003 06:25
Cool Raven! Thanks a lot! I learn better thru examples! You can just email me directly. Thanks again!

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 10th May 2003 13:35
lol... i'll have to clean this up alot before i send it - my coding style is ... erm ... yes
also got some bugs to ween out, seems DBpro doesn't really like using anything other than Pixel&Vertex Shaders 1.0

Within the Epic battle of the fates the Shadow and the Angel will meet. With it will harbinger the very fight of good vs evil!
Bulleyes
23
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 12th May 2003 14:13
Meaning that DBpro only supports Shader 1.0? I thought this shader thing is depends on your graphics card and also the DirectX version installed?

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 12th May 2003 18:01
well it'll use 1.1 and 1.2 shaders - won't use 1.3 at all (crashs pro) and you can forget about anything above that...

but as i'm not used to only using 1.1 then that would be oki, cept its a bit jittery about loading them - sometimes it loads them find, sometimes i doesn't, kinda weird.
Personally i hope the added DirectX9 support in patch5 will mean that we can use DirectX .fx instead - cause then i can use Cg

that aside, i wanna get a demo up and running - cept right now i'm having major problems with my system ... keeps hanging on me.
I'm not sure if it's SP1a or if my HDD is just on its last legs.
i've shifted all of the files on my other hdd's around to be in single directories for a backup copy later so i can reformat the other HDD and use that - and turned of fast write caching, which means the HDDs are now slightly slower ... but seems to be staying on longer without crashing.

thing thats bugging me the most about this is i tried to debug windows, and i can't run Windows Debugger and it crashs the entire system

Within the Epic battle of the fates the Shadow and the Angel will meet. With it will harbinger the very fight of good vs evil!
Bulleyes
23
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 13th May 2003 10:02
Good luck to you man! I usually will reformat my HD and reinstall my OS again when I met this.

Oh, BTW, can you pls jz send me the pixel (and vertex) shader examples when you done with it. I still haven't figured out how to set the Constant Register of a Pixel Shader. It will be a real pain to me if I was unable to do this. :-s

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
Hubdule
23
Years of Service
User Offline
Joined: 3rd Sep 2002
Location: Gundelsheim
Posted: 13th May 2003 10:24
simply wait for Patch 5 as there would be better shader support (as read in Lee's diary @ DBDN)

Bulleyes
23
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 13th May 2003 16:22
How long am I expect to wait? 1 month? That's the most I can wait.

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
Zembla
23
Years of Service
User Offline
Joined: 18th Dec 2002
Location:
Posted: 13th May 2003 22:01
hi,
there are 8 constant registers (c0 to c7) in pixel shader spec. they are read only and constains 4 floating point( channels).
Use "def" instruction to load your constant register in your pixel shader file.
that's all


Bulleyes
23
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 14th May 2003 08:01
Thanks Zembla! I know I can do that. But what I want is to set the pixel shader constant register in DBpro. I know it can be done, as there is a function in DirectX SDK called SetConstantRegister() (or something like that).

How is it coming, Raven?

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 14th May 2003 08:03 Edited at: 14th May 2003 08:06
not sure how long your suppose to wait for patch5
i'm not at home right now and someones turned off my remote desktop (which is annoying)

so i've had to try and code something without dbpro and even a viable machine to run it on (GeForce2 Go! don't like Px Shaders, run Vertex ones like a dream though lol)

as for constants/registers/etc declared in the code - you can't just use them on thier own... well the constancts you can, but you're not suppose to really.
i was reading through the help and your right they have skipped on the constant/register export to the pixel shaders - though as i noted a while ago they've not got Vector4's for Vertex yet... i'm hoping to god that the new shader extentions within p5.0 actually makes them more worth while using, because the depth has limited anything to be done in a standard way.

but personally i'll be far more greatful for added outputs and the use of the .fx format

anyways - enjoy my very basically cutdown and hyper commented shader
i checked it for spelling so really it should work off the bat, but knowing my coding skills it'll need a tiny tweaking before it works

what you should see is this ->


heres the image to do it with


i know its not much but hopefully it should help a few of you understand a little better howto make something simple
this simple little technique can be used to do allsorts though.

it takes little effort to actually enhance this a little to include say a second picture and then combine that through the colour channel

[edit-] almost forgot to mention, the way to edit the constants of pixel shaders and such is actually through a vertex shader... the whole shaders setup means that to get the most out of them you'll actually be using them in combination with each other to perform certain tasks.
the DirectX 9 SDK has alot of the information needed to understand this

Within the Epic battle of the fates the Shadow and the Angel will meet. With it will harbinger the very fight of good vs evil!
Bulleyes
23
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 14th May 2003 08:10
Hmm... meaning that I can't pass certain value that I had calculated in DBpro to the pixel shader. As far as I know, the constant register in both vertex and pixel shader is a convinient way to enable communication between the shader code, and the programming code that loads it, which in this case is DBpro.

Thanks for your code, Raven!
Cheers!

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
Bulleyes
23
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 14th May 2003 08:14
Hmmm.... a good example is, I wanna make a pixel shader to specular mapping (or shininess mapping). I need to pass in the lights vector in DBpro to the shader for calculation.

p/s: I am still new to shader. I might be wrong that pixel shader is suitable for this. Anyone, feel free to comment me if I am wrong. Or whether vertex shader is more suitable for this?

Oh... BTW, does anyone had the algorithms (not necessary source code) for calculating specular mapping (or shininess mapping)?

Thanks a lot!

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 14th May 2003 08:18
well for some reason in pro the pixel and vertex shader instance are kept seperate... becuase your right in C++ the SetConstant does do both, however difference is the constants in the vertex shader are actual editable pipeline but the pixel ones arn't - which would probably explain why you can't do it in pro.
but still is annoying...

i'd suggest if you need to setup any specific data you want to pass you use the diffuse, specular and other generally unused registers
that what i've done for alot of hacks around the limitations

and hope the code actually works for ya lol else its a pretty poor example

Within the Epic battle of the fates the Shadow and the Angel will meet. With it will harbinger the very fight of good vs evil!
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 14th May 2003 08:22
lol... oh you wanna make something shiney, like metal perhaps?
then you'd be wanting the vertex shader

i'll see about mocking up some fresnal metal code for ya, alternatively i'd just use Spheremapping with a chrome like texture

Within the Epic battle of the fates the Shadow and the Angel will meet. With it will harbinger the very fight of good vs evil!
Bulleyes
23
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 14th May 2003 09:05
Hmm... thanks for your help, Raven! I really appreciate that!

What I meant for specular mapping is I had a grayscale image which determines the shininess of an object.

I tried using using sphere mapping before by creating a sphere map image with a sunburst gradient in the image. That will makes my model looks somehow shiny by the existence of the specular hilighting.

This is only good if the entire object have the same degree of shininess (uniform specularity). But actually that's not what I am looking for. For my case, I had a specular map (or shininess map) that determines which part of my models are shinier than others. The effects can be more apparent when the object is rotating while the light source remains the same.

If you are working in 3D Studio MAX, you will know what I mean. The terminology for this effect in MAX are specular mapping.

Again, I am grateful to you, Raven! Thanks!

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
Bulleyes
23
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 14th May 2003 09:08
OH... I thought of something...

The main reason why sphere mapping doesn't do the trick is that, the mapping doesn't rotate with the model. So even if are managed to create a chrome like texture, the specular map will be out as the model rotates.

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
Bulleyes
23
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 14th May 2003 09:14
Hmmm.... I hoped you can understand. I am a bad teacher.

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 14th May 2003 09:16
lol... well i'm not sure how dbs have implimented thier spheremap effect - but it makes a good shine.

you could always convert your model to a format with specular and then put it in a memblock, and then find out the specular colour from the map you've created for that vertex point (use the texcoords for it) and then once your done convert back to an object and put the texture back on.

wouldn't even need shaders then

Within the Epic battle of the fates the Shadow and the Angel will meet. With it will harbinger the very fight of good vs evil!
Bulleyes
23
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 14th May 2003 09:29
Hmm... sounds possible. Good one, Raven!

How do I know the way DBpro store the model in memblocks. From what I can understand, I need to access the vertices data and also the texture maps and texture coords. Is these data are in the memblocks as well?

Oh, BTW, are the specular color are stored in the DBpro object as well? As for my case, the specular map is a GREYSCALE image which determines the shininess of the surface. It is NOT the surface specular color. But from what you are saying, if I manage to get the specular color of each vertex of the model, I might be able to modulate the specular color based on my specular map.

Thanks man! You had enligtened me!

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 15th May 2003 00:46
natively no DBpro doesn't load the specular colour map (which is annoying)

now for a basic setup what you'll have to do to set it up is this ->


all you have to remember is the first 12bytes of a Memblock is
4byte DWORD - FVF Code
4byte DWORD - Size of Vertex Data
4byte DWORD - Number of Vertex

you shouldn't need to know the FVF Code, as thats the number you used to "convert object fvf"
size is the number of bytes in the vertex data... as almost every setup of FVF you'll use in DBpro will be standard instance you can assume that all data is either a 4byte float or a 4byte dword

also you notice the order in which i've declare things
XYZ (position)
DIFFUSE (diffuse colour)
SPECULAR (specular colour)
TEX1 (1 Set of Texture Coordinates)

this basically means this is also the order in which they are within the vertex data stream.

so to get to specular you need to offset each vertex position by 16, as XYZ is 3float position, and diffuse is a 1dword colour...

hopefully that makes sense, once you have that down and understand it i'll edit the code i made to handle a second texture which in this case will be the specular map and show you howto blend them to get the effect you want

Within the Epic battle of the fates the Shadow and the Angel will meet. With it will harbinger the very fight of good vs evil!
Bulleyes
23
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 15th May 2003 06:21
Thanks! Hmmm... how do I know the order of the vertex data stream? By just following the order of the flags passed in CONVERT OBJECT FVF? That doesn'y make sense to me as from what I understand so far, the flags are just a bit masks.

Therefore,
FVF_XYZ || FVF_DIFFUSE || FVF_SPECULAR || FVF_TEX1

or

FVF_DIFFUSE || FVF_SPECULAR || FVF_TEX1 || FVF_XYZ

or

FVF_SPECULAR || FVF_TEX1 || FVF_XYZ || FVF_DIFFUSE

still tell the function the same thing. So how do you know the data order of the vertex stream? i.e. you mentioned in the order of

XYZ (position)
DIFFUSE (diffuse colour)
SPECULAR (specular colour)
TEX1 (1 Set of Texture Coordinates)

Or is it following the same order as specified in the vertex shader v-registers? As in

v0. Position
v1. Blend Weight
v2. Blend Indices
v3. Normal
v4. Point Size
v5. Diffuse Color
v6. Specular Color
v7. Texture Coords. 0
v8. Texture Coords. 1
v9. Texture Coords. 2
v10. Texture Coords. 3
v11. Texture Coords. 4
v12. Texture Coords. 5
v13. Texture Coords. 6
v14. Texture Coords. 7
v15. Position 2
v16. Normal 2

Is that right?

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 15th May 2003 07:08
well yeah technically you could just put them in any order...
but its good practise to order them in the bits they represent
first 3 bit = position (xyz)
next 3 = extra position values
next 4 = diffuse/specular/point/(forget the last)
next 3 = texcoord number
next 3 = texcoords setup
the rest i'm not sure about, i think 32=lastbeta but don't hold me to it

but basically thats the order in which they'll appear in your stream - its easier to remember this if you put the code declaration in the order in which the bits come in
if you need to know the exact order the FVF help has it

as for the Vertex registers... no that isn't right at all

your declare the registers to the values

decl_position v0 ;this means v0-2 are now X Y Z of the vertex
decl_diffuse v3 ;this means v3 is now the diffuse colour
etc..

you have to declare them prior to use in the shader

Within the Epic battle of the fates the Shadow and the Angel will meet. With it will harbinger the very fight of good vs evil!

Login to post a reply

Server time is: 2026-07-11 03:38:17
Your offset time is: 2026-07-11 03:38:17