Horde3D

Next-Generation Graphics Engine
It is currently 28.10.2020, 13:07

All times are UTC + 1 hour




Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: 18.01.2009, 03:49 
Offline

Joined: 01.01.2009, 21:09
Posts: 54
Ok I figure out my mistake but would appreciate any clarification.

old question..
Quote:
After getting the shader extension to work I wanted to play with that stellar example on the wiki. I was able to get the code in place and made up a few detail jpg's but only unit one (dirt) shows. I did some tinkering and changing the vectors but all I get is the first unit no others. The log shows that the files are found ok and I can swap unit 1 and unit 3 and unit 3 shows. The wiki goes in to great detail but does not mention if any thing needs to be taken out, so I left the current train example in tack and just made the changes. Anyone get this to work, or know of a download?

One thing I saw was there is a FragmentShader and VertexShader for ATTRIBPASS,SHADOWMAP,LIGHTING, and AMBIENT, The wiki didnt see to saw which one needed the code changes. I just chose the one that seemed similar.


What I found was that I first choice the ATTRIBPASS for the changes, but then used the AMBIENT and that did the trick. I then relied I did need any but the AMBIENT. I'm hoping to strip this down as it is in dead very expensive on the CPU. I tried cutting down the texture sizes a bit, but still rather slow.


Any chance of getting this converted to the style used here. http://www.horde3d.org/wiki/index.php5? ... _Texturing

side question
Quote:
You'll also notice that the materials at some levels are different than those at higher or lower levels and that some materials don't show up on slopes over a certain degree
Would it be possible to do the same based on distance? I want the dirt textual up close and the rock texture far.

Also I seem to get a lot of stretching. I had my textures at 512x512 and tried 256x256 but didnt see a difference. My height map is 1024, is there a recommended size for textures? It does not seem to be one texture. It also seems as though the textures are being projected on the entire terrain, is that right? If so is there a way to control the repetition of the texture.


Attachments:
EX.JPG
EX.JPG [ 28.83 KiB | Viewed 19860 times ]
Top
 Profile  
Reply with quote  
PostPosted: 19.01.2009, 09:17 
Offline

Joined: 11.06.2008, 10:34
Posts: 119
Unfortunately I can't really help out (in the same boat when it comes to shaders), however the texture repetition for the shader on the wiki is controlled by * 200.0 I believe.

I never managed to get AcidFaucet shader working.

_________________

Let's bring 'em out! Any old iron! Any old iron!
A door opens and a homewife brings out a rather sophisticated-looking ground-to-air missile system, and dumps it on the cart.
Thank you.


Top
 Profile  
Reply with quote  
PostPosted: 19.01.2009, 12:41 
Offline

Joined: 06.12.2008, 08:32
Posts: 10
ulao wrote:
I'm hoping to strip this down as it is in dead very expensive on the CPU. I tried cutting down the texture sizes a bit, but still rather slow.

The speed issue in this is due to the 12 texture lookups in the fragment shader when using 4 textures. If you can get away with say 2 textures that would be a good thing ;)

ulao wrote:
Would it be possible to do the same based on distance? I want the dirt textual up close and the rock texture far.

You could do it based on any metric you want :) I would think, however, that doing it based on distance (I assume you mean distance from the camera) might look a bit weird since the ground type (dirt/rock) would change as the camera moves around.

ulao wrote:
Also I seem to get a lot of stretching. I had my textures at 512x512 and tried 256x256 but didnt see a difference. My height map is 1024, is there a recommended size for textures?

Well bigger textures generally look better :) For the record, the textures used in the screenshot on the wiki are all 512x512.

ulao wrote:
If so is there a way to control the repetition of the texture.


You can adjust the texture scale by multiplying by a different value in the texture2D() call (eg. texture2D(tex1, triTexCoords.xy*10.0))
Bigger number there will result in the texture repeating more often. You might consider adding another uniform to your material/shader that contains scaling amounts for each of you textures and use those in your call to texture2D (I probably should have done that in the first place.)


Top
 Profile  
Reply with quote  
PostPosted: 19.01.2009, 18:20 
Offline

Joined: 01.01.2009, 21:09
Posts: 54
Quote:
The speed issue in this is due to the 12 texture lookups in the fragment shader when using 4 textures. If you can get away with say 2 textures that would be a good thing
- Yeah figured, Ill manage.


Quote:
You could do it based on any metric you want :) I would think, however, that doing it based on distance (I assume you mean distance from the camera) might look a bit weird since the ground type (dirt/rock) would change as the camera moves around.
Yes I need the texture up close ( to the came) to be shown only with in a fix pixel range. And the other only in the distance. I would amuse the texture would not move this th camera so why would it look weird. As long as the texture near wont move or change ( say a 300 pixel radius) and the texture beyond would show another and only when its beyond that radios it should be ok no? Like Torque does and other engines. AKA detail/normal textures. I dont know shader lang well but If you pointed my in the right direction I could figure it out.

Quote:
Well bigger textures generally look better :) For the record, the textures used in the screenshot on the wiki are all 512x512.
- I'll try that

Quote:
You can adjust the texture scale by multiplying by a different value in the texture2D() call (eg. texture2D(tex1, triTexCoords.xy*10.0))
Bigger number there will result in the texture repeating more often. You might consider adding another uniform to your material/shader that contains scaling amounts for each of you textures and use those in your call to texture2D (I probably should have done that in the first place.)
Hmm I dont see why I would need to I could just do

Quote:
// grass
tempColor = tpweights.z * texture2D(tex2, triTexCoords.xy*5.0);
tempColor += tpweights.x * texture2D(tex2, triTexCoords.yz*5.0);
tempColor += tpweights.y * texture2D(tex2, triTexCoords.xz*5.0);
finalColor += weights.w * tempColor;

// dirt
tempColor = tpweights.z * texture2D(tex1, triTexCoords.xy*200.0);
tempColor += tpweights.x * texture2D(tex1, triTexCoords.yz*200.0);
tempColor += tpweights.y * texture2D(tex1, triTexCoords.xz*200.0);
finalColor += weights.y * tempColor;

// rock // found 4 ( divisible by height map ) stops some of the stretching.
tempColor = tpweights.z * texture2D(tex3, triTexCoords.xy*4.0);
tempColor += tpweights.x * texture2D(tex3, triTexCoords.yz*4.0);
tempColor += tpweights.y * texture2D(tex3, triTexCoords.xz*4.0);
finalColor += weights.x * tempColor;

and that sets the scale for each no? What am I missing here?

Thx for helping out on this, and PuG I here ya I wrong a bump map shader once. and when I was done although it worked well I didnt understand much of it. I may finally try to understand it a bit.

Brain storming..
Code:
                         if (cam is far)
                        { //detailed texture
            tempColor = tpweights.z * texture2D(tex1, triTexCoords.xy*200.0);
            tempColor += tpweights.x * texture2D(tex1, triTexCoords.yz*200.0);
            tempColor += tpweights.y * texture2D(tex1, triTexCoords.xz*200.0);
            finalColor += weights.y * tempColor;                               
                        }
            
                         if (cam is near)
                        {// basic texture
            tempColor = tpweights.z * texture2D(tex3, triTexCoords.xy*4.0);
            tempColor += tpweights.x * texture2D(tex3, triTexCoords.yz*4.0);
            tempColor += tpweights.y * texture2D(tex3, triTexCoords.xz*4.0);
            finalColor += weights.x * tempColor;
                       }
I would just need to know how to get the cam distance.If I could just not render that texture it would speed things up but I dont really know where to even begin with shaders. I would needs at least a way to trace some data to figure this out. I think I can get the cam position with

myCam cam_pos;
or use cam_pos[x]

cam_pos[ x(1) y(2) or z(3) ]. I'm not sure if its 0 based or not. I also saw a referenced for cam_pos[4] not sure what that is. I think I only need x and y. I'm not sure how the 2d to 3d translation will work.


Here is the concept I'm after.
http://www.ogre3d.org/forums/viewtopic. ... 6f4e2718c6


Top
 Profile  
Reply with quote  
PostPosted: 20.01.2009, 07:56 
Offline

Joined: 06.12.2008, 08:32
Posts: 10
To get the distance you could just add a new 'varying float distance;' to the shader then set it in the vertex shader with 'distance = length(calcViewPos(pos));' then use it in the fragment shader however you want.

Depending on your terrain, you might even want to try removing the triplanar texturing as well (then you texture coordinates would be just the xy plane.) If the terrain doesn't have any terribly steep spots and/or will never be viewed close up you might still get acceptable results (along with a huge performance increase.)

As for the way to set the scale amount for the textures, putting the scale values directly in the shader like that is perfectly fine. I just figured having a single uniform that holds the scale values for all the textures is easier since it only leave a single place the values need to be changed if you should need to change them at some point. But I'm just lazy like that :)

Also, if you want a good book on GLSL I would suggest OpenGL Shading Language (2nd edition)


Top
 Profile  
Reply with quote  
PostPosted: 20.01.2009, 19:11 
Offline

Joined: 01.01.2009, 21:09
Posts: 54
Ok that is working but I dont think I got the right section. I can tell where the actule displaying of textures is. If the shader has to redraw the texture every time the scene moves where is that done? What i have below seems the kill the lights, but that makes scene to me.

Oh do you have another reference, possibly an online reference ? I appreciate the book but like online tools a bit better. At lease for thing I wont need to often.
Code:
            // grass
            if ( distance > 100)
            {
            tempColor = tpweights.z * texture2D(tex2, triTexCoords.xy*5.0);
            tempColor += tpweights.x * texture2D(tex2, triTexCoords.yz*5.0);
            tempColor += tpweights.y * texture2D(tex2, triTexCoords.xz*5.0);
            finalColor += weights.w * tempColor;
            }
            
            // dirt
            if ( distance < 100)
            {
            tempColor = tpweights.z * texture2D(tex1, triTexCoords.xy*200.0);
            tempColor += tpweights.x * texture2D(tex1, triTexCoords.yz*200.0);
            tempColor += tpweights.y * texture2D(tex1, triTexCoords.xz*200.0);
            finalColor += weights.y * tempColor;
            }
            // rock
            if ( distance > 100)
            {
            tempColor = tpweights.z * texture2D(tex3, triTexCoords.xy*4.0);
            tempColor += tpweights.x * texture2D(tex3, triTexCoords.yz*4.0);
            tempColor += tpweights.y * texture2D(tex3, triTexCoords.xz*4.0);
            finalColor += weights.x * tempColor;
            }
            gl_FragColor = finalColor * l;


Oh small little thing that I cant fix, no related to the shader but the height map? See picture above. what creates that river like thing? I have a new height map, and killed the fine detail. but left the normal map and alpha.
when you say triple I'm thinking you just meant the third texture ( aka grass ) and nothing to fancy then? I like the grass and would hate to lose it. But I could combine my detail texture with my normal and use the grass for the transition. .. I think. I would still need 3 separate textures though..

? is there a way to get the texture transparency working? I want my grass not to be a square and only show the pixels that have date not the undrawn areas. I tried png, tga, and jpgs... Blank spaces are always white? Is there a special hot color?


Last edited by ulao on 21.01.2009, 02:08, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: 20.01.2009, 20:25 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
ulao wrote:
Oh do you have another reference, possibly an online reference ? I appreciate the book but like online tools a bit better. At lease for thing I wont need to often.

http://www.lighthouse3d.com/opengl/glsl/ is a quite good introduction to GLSL. You can skip the first part which handles the OpenGL side since that is entirely handled by Horde and start with the Shader Examples.


Top
 Profile  
Reply with quote  
PostPosted: 21.01.2009, 00:59 
Offline

Joined: 01.01.2009, 21:09
Posts: 54
thx marciano that may help a bit.


BTW PuG, I got Dot Product Detail Texturing working by adding

<InsCode code="utilityLib/fragLighting.glsl" /> in the fragment shader. ;) At lease it compiles that is.


Last edited by ulao on 21.01.2009, 21:24, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: 21.01.2009, 10:17 
Offline

Joined: 06.12.2008, 08:32
Posts: 10
I think instead of doing 'if(distance > 100) { do texture lookup }' you should create a set of weights (1 for each texture) based on the distance in the same way that they're created for height and slope. This way instead of having a hard edge at the transition between using a texture and not using it, it'll give a smooth fall off. I realize you're doing this to eliminate some texture lookups but I think the only way to smoothly blend between multiple textures requires sampling them then combining them with the weights (if anyone has any other ideas on that feel free to speak up... I'm by no means a shader master ;).) I assume this is what you meant when you said you don't want your grass to be square. Just remember that these weights would need to sum to 1 just as they do for the height and slope weights (weights *= 1.0 / (weights.x+weights.y+weights.z+weights.w); achieves this.)

As for the odd colors showing up on you terrain, I'm unfortunately at a complete loss for an explanation on that.


Top
 Profile  
Reply with quote  
PostPosted: 21.01.2009, 10:19 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1149
Location: Germany
Concerning shader development you may also want to take a look into the Editor tutorial video. From position 8:00 it may become interesting for shader developers, showing how to use the editor for quick shader development (unfortunately the embedded flash player is a bit confusing when trying to jump to a specific position in the video).


Top
 Profile  
Reply with quote  
PostPosted: 21.01.2009, 16:32 
Offline

Joined: 01.01.2009, 21:09
Posts: 54
Quote:
I think instead of doing 'if(distance > 100) { do texture lookup }' you should create a set of weights (1 for each texture) based on the distance in the same way that they're created for height and slope. This way instead of having a hard edge at the transition between using a texture and not using it, it'll give a smooth fall off. I realize you're doing this to eliminate some texture lookups but I think the only way to smoothly blend between multiple textures requires sampling them then combining them with the weights (if anyone has any other ideas on that feel free to speak up... I'm by no means a shader master ;).) I assume this is what you meant when you said you don't want your grass to be square. Just remember that these weights would need to sum to 1 just as they do for the height and slope weights (weights *= 1.0 / (weights.x+weights.y+weights.z+weights.w); achieves this.)
- I agree completely. And to be honest I'm finding the AcidFaucet example to be a bit easier to follow since I dont really need angles in my shader. And I'm still learning how this beast works. If I could use the weights I would definitely do that, but I'm lost in that code. I think his code uses weights and if the angle stuff was out I may have a better chance. Every time I strip it down I break it.


Quote:
As for the odd colors showing up on you terrain, I'm unfortunately at a complete loss for an explanation on that.
- Making the assumption you mean the purple and not the stretching, and still amusing you not kidding with me, it is meant to be purple ( Crateria shhhhh) ;)

Quote:
Concerning shader development you may also want to take a look into the Editor tutorial video. From position 8:00 it may become interesting for shader developers, showing how to use the editor for quick shader development (unfortunately the embedded flash player is a bit confusing when trying to jump to a specific position in the video).
This may help thx!

Diverting for a moment and looking at AcidFaucet 's example..

I think this section

Code:
               // Wrap lighting fur sun
               float l = max( dot( normal, light ), 0.0 ) * 0.5 + 0.5;
               gl_FragColor = vec4( colMap  * l, 1.0 );
               //gl_FragColor.rgb =
               //calcPhongSpotLight( pos.xyz, normalize( normal ), colMap, 0.0, 16.0, -vsPos.z, 0.3 );
            }


is where I fail.. The "// Wrap lighting fur sun" is from the terrain shader and AcidFaucet didnt use sundir. Seem that calcPhongSpotLight renders black. I'm guessing its because I'm not using the wrap sun and maybe getting no lights.

I tried

gl_FragColor.rgb = calcPhongSpotLight( pos.xyz, normalize( normal ), colMap * l, 0.0, 16.0, -vsPos.z, 0.3 );

I also added "vsPos = calcViewPos( pos );" above as vsPos was doing nothing.. but still black.


Top
 Profile  
Reply with quote  
PostPosted: 22.01.2009, 11:38 
Offline

Joined: 06.12.2008, 08:32
Posts: 10
Ahh sorry, when you said "river like thing" in your previous post I assumed you meant the purple/blue parts... my bad :oops: In this case I'm not sure what "river like thing" you're talking about.

Maybe try a quick test using the terrain that comes with the extension sample. If the problem persists then it's probably something in the shader, if the problem is gone it's probably something with your heightmap.


Top
 Profile  
Reply with quote  
PostPosted: 22.01.2009, 16:23 
Offline

Joined: 01.01.2009, 21:09
Posts: 54
Quote:
Ahh sorry, when you said "river like thing" in your previous post I assumed you meant the purple/blue parts... my bad :oops: In this case I'm not sure what "river like thing" you're talking about.
- Oh, it turned out to by the normal map, all fixed ;)


Ok so I got it working.. I had to use the "LIGHT" Pass the ambient was not working. And I had to turn on the NodeHandle light that is off in the terrain example.


Some understand please? The AMBIENT, LIGHT, SHADOWMAP, and ATTRIBPASS passes. What are they for, just passes for the shader? Do they always apply?

So far all my textures are blending but they are very very strong, and I can find the right setting to dim them down a bit. Also I cant determine how to control the bled amounts?

Here is what I have so far, you will see the terrain is transparent, and I have no idea why. That bar is part of the terrain mesh I have seen before by going under the terrain.


Attachments:
shot.JPG
shot.JPG [ 88.76 KiB | Viewed 19537 times ]
Top
 Profile  
Reply with quote  
PostPosted: 23.01.2009, 20:33 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
ulao wrote:
Some understand please? The AMBIENT, LIGHT, SHADOWMAP, and ATTRIBPASS passes. What are they for, just passes for the shader? Do they always apply?

The contexts are referenced in the pipeline (resource). The light nodes also have context properties, so that they know which shader they should use for lighting and shadow map rendering.


Top
 Profile  
Reply with quote  
PostPosted: 25.01.2009, 11:27 
Offline

Joined: 06.12.2008, 08:32
Posts: 10
You calculate weights with the computeWeight() function. You would call computeWeight(x, minVal, maxVal) to get a weight based on x (this is height and slope in the shader.) You need a weight for each texture you plan on using. Then you need to make sure that the sum of all the weights is equal to 1. This is done in the shader with the line weights *= 1.0 / (weights.x + weights.y + weights.z + weights.w);

So for example, if you wanted to calculate weights for 2 textures based on just the height you would do something like:

Code:
vec2 weights = vec2(0.0, 0.0);

weights.x = computeWeight(height, 0, 100);
weights.y = computeWeight(height, 100, 200);
weights *= 1.0 / (weights.x + weights.y); // make sure weights sum to 1

vec4 color = weights.x * texture2D(tex1, texcoords);
color += weights.y * texture2D(tex2, texcoords);


Now color is a blend of tex1 and tex2 with tex1 showing at heights between 0 and 100 units and tex2 at heights 100 to 200.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group