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 / Few questions about texture layers

Author
Message
wh1sp3r
21
Years of Service
User Offline
Joined: 28th Sep 2003
Location: Czech republic
Posted: 17th Mar 2008 16:15
When object has only one set of UV's .. So,every stage has same UV

texture object x, 0,img = UV0
texture object x, 1,img = UV0
texture object x, 2,img = UV0
texture object x, ...,img = UV0

when I would like to use two sets of UV's, so

texture object x, 0,img = UV0
texture object x, 1,img = UV1
texture object x, 2,img = ????
texture object x, ...,img = ???

Isnt it ? I dont understand now, how its working


PS: Real programmers aren't afraid of math!.
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 17th Mar 2008 16:33
You need to use the Set Blend Mapping On command to specify anything like that.

wh1sp3r
21
Years of Service
User Offline
Joined: 28th Sep 2003
Location: Czech republic
Posted: 17th Mar 2008 16:37
dark coder : Its for shader anyway, I would like to know, how does it works.

Where i set 2 sets of 'UV¨s (FVF ... + 0x200) Where is first UV set and where is second UV set .. if STAGE 0 is first UV, and STAGE 1 is second UV, but what UV has STAGE 2 ?


PS: Real programmers aren't afraid of math!.
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 17th Mar 2008 17:03
In that case, in your shader you specify which texture coordinate stage you're reading from when sampling from a texture, in DBP you don't tell it which to use. To use two sets of UV texture coords as you said, you just need the 0x200 flag on the object's FVF, this can either be sets via memblocks when making a mesh or you can modify the FVF of an object using the Convert Object FVF command, however this will most likely just create a blank UV set, i.e. all the UV coords will likely be set to 0.0 so it's your job to make them do something useful. Once that's done, in your shader, you need to make the texture coord 1 or the TEXCOORD1 semantic get passed as a parameter to the fragment shader, once done, you can sample from it using what's most likely the tex2D function.

wh1sp3r
21
Years of Service
User Offline
Joined: 28th Sep 2003
Location: Czech republic
Posted: 17th Mar 2008 17:29
dark coder : I know about that, but how does program know, what UV stage has ..

For Example:

Stages 0 and 1 has UV0, Stages 2,3,4 .. has UV1. I would like to know, how can I assing UV's to stages ? I am sorry, sometimes is too dificult explain something in english for me


PS: Real programmers aren't afraid of math!.
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Mar 2008 17:52 Edited at: 17th Mar 2008 17:53
Quote: "dark coder : I know about that, but how does program know, what UV stage has .. "


The program, i.e. your shader, doesn't know - as Dark Coder said, you have to tell the shader which to use when you write the texture look-up.

To use your example, the shader might have 5 texture declarations:



with associated samplers



At that point the samplers are just associated with the five texture stages specified in your DBPro program - the shader doesn't yet know which set of UV coords to use.

You do this as follows in your example:

First tell the vertex shader to read the two sets, e.g. your vertex shader input structure might be:



and the vertex shader might have something like



(You would need a matching output structure and an input structure for the pixel shader of course.)

The pixel shader then assigns the 2 UV coords to the 5 textures with something like the following:

wh1sp3r
21
Years of Service
User Offline
Joined: 28th Sep 2003
Location: Czech republic
Posted: 17th Mar 2008 18:19
Green Gandalf : Thank you GG, um, but, how can I set UV0 and UV1 in dbpro ?


PS: Real programmers aren't afraid of math!.
wh1sp3r
21
Years of Service
User Offline
Joined: 28th Sep 2003
Location: Czech republic
Posted: 17th Mar 2008 18:36 Edited at: 17th Mar 2008 20:48
prob here:



dbpro



Object always disappear why ? thanks


PS: Real programmers aren't afraid of math!.
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 17th Mar 2008 20:43 Edited at: 17th Mar 2008 20:44
Did you try it without the FVF_DIFFUSE? I don't think that FVF would be correct for that particular shader effect. I am wondering myself, perhaps a shader guru can tell us:
How you determine the FVF needed for a particular shader?
How can you tell what the FVF of an object is in the first place? I would hate to have to resort to using DirectX for something like that.
wh1sp3r
21
Years of Service
User Offline
Joined: 28th Sep 2003
Location: Czech republic
Posted: 17th Mar 2008 20:49
jinzai : same without diffuse


PS: Real programmers aren't afraid of math!.
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Mar 2008 21:16 Edited at: 17th Mar 2008 21:20
Various problems there:

1. You need to set the second set of UV values in DBPro - use the vertexdata commands. To get the idea I suggest you start by just copying the first set into the second stage.

2. You shader doesn't compile - which means that DBPro will fail to show the object.

3. The reason the shader doesn't compile is that you copied my snippets without making sure you had a complete shader - they were only meant to illustrate the use of UV coords and textures not to give a complete shader. For example, the quantities "scroll" and "seconds" need to be declared and given values in your shader code. You also need to declare "col" in the pixel shader output structure.

Try the following shader code: I've marked the changes with // ** GG ** //



The above code should run with your dba code - but you should see it doesn't work correctly. This is because the second stage UV coords have been set to zero by default when you changed the object's format. See if you can use the vertexdata commands to sort that out.

Some other points to note:

4. The pixel shader output structure must only contain color as shown in the corrected code above.

5. The pixel shader input structure probably shouldn't include the "pos" variable - it does no harm if you leave it in but you'll get an error if the pixel shader tries to use it. Therefore best to remove it.

6. In the technique section the vertexshader declaration uses VS2_0 not PS2_0 (I guess that was a typo ).

That was a good attempt at a first shader and was clearly constructed so it was easy to correct.

[Edited typo. ]
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Mar 2008 21:19
@jinzai

Quote: "How can you tell what the FVF of an object is in the first place?"


Make a memblock from it's mesh - check the DBP Help file for details.
wh1sp3r
21
Years of Service
User Offline
Joined: 28th Sep 2003
Location: Czech republic
Posted: 17th Mar 2008 21:35 Edited at: 17th Mar 2008 21:44
Green Gandalf : Thank you GG I dont know, how to set UV's um .. I have to set UV's to second stage, have I ?



It works ! Hey GG, Do you know about really helpful website with shaders? I was googling ..but, There are lot of webpages, which are always difficult without explantation.


PS: Real programmers aren't afraid of math!.
wh1sp3r
21
Years of Service
User Offline
Joined: 28th Sep 2003
Location: Czech republic
Posted: 17th Mar 2008 21:54
GG: what is bad here, please ?



I think, that code is alright... I owuld like to only read texture from object, and show it again. Only blue screen ...


PS: Real programmers aren't afraid of math!.
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Mar 2008 22:28
Quote: "I think, that code is alright"


It isn't.

If you are seriously intending to work with shaders you need to get something like Dark Shader. That would enable you to check that your shader code compiles and runs (whether it gives you what you want is another matter ) - it also gives you some error messages which make more sense the more you know about shaders. ) [There are some exceptions because Paul forgot that the shader compiler also gives warning messages. ]

In your case you've used "void" as the return structure from your vertex shader and pixel shader codes when they should be a structure that matches your "return" statements. Replacing the two "voids" with "VSoutput" and "PSoutput" respectively, as in your previous example, should work.

By the way, I went through all this myself when I started - step by step tutorials are hard to find and I had to get some decent books before it began to make sense (e.g. see Chris K's first post on the "Learning to write shaders" thread). A lot of shaders on the web are often unnecessarily complicated and don't work in DBPro without major changes. I've stumbled across a few useful websites but none specifically spring to mind. My best advice is to keep Googling - and get one of the MS DX9 SDK's, they're free and contain lots of useful stuff when you know where to look.
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 17th Mar 2008 22:29
Thanks heaps, GG.
wh1sp3r
21
Years of Service
User Offline
Joined: 28th Sep 2003
Location: Czech republic
Posted: 17th Mar 2008 22:30
Green Gandalf : omg, I see ... void function cannot return the value .. omg .. Dark Shader shows errors and warnign ?? nice !! I am gonna buy it !


PS: Real programmers aren't afraid of math!.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 17th Mar 2008 23:46
@jinzai,
There's a function in one of my plug-ins called GET LIMB FVF that will also do the job without the overhead of copying the data around in memory.

jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 17th Mar 2008 23:49
oh, IanM...you're the dreamiest! That settles it, I'm d/ling yer codez! (btw, I knew you had something for that!)
Cheers.
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Mar 2008 00:30
Yes, I need to check through IanM's functions as well. I've got the plug-in (I think) but am only familiar with one or two of them. The few I've used work perfectly.

Login to post a reply

Server time is: 2025-08-09 02:28:11
Your offset time is: 2025-08-09 02:28:11