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 / 3 Terrain shaders with example!

Author
Message
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 9th Jan 2008 05:57 Edited at: 13th Mar 2008 08:20
So I said yesterday that I'd make an example of vertex and texture based multi-layered texture blending, and one day later I've finished writing it! I also made a shader based matrix example too(as each shader has its own use).

I've attached the shaders(with example) below, if you use them please give credit. Hopefully someone has a use for them, I believe the example is quite well documented, but ask any questions you have here. It requires a GPU capable of at least Pixel Shader 2.0(due to the amount of samples that are taken) and the latest DBPro(6.6b, though you may be able to use earlier versions, I haven't tested).

Pics:

Texture blended terrain:


Vertex blended terrain:


Shader matrix:


Stepped blending:


All of the terrains use an Advanced Terrain object as a base, so you get the advantage of welded vertices and frustum culling areas that aren't in camera view.

[Edit] Updated Shader Matrix for higher FPS and potentially sped up vertex blend.

[Edit] Added the stepped blending terrain texturing technique

Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 9th Jan 2008 06:00
Awesome man.

Tempest (DBP/DBCe)
Multisync V1 (DBP/DBCe)
RUCCUS
20
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 9th Jan 2008 06:45
That looks great, especially the second pic there. Really good job.

Sid Sinister
20
Years of Service
User Offline
Joined: 10th Jul 2005
Location:
Posted: 10th Jan 2008 04:24
Thanks for the demo =]

"If I have seen a little further it is by standing on the shoulders of Giants" -Isaac Newton
Roxas
19
Years of Service
User Offline
Joined: 11th Nov 2005
Location: http://forum.thegamecreators.com
Posted: 10th Jan 2008 12:44
PS 2.0.. You should think about older cards IMO


Click For Details!
bob_marley
17
Years of Service
User Offline
Joined: 19th Sep 2007
Location:
Posted: 10th Jan 2008 17:10 Edited at: 10th Jan 2008 17:32
Ask and you shall receive aye Sid?

Well thanks dark coder good job old boy

http://forum.thegamecreators.com/?m=forum_view&t=121141&b=6

simple editable text boxes..
david w
19
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 10th Jan 2008 23:01
@dc Thanks for these examples.
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 11th Jan 2008 00:07
Thanks for the comments.

Quote: "PS 2.0.. You should think about older cards IMO"


Well I tried to use PS1.4 for the shader matrix but for some reason the UV doesn't get shifted under it, also I forgot to remove some debug code while I added trim so the shader matrix should be a little bit faster now:



As for the other two, as I take 8 samples and use quite a few functions I highly doubt I can reduce the shader model. However if you were to remove some layers then it might be possible, I was just trying to get the most layers I could(and I could still get higher). Plus Shader Model 2.0 is quite common these days, even some games(other than DX10 ones) require SM 3.0 so maybe you should upgrade .

Roxas
19
Years of Service
User Offline
Joined: 11th Nov 2005
Location: http://forum.thegamecreators.com
Posted: 11th Jan 2008 14:25
Quote: "As for the other two, as I take 8 samples and use quite a few functions I highly doubt I can reduce the shader model. However if you were to remove some layers then it might be possible, I was just trying to get the most layers I could(and I could still get higher). Plus Shader Model 2.0 is quite common these days, even some games(other than DX10 ones) require SM 3.0 so maybe you should upgrade"


Yes i should.. I just need new processor(Mainly cuz my current one sucks.. But its overclockers friend ),motherboard,GPU :/


Click For Details!
Omega gamer 89
17
Years of Service
User Offline
Joined: 10th Sep 2007
Location: Pittsburgh, PA
Posted: 11th Jan 2008 16:22
lol, the first one looks like its made of Legos. But still, very cool.
Alquerian
19
Years of Service
User Offline
Joined: 29th Mar 2006
Location: Reno Nevada
Posted: 11th Jan 2008 18:49
This is really quite nice. I mean that. Great work DC. I will definitely be using one form or another of these in some of my future work.

Support the indie!
Aaron Miller
19
Years of Service
User Offline
Joined: 25th Feb 2006
Playing: osu!
Posted: 11th Jan 2008 20:57
Looks awsome man.

Cheers,

-naota

With any luck you'll be able to turn a fully functioning program to a crashing program with just a little bit of coding.
Aex.Uni forums
Ian T
22
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Around
Posted: 16th Jan 2008 05:48
This is very useful to me.

However, I have an issue with it that I believe relates to using shaders on objects in general. The terrains do not intersect nicely at all with other shaded objects - IE nice looking water. I guess they can't use the Z-Buffer like other objects? This is odd because you definately have a crapload of intersecting shaded objects in modern games working just fine. If there's a magic ingredient to fix this, I'd love to know it...
david w
19
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 16th Jan 2008 06:04
@Ian T what exactly are you talking about? I think you are refering to what appears to be, that the different shaders do "mesh" together nicely. Like they look out of place? Anyways I think that this is because we here are not "pro". But rather we use a collection of resources and alot of these are not written to compliment one another. For example the light position and range in a terrain shader might not be the same as the equivalent in a normal mapping shader, making it appear as though it does not quite fit into the scene.

Take for instance say you want water, terrain, and normal mapping, plus a sky and fog shader. Well the chances here are that most of to people on here will just download any one of the available shaders and set it up in their game world and not really understand what it means exactly for the light to be calculated, and in each shader probably will have different variables for each and then even different calculations on how the lighting is achived.

maybe I misunderstood what you meant. lol
MkyCky
17
Years of Service
User Offline
Joined: 15th Jan 2008
Location:
Posted: 16th Jan 2008 06:13
nice work


dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 16th Jan 2008 08:54 Edited at: 16th Jan 2008 08:55
He means my terrain models in my example are very small, when he placed water intersecting it there was a lot of Z-Fighting, I told him this over IRC anyway. It can be fixed by either changing the Set Camera Range's near value or increasing the terrain's size.

david w
19
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 16th Jan 2008 12:08
oh ok. lol.
Scraggle
Moderator
22
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 12th Mar 2008 15:25
Fantastic work DC!
I love the texture blended shader.

I have no clue how to code shaders, so anyone that offers work like this instantly becomes my hero

Baring in mind that I know nothing about shader code, could you please explain to me what I would need to do in order to also use the blue layer from the second LayerMap (and perhaps the alpha layers in both)?
Also, is there a way to adjust the texture scale?

Thanks a lot



BatVink
Moderator
22
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 12th Mar 2008 15:44
I also have questions as it's risen back to the surface...

Can the blended textures be exported as a new single texture, or is this something that is permanently shader based?

If it has to be always shader-based, do you know how much of an overhead it is? I'm a shader-noob, so I don't know if these things are a one-hit overhead, or will add to the load throughout the game.
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 12th Mar 2008 16:19
Quote: "could you please explain to me what I would need to do in order to also use the blue layer from the second LayerMap (and perhaps the alpha layers in both)?"


It depends what you mean, in my example I used the RGB and RG channels from the Layers map 1&2 respectively because you're limited to 8 texture stages for any given mesh, and because each texture can only store 4 channels maximum(ARGB) I was forced to use a minimum of 2 Layer mask images, I could have just use ARGB from the first and R from the 2nd, but in most image editing applications editing the RGB channels is usually much easier than editing the A as well.

Also, as listed in the shader, the first two texture stages are the Layer(mask)Maps, the 3rd being the base texture(this doesn't require a mask as it's assumed to be the default colour), I'm then left with 5 texture stages which I used as the subsequent 5 textures and are masked with the RGB + RG channels.

Now, it is possible to add more than 5 additional texture layers while keeping within the limits of 8 texture stages, you could even make the amount of layers almost unlimited by means of a Texture Atlas and some code to offset UV values you use to sample from, but such code makes the terrain masks harder to manage, not to mention adding more and more layers results in more and more slow down.

If you really need that many textures on your whole terrain you could possibly use multiple terrains so each terrain itself never uses more than 5 additional layers but you construct it so that overall you are using more.


Quote: "Can the blended textures be exported as a new single texture, or is this something that is permanently shader based?"


If you mean can a shader's result be rendered to texture, the answer is yes. A good example for code on this are things like bloom shaders(or any fullscreen shader), as they will place a quad in-front of the camera and render the texture on it with an effect to produce what's most likely a 1:1, pixel:texel rendition of it.

Here's two functions I used in my own bloom shader that do what you're after:



The same thing can also be done using a shader(the positioning of the squad that is), i.e. the Quad.fx that seems to come with DarkShader projects(quite easy to find when people upload their DS projects :p) which is better because using a shader you can skip the transform of an object(thus you don't have to account for FOV, but in my code I cheat and use Pick Object() to calculate that for me).

Quote: "do you know how much of an overhead it is? I'm a shader-noob, so I don't know if these things are a one-hit overhead, or will add to the load throughout the game."


The overhead is pretty-much constant and depends on many things, these shaders are all pixel shader intensive, thus render speed is determined by how many pixels of the terrain are being drawn, as there is quite a bit of computation being done. Rendering the final blending output to a texture would speed rendering up, but to get the detail as high as my example has, that would require a colossally large texture and isn't really practical(~65k px^2), but for a small terrain or things that aren't even terrains it might be beneficial.

wh1sp3r
21
Years of Service
User Offline
Joined: 28th Sep 2003
Location: Czech republic
Posted: 12th Mar 2008 19:56
dark coder : What about bump mapping and specular ? I know about limits, Its about 7 or 8 layers... but layers with own UV, or without UV ? I am using 10 layers of different textures blended together.

I dont understand, how can I render all textures from terrain into one texture, It will be really nice, if you put code here, how to make that Thank you


PS: Real programmers aren't afraid of math!.
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 13th Mar 2008 03:36 Edited at: 13th Mar 2008 08:26
Quote: "What about bump mapping and specular ?"


It is possible, but my example terrains were merely there to show as many layers as I could using fairly simple and easy to understand methods, it would be quite possible to have the diffuse texture and normal map on the same texture for each layer and sample from each side, but doing this would result in double the texture samples.

Quote: "I dont understand, how can I render all textures from terrain into one texture, It will be really nice, if you put code here, how to make that"


If you read my reply to BatVink you'll see I posted some code to create a plane and position it in-front of the camera, you can then just apply the terrain shader(texture blend one) to this plane, as well s the textures and it will render it as it would the terrain and you can save the render output to a texture via Set Camera To Image.

Also, MadrMan on IRC showed me some pics from Populus 3, and I have a new idea of how to make textures with what appear to be multiple levels of texture, while only using two, I'll see if I can implement this.

[Edit]

I've now written what I call Stepped Blending whereby I texture a terrain using a gradient map(bottom is water, then sand, grass, rocks and snow or anything), I then step this, i.e. I find the current texture by finding the closest step to the current height. I then find the step under this and transition between them using a StepMap texture which is like a detail map, but I also add to this map based on how far between each step I am, well it's quite hard to explain how it works but it looks quite cool, and uses minimal texture resources too.

Lucka
20
Years of Service
User Offline
Joined: 1st Oct 2004
Location:
Posted: 9th Jun 2008 20:30
A question for you:

I'm playng with TextureBlend.fx, learning how to write shaders..

How is possible to change the "lightposition" in an .fx like this, that doesn't have the tweakeble float4 LightPos ?

I mean..

If I want to move the "shadows" like the "sun" is somewhere else?

Hope my eng is "readable"..

Lucka - gawteam coder - www.gawgames.com
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 9th Jun 2008 20:45
None of these shaders have lighting/shadow calculations, I left it out because Advanced Terrains automatically generate the lighting and store it in the COLOR0 semantic of the FVF, this is faster because for such basic lighting on a static mesh like AdvT terrains they never change, normally. However it's still pretty easy to add in such basic lighting, you need to find two vectors, the normal of the vertex in world-space, and the light to vertex vector, assuming both are normalized you just then need to dot-product them and multiply the result with the output diffuse, this should give the same result as the current lighting, but would allow you to move the light-source around.

Lucka
20
Years of Service
User Offline
Joined: 1st Oct 2004
Location:
Posted: 10th Jun 2008 14:23
ok, it seems not so much out of mind, the problem is syntax and location (in one word "rules").

It's too much if I ask an example?

In wich part of the .fx I have to put the dot product?

It would be very useful to me, thanks in advance

Lucka - gawteam coder - www.gawgames.com
Lucka
20
Years of Service
User Offline
Joined: 1st Oct 2004
Location:
Posted: 10th Jun 2008 14:41 Edited at: 10th Jun 2008 14:43
e.g.

I already done this:



where LightInt is a costant float that I send to increase/decrease total illumination (range 0-100).

your suggestion is something like that?

Lucka - gawteam coder - www.gawgames.com
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 10th Jun 2008 15:25
No, you need to look at the OUT.Diffuse line in the vertex shader function, replace the '= IN.Diffuse' part with code to calculate the brightness, the brightness will be in a range of 0.0 to 1.0 the same as virtually everything in a shader, never use 0-100 for anything. I don't have time to write it now but try looking at other shaders people have written, it's generally quite simple to just have basic vertex/pixel lighting.

Lucka
20
Years of Service
User Offline
Joined: 1st Oct 2004
Location:
Posted: 11th Jun 2008 14:29
Thanks, it's always a good idea to follow rules (like range 0-1f). I done it like that just for a test, there was already a light value and that was the faster way.

Now I'll try to properly set the OUT.Diffuse, then I'll post it here.

Lucka - gawteam coder - www.gawgames.com
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 11th Jun 2008 15:41
I gave this a try earlier but couldn't seem to get the normals to do anything, so it's possible Advanced Terrains don't save the normals, in which case you'd need to recalculate them or use a different type of object that does.

Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 11th Jun 2008 18:49
Quote: "I gave this a try earlier but couldn't seem to get the normals to do anything, so it's possible Advanced Terrains don't save the normals"


It doesn't. I don't have DBPro here so I can't check the precise details, but IIRC Advanced Terrain just has XYZ, DIFFUSE, UV0 and UV1 vertex data. The lighting is pre-calculated and stored in the DIFFUSE component I suspect. I usually change the FVF to include the NORMAL component so I can get lighting shaders to work correctly with AT - but I think there are some irritating glitches with FVF formats which include DIFFUSE. One day I'll post a bug report ...

Quote: "never use 0-100 for anything"


Why not?

You are restricted to the range 0 to 1 for variables with the COLOR semantic (and probably DIFFUSE and SPECULAR as well ) but other variables, such as those with TEXCOORD0-7 can be almost anything in SM2 upwards. (There are limits to these variables but I've so far failed to find out what they are ...)

In SM1, TEXCOORD0-7 were restricted to the range 0 to 1 - but I doubt you need to use SM1 shaders.
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 11th Jun 2008 22:20
Quote: "Why not?"


Like you said, UV values aren't subject to any form of clampimg, if I were to have some constant such as 'float uvScale;' and if this scale were a percentage, i.e. 0-100, where 100 is no change, then in the shader I'd have to do a pointless *0.01 just so my UV values get scaled by the right amount, the loss here is quite large compared to what you gain. Of course there are _some_ things where you could use percentage scales above 0-1, but UV data or colours aren't them. So don't get me wrong, I'm not saying you should never use values over 1.0 but in the instance of a percentage, and this probably goes for all code, it isn't required, if you have a GUI output this can be beneficial as it's easier for the user to relate to 5%, 19% and not 0.013 or something, but such values can be scaled up when outputted and not stored this way, it's faster to use 0-1 scaled percentages as mentioned above, and in shaders speed is vital.

Cliff Mellangard 3DEGS
Developer
19
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 12th Jun 2008 00:42
thanks dark coder some very usefull stuff here.
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th Jun 2008 02:02
@Dark Coder

I agree with your comments about the unnecessary re-scalings required with percentages - but you said "never use 0-100 for anything". As I'm sure you realise, percentages are not the only things which can be in the range 0-100. You might, for example, have minimum fog at distance 0 and maximum fog at distance 100. You appeared to be making a general statement (which you weren't apparently).
Lucka
20
Years of Service
User Offline
Joined: 1st Oct 2004
Location:
Posted: 12th Jun 2008 11:47
ok, some steps more:

In the example we were talking about (textureblend) we'r using an object cloned from the AT.

I suppose (this evening I'll test) that after cloning the AT, we can simply cancel it.
I think we can use any kind of object (properly generated) instead of an AT.
So the problem of change then light direction for the Diffuse is not related to the Advanced terrain.. or not? (believe me, it's a question! )

What I understood till now is..

Recipe:
1) Find out a LightDir vector, something like:

float3 LightDir (1.0f, 0.5f, 0.8f);

2) A world view (projection?)

3) A dot product of the two to set the OUT.Diffuse..

..hmm.. It look easy, but it's not..
The result in my test is always a "disappearing" of the object, due to: - Syntax errors somewhere in may changements - Value out of range - I'm too Noob with .fx "language".

Still reading you (DK & GG), maybe one day..

Lucka - gawteam coder - www.gawgames.com
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 12th Jun 2008 16:50 Edited at: 12th Jun 2008 17:04
Assuming your object has normal data then this should be fine:



You can see I made changes from line 138. Just change the LightPos vector to reposition the light, it would be faster and maybe more beneficial to your needs to just pass a light direction rather than position, i.e. to make a directional light, as this is a point light without any attenuation calculation, but that's easy enough to change.

[edit] Removed the first normalization as it probably wasn't required.

Cliff Mellangard 3DEGS
Developer
19
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 12th Jun 2008 22:40 Edited at: 13th Jun 2008 19:03
hi dark coder could you maybe help me out here as iam trying to learn shaders but are yust to stupid to get the hang of converting fx files to dark basic pro.
as i yust bought an shaders book that use render monkey in its learning.
but how do i get the shaders in to dbp?
is there some state ments that dbp must have in an fx file?
could you please help me or any other shaders wizard out there to get this shader to work in dbp with an native plain and an loaded texture?
ppleeeaasseeeeee



Edited..........
sorry guys i found the problem as rendermonkey does put out messy fx files that dbp does not like at all.
first of all like the lightnes float group must be at the beginning.
before float4x4 matViewProjection : WorldViewProjection;
but now do i get the effect all over the screen so yust have to type and learn to get it to yust the object
but being an as stupid wanabe coder like me is not easy
as i dont know much about all the coding terms and make messy code.
cheers
Lucka
20
Years of Service
User Offline
Joined: 1st Oct 2004
Location:
Posted: 13th Jun 2008 00:45
@Dark coder

Thank you very much, but definitevly the cloned object from AT has no normals.. I'll try to find out another way to generate (maybe saving it, loading with an editor, then saving it again will allow me to manitain the "height map generation" method from AT)

When I'll know how to, I will post here..

Again Thanks DK

Lucka - gawteam coder - www.gawgames.com
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 13th Jun 2008 02:12
@Lucka

You can try converting the AT object's FVF format using the convert object FVF command so that it includes normals. You will then need to give it the correct normals - set object normals doesn't quite work because the AT object is split into limbs and the normals are not correctly calculated along the seams between limbs, but at least you should be able to test the shader.

The other thing you need to do is use the additional "don't recalculate tangents" flag when you are loading the shader, e.g. load effect "myShader.fx", 1, 0, 1 (don't ask me why you need to do this, ask Lee or Mike). This flag was introduced a few upgrades back and I have no idea why it had to be done in such an awkward way. It seems to be needed for objects which have DIFFUSE vertex data (such as AT objects).

I agree it would be nice to keep the terrain generation features of AT. Perhaps one day TGC will tidy up this part of the code.
Lucka
20
Years of Service
User Offline
Joined: 1st Oct 2004
Location:
Posted: 13th Jun 2008 13:00
@Green Gandalf

Really usefull suggestions, GG. Still tryng to find out a way to know ALL the flags/property of the commands we already use in DBPro..

It's the first time I heard about the "don't recalculate tangents" flag! (what a flag.. )

Now.. I'll follow your suggestions, then I'll generate a terrain with Game Space then (if I don't fall down on the ground cause my blood is completly sugarless) I'll post some screens..

Lucka - gawteam coder - www.gawgames.com
Lucka
20
Years of Service
User Offline
Joined: 1st Oct 2004
Location:
Posted: 13th Jun 2008 14:52 Edited at: 14th Jun 2008 00:21
Ok, actual situation:

I play with Convert object FVF, lot of ionteresting results!
but..

The new "textureblend.fx" from Dark Coder have this mods:



it doesn't works with FVF I tried out, to make a test a simply edit the last line to:



It means, in my intentions, calcute what you prefer, I'll simply use the IN.Diffuse value as the original .fx, right?

But in this way, the object disappear, making me thinking about some kind of syntax error somewhere.. If I add one of the first two line (just calculations) in a working .fx, the affected object disappears.

Any idea?

Lucka - gawteam coder - www.gawgames.com
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 13th Jun 2008 15:06
Because in the 2nd shader I posted I removed the Diffuse semantic from being passed to the vertex shader as it wasn't required, modify the original if you want to make changes like that as it still has it in.

Lucka
20
Years of Service
User Offline
Joined: 1st Oct 2004
Location:
Posted: 14th Jun 2008 00:25
I really apologize Dark, but (it's clear for everyone) I'm not natural born english.. And really your last sentence can make my head exploding!

Can you explain me in some other way?
In any case, thanks a lot for the attention!

Lucka - gawteam coder - www.gawgames.com
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 14th Jun 2008 09:17 Edited at: 14th Jun 2008 09:18


This is the struct I use for input to the vertex shader, this tells DBP which values for each vertex I wish to read from the current terrain object, the name on the left is just an identifier and can be anything you like, but the one on the right of ':' is the semantic, and this tells the application what you want, in this case the vertex position, UV stages 0 and 1, and the normal(surface direction used in lighting).

In the vertex shader declaration this struct gets passed into the IN variable, as seen here 'TextureBlend_Output VS_TextureBlend(TextureBlend_Input IN)', so now in the vertex shader I can access any one of these 4 passed values, or semantics by doing 'IN.Position ..., IN.UV0 = 5.0f; etc' Your modification uses IN.Diffuse, but there is no diffuse in this struct so you will get an error. To fix this add 'float 3 Diffuse : DIFFUSE;'[i] to this input struct. You will then be able to have [i]'OUT.Diffuse = IN.Diffuse'

Lucka
20
Years of Service
User Offline
Joined: 1st Oct 2004
Location:
Posted: 14th Jun 2008 17:42
Great! Thx for the explanation, Dark. I assure you, it's not so easy to chat about technical stuff in a different language!

About the point: what I tried to say was that the second version of TextureBlend you posted here was not working. I supposed that the problem was the "normals" infos not storerd in the object cloned from the A.T. one.
I started to play around with conversions, FVF and stuff like that.
But now I know that there's some other problem, and it's inside the .fx.


That's the version I'm chatting about:



And particulary this lines:



I suppose thess are the only differences from the original.. (and a declarations for LightDir as a Shader Costant.

The point is that I suppose something is wrong in this two lines:

cause if I add it in the working version of the .fx where OUT.Diffuse = IN.Diffuse, the object disappears..

I think (but probably it's my mistake) that if I put only calculations without using the results, the effect must work anyway.
If I only add the lines of the calculations in the working version without using the results in OUT.Diffuse, I expect that must work in the some way (just loose some cycle more to calculate)

It's right?

Now.. Adding it the effect stop working, I think in those two lines there's something missing/wrong..

I hope my explications was not clear.. But a lit readeble

Lucka - gawteam coder - www.gawgames.com
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 14th Jun 2008 18:52
Not sure I follow, the pixel shader function expects the Diffuse value, so you cannot just remove it and expect it to work, if you don't want diffuse then remove the 'float Diffuse : COLOR;' from the pixel shader input struct/vertex shader out. In addition to this you'd need to remove the usage of it in the pixel shader, on this line 'BaseMap.rgb *= IN.Diffuse'. Also it may help to output any shader errors which DBP can give you with the, 'Perform Checklist For Effect Errors' and 'Checklist String$()' etc so you can see what's going wrong.

Lucka
20
Years of Service
User Offline
Joined: 1st Oct 2004
Location:
Posted: 14th Jun 2008 19:44
ok.. I'll try again to explain: (really apologize, man)

The second version of the .fx doesn't work.
I try to find out the reason.

I saw there are some calculations:


The first line calculate the Normal.
The second line calculate the LightDir.
The third line use the dot product of the two to set the OUT.Diffuse.

In the first version the value of OUT.Diffuse was IN.Diffuse
OUT.Diffuse = IN.Diffuse;

now, OUT.Diffuse is the dot product.

Looking for the reason why the shader doesn't works, I try to set again (in the second version) the value of OUT.Diffuse like in the first version (= IN.Diffuse).
I imagine that (in this way) the calculation of Normal and LightDir will be simply ignorated.
But the shader doesn't work if it contain this two calculations.
That's the problem. I think in the two lines there must be something wrong/missing.

In another way:
If you use the first version, and the effect works, the object is visible and properly textured as you desire, then you add ONLY one of the calculation line (for example the line where you calculate the Normal), the effect stop working, the object become invisible.

What I think is: if you calculate something and you don't use nowhere the result, the effect (that before the calculation was running properly) must continue working without any changement on the final result..
But, it's not like that.

The third way to eplain will follow

Lucka - gawteam coder - www.gawgames.com
Lucka
20
Years of Service
User Offline
Joined: 1st Oct 2004
Location:
Posted: 14th Jun 2008 19:53 Edited at: 14th Jun 2008 19:54
Here I am..

This is the first (and working) version:





Use it somewhere, the use this instead:



This one, in the same prg, doesn't work (object become invisible), but it's exactly the same, except for the lines that calculate normal and lightdir.
Only the calculation, but the result is not used nowhere.

So.. the question is.. Why it's not working properly?
I imagine that some declaration is missing, or some error in the syntax, or.. I don't know

Hope now is clear, I done my best

Lucka - gawteam coder - www.gawgames.com
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 14th Jun 2008 20:04 Edited at: 14th Jun 2008 20:04
It doesn't work because the World matrix isn't defined, it's being used here 'mul( IN.Normal, World );' and the line after 'normalize( LightPos - mul( IN.Position, World ) );', to fix this just put 'matrix World : World;' at the very top of the shader, next to the WorldViewProjection line.

Lucka
20
Years of Service
User Offline
Joined: 1st Oct 2004
Location:
Posted: 14th Jun 2008 22:59
You great!

Lucka - gawteam coder - www.gawgames.com
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Jun 2008 12:23 Edited at: 15th Jun 2008 20:40
@Lucka

I'll try to look at that later today. (You might be in luck - it's raining so I'll be indoors. )

EDIT Oops! Looking at the wrong page . I see Dark Coder has already sorted you out. I'd better get back to my gardening ...

Login to post a reply

Server time is: 2025-08-08 15:34:36
Your offset time is: 2025-08-08 15:34:36