WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 09-05-2006, 06:36 PM
k_iwan k_iwan is offline
Member
 
Join Date: May 2006
Posts: 115
Smile Multi-Texturing...

Hi,

Is it possible to do multi texturing in Vizard, not as in blend-mode, but as overlay?
I have attached 2 sites which captures exactly what I have in mind.

Multi Texturing in openGL;
http://www.kraftwrk.com/multi_texturing.htm
http://www.cs.auckland.ac.nz/~jvan00.../multitex.html

I hope that I posted this in the right forum.

Kind Regards,
Iwan
Reply With Quote
  #2  
Old 09-06-2006, 09:42 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

I'm not sure what you mean by "overlay". The examples you pointed to apply multiple textures to a mesh and blend them together. This technique is possible within Vizard. To apply multitple textures on a node just do the following:
Code:
node.texture(tex1,'',0) #Apply to texture unit 0 (default)
node.texture(tex2,'',1) #Apply to texture unit 1
In the examples they use different texture coordinates per unit. You either need to set these in your modelling program and make sure they are exported, or you can use a texture matrix to change the coordinates of a unit. In the examples you gave, they simply have the detailed textures repeat over the surface, so create a texture matrix that scales the texture coordinates:
Code:
m = viz.Transform.scale(20,20,1)
node.texmat(m,'',1) #Scale texture coordinates of unit 1 (detail texture)
For this to work you need to make sure that your detail texture is in repeat mode:
Code:
tex.wrap(viz.WRAP_S,viz.REPEAT)
tex.wrap(viz.WRAP_T,viz.REPEAT)
To blend the textures you can use the following example:
Code:
node.texblend(0.5,'',1) #Blend texture 1 50% with texture 0
I believe this is similar to what the first example does. The second example is a little more tricky. It would be easier to implement in a shader. If you don't have a card that supports shaders then I could create a simple plugin that implements that behaviour.

Hope this helps.
Reply With Quote
  #3  
Old 09-06-2006, 05:40 PM
k_iwan k_iwan is offline
Member
 
Join Date: May 2006
Posts: 115
Unhappy tiling doesn't work?!? could be a mistake from my end

Hi,

Firstly, thanks for the reply. In order to attempt this blend-multi texture, I created a model out of Candor Canyon on mars, and I textured it.

The blending does work, but the repeating texture does not. for the detail texture I used a 64 x 64 image. I was hoping this small texture would repeat itself over large terrain.

There are 2 screenshot attached;
no_detail.jpg - plain texture.. no additional texture applied
not_tiled.jpg - I could see here that my 64 x 64 texture is fully streched across the terrain.

the terrain has only 1 UV map applied to it.

I attached my script, I couldn't figure out what did I do wrong??? could you have aa look and see why I couldn't repeat my small texture across the terrain?

#---------------------------------------------------------------------
import viz

viz.go()

viz.enable(viz.CULL_FACE)
viz.enable(viz.CULLING)

#loading textures
tex1 = viz.add('texModified.jpg')
tex2 = viz.add('detail.jpg')
tex2.wrap(viz.WRAP_S,viz.REPEAT)
tex2.wrap(viz.WRAP_T,viz.REPEAT)

#loading the objects
stage = viz.add('output.osg')
stage.enable(viz.CULL_FACE)
stage.enable(viz.CULLING)

stage.texture(tex1,'',0) #Apply to texture unit 0 (default)
stage.texture(tex2,'',1) #Apply to texture unit 1
stage.texblend(0.8,'',1) #Blend texture 1 50% with texture 0

#loading the skybox
env = viz.add(viz.ENVIRONMENT_MAP,'mars_sky\mars_sky.jpg ')
sky = viz.add('skydome.dlc')
sky.texture(env)
#---------------------------------------------------------------------

Thanks for your help! Have a great day.

Regards,
Iwan
Attached Thumbnails
Click image for larger version

Name:	no_detail.jpg
Views:	1165
Size:	63.9 KB
ID:	108   Click image for larger version

Name:	notTiled.jpg
Views:	1212
Size:	41.6 KB
ID:	109  
Reply With Quote
  #4  
Old 09-06-2006, 05:44 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

The texture coordinates were probably not exported for the second texture unit. Try setting the texture matrix like I mentioned in my previous post.
Code:
m = viz.Transform.scale(20,20,1) #Repeat 20 times in both directions
stage.texmat(m,'',1)
Let me know if this works.
Reply With Quote
  #5  
Old 09-06-2006, 05:48 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

I just double checked to make sure this works and was able to create this sample script.
Code:
import viz
viz.go()

#Create quad and place it in front of user
quad = viz.add(viz.TEXQUAD,pos = (0,1.8,3))

#Add main texture
tex1 = viz.add('ball.jpg')

#Add detail texture in repeat mode
tex2 = viz.add('gb_noise.jpg',wrap=viz.REPEAT)

#Apply textures to quad
quad.texture(tex1)
quad.texture(tex2,unit=1)

#Blend textures 50%
quad.texblend(0.5,unit=1)

#Repeat detail texture 20 times
quad.texmat(viz.Transform.scale(20,20,1),unit=1)
Reply With Quote
  #6  
Old 09-06-2006, 07:14 PM
k_iwan k_iwan is offline
Member
 
Join Date: May 2006
Posts: 115
Talking VR Mars exploration has just started on Vizard!!!

Hi,

Thank you for your speedy response. It didn't work initially because I missed 2 lines!!! Thanks for pointing this one out to me.

Please look at the screenshots attached, the detail looks great. Detail texture may look bit repetitive for now, but it will change soon!

I attached my script with some changes in it, I had to bring the blend value to 0.065 to get the result that I wanted.

#-----------------------------------------------------
viz.go()

#loading textures
tex1 = viz.add('texModified.jpg')
tex2 = viz.add('detail.jpg')
tex2.wrap(viz.WRAP_S,viz.REPEAT)
tex2.wrap(viz.WRAP_T,viz.REPEAT)

#loading the objects
stage = viz.add('output.osg')
stage.enable(viz.CULL_FACE)
stage.enable(viz.CULLING)

stage.texture(tex1,'',0) #Apply to texture unit 0 (default)
stage.texture(tex2,'',1) #Apply to texture unit 1

stage.texblend(0.065,'',1) #Blend texture 1 0.065% with texture 0
m = viz.Transform.scale(5000,5000,1) #Repeat 5000 times in both directions
stage.texmat(m,'',1)


#loading the skybox
env = viz.add(viz.ENVIRONMENT_MAP,'mars_sky\mars_sky.jpg ')
sky = viz.add('skydome.dlc')
sky.texture(env)

#disabling head-light
viz.disable(viz.LIGHT0)
#-------------------------------------------------------------------

Thank you for your assistance! have a great day.

Regards,

Iwan
Attached Thumbnails
Click image for larger version

Name:	shot1.jpg
Views:	1191
Size:	69.5 KB
ID:	112   Click image for larger version

Name:	shot2.jpg
Views:	1173
Size:	52.0 KB
ID:	113  
Reply With Quote
  #7  
Old 09-06-2006, 07:29 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

Looks good. I just realized that the texblend operation is not the same as the blending in the example website you posted. I've attached another example that uses a shader to perform the correct blending. This example assumes the detail texture is gray scale. Let me know if this is better.
Attached Files
File Type: zip DetailTextureExample.zip (901 Bytes, 1129 views)
Reply With Quote
  #8  
Old 09-06-2006, 08:03 PM
k_iwan k_iwan is offline
Member
 
Join Date: May 2006
Posts: 115
Error compiling ... ?

Hi,

I tried this just now and I get this error everytime I run it. The Blending looks okay though. I'll play around with it more. I have CG toolkit 1.4.1 installed.

-----------------------------------
FRAGMENT glCompileShader "" FAILED
FRAGMENT Shader "" infolog:
ERROR: 0:6: 'texture2D' : no matching overloaded function found
ERROR: 0:6: '=' : cannot convert from 'const float' to '4-component vector of float'
ERROR: 0:7: 'texture2D' : no matching overloaded function found
ERROR: 0:7: 'assign' : cannot convert from 'float' to 'FragColor 4-component vector of float'
ERROR: 4 compilation errors. No code generated.
glLinkProgram "" FAILED
Program "" infolog:
Link failed. All shader objects have not been successfully compiled.

-------------------------
Reply With Quote
  #9  
Old 09-06-2006, 08:09 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

Sorry about that. Replace the the code in the shader file with the following:
Code:
uniform sampler2D BaseTexture;
uniform sampler2D DetailTexture;

void main (void)
{
	vec4 detailColor = texture2D(DetailTexture, gl_TexCoord[1].xy);
	gl_FragColor  = (texture2D(BaseTexture, gl_TexCoord[0].xy) * detailColor.r) * 2.0;
}
Reply With Quote
  #10  
Old 09-06-2006, 08:59 PM
k_iwan k_iwan is offline
Member
 
Join Date: May 2006
Posts: 115
Talking Excellent!!!!!! Thank you!

Hi,

It works! Have a look at the screenshots attached. The fog is completely gone?!? and the terrain is somehow very-brightly lit!! (perhaps this is caused by uniform intensity command?)In which actually looks nice, I could turn down the spot light color a bit to get the brownish feeling on the planet.

I like the result! heaps better than normal blending. Thank you!

From high elevation the terrain looks bit funny with tiled detail texture (oh well). From right above the ground... the terrain looks amazing!! What do you think?

Regards,
Iwan
Attached Thumbnails
Click image for larger version

Name:	withShader1.jpg
Views:	1168
Size:	116.4 KB
ID:	115   Click image for larger version

Name:	withShader2.jpg
Views:	1156
Size:	103.8 KB
ID:	116  
Reply With Quote
  #11  
Old 09-07-2006, 11:01 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

I agree, the close-up shot looks really cool! But the tiling is noticeable from far away. The second example you posted would fix the tiling problem, but it might be harder to create the textures for it.

The fog is gone because you are using a shader. You will have to implement the fog in the shader. Let me know if you need help with this.

The terrain is bright because of the scale applied. In the shader try changing the scale parameter from 2.0 to 1.0. If you end up doing this, then you don't even need the shader anymore, plus the fog will work again.

Either way, I just added the ability to set all the texture combine properties from within Vizard. This should be available in the next release.
Reply With Quote
  #12  
Old 09-07-2006, 07:07 PM
k_iwan k_iwan is offline
Member
 
Join Date: May 2006
Posts: 115
Red face Fog......

Hi,

I would definitely need your expertise in this matter, since you solved the shader problem within a couple of minutes while it would probably take me 2 months alone on it.

Fog shader would be great, what about fractal animated layered fogs? would this be too much asking for next release???

...perhaps something like;
fog1 = viz.add(viz.fogshader, 'someFractalImage.png') #finite fog shader
fog1.size(10,1,10) #fog plane 100 unit square
fog1.transform(0,2,0) #putting the fog plane 2 unit up
fog1.animate(1,0,0, 4) #animating the fog 4 unit/sec in x direction
fog1.intensity(1.5)
fog1.amplitude(1.5) # strength of someFractalImageImage.png
fog1.color(0.92, 0.92, 0.98) #blue-ish color

hmmm... somehow this ideas might go futher to fractal animated cloud plane

I wish you guys all the best in improving vizard.

*edited* for incorrect grammar :P


Regards,
Iwan
Reply With Quote
  #13  
Old 09-08-2006, 09:54 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Here is a version of the shader that implements exponential fog:
Code:
uniform sampler2D BaseTexture;
uniform sampler2D DetailTexture;

const float LOG2E = 1.442695;

void main (void)
{
       float fog = exp2(gl_Fog.density * gl_FogFragCoord * LOG2E);
       fog = clamp(fog, 0.0, 1.0);
       vec4 textureColor = (texture2D(BaseTexture, gl_TexCoord[0].xy) *
texture2D(DetailTexture, gl_TexCoord[1].xy).r) * 2.0;
       gl_FragColor = vec4(mix( vec3(gl_Fog.color), vec3(textureColor),
fog), textureColor.a);
}
Did you try not applying the shader at all to fix the brightness problem?

Do you have any links explaining fractal animated layered fog, a quick google search didn't find anything.

The following page has an example that creates a moving cloud plane. I'm not sure if this is what you are looking for, but it might be useful.
http://www.worldviz.com/forum/showthread.php?t=549
Reply With Quote
  #14  
Old 09-09-2006, 06:17 PM
k_iwan k_iwan is offline
Member
 
Join Date: May 2006
Posts: 115
Hi,

I will give it a try. I didn't modify the shader to remove the brightness effects because I happen to like it. But, for the openday we used blend option as I didn't have enough time to fix the texture tiling problem.

I'll give this one a try.

I gave the could plane a try some months ago, it looked great but doesn't suit with my mars. I was looking for more... glommy cloud to give distress feeling.

I got this idea of animated layered fog from www.garagegames.com forum, as I happen to be an owner of Torque SDK.
Here's the link of fractal animated cloud, which I believe also suitable for low laying animated fog.

http://www.garagegames.com/index.php...=view&qid=3525

you do not need to create account to view this link, this resource is public.

Thank you for help, can't wait to see what you guys will have on the actual final release

Regards,
Iwan
Reply With Quote
  #15  
Old 09-09-2006, 09:01 PM
k_iwan k_iwan is offline
Member
 
Join Date: May 2006
Posts: 115
Talking Excellent!!! Thank you!!!!!

@ Farshizzo;

In order to reduce the intensity of texture on terrain, I decreased the brightness of the detail texture, without modifying the shader at all.

Also, a "proper" seamless texture for detail, decreases the ugly looking tiles on terrain greatly.

The fog definitely gives more depth to the scene. I attached the latest screenshots of your shader implementation The scene looks really nice!

Regards,
Iwan
Attached Thumbnails
Click image for larger version

Name:	shader_detail_fog1.jpg
Views:	1164
Size:	87.0 KB
ID:	119   Click image for larger version

Name:	shader_detail_fog2.jpg
Views:	1156
Size:	135.3 KB
ID:	120  
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 04:31 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC