How can I paint multi terrain textures like this screenshot?
gamekill
16-05-2007 09:29:32
Hi!
I have a terrain in 3DS Max 9, and I vertex painted it with different Red, Green and Blue colors. Red vertices where dirt should be, green vertices where grass should be, and blue vertices where a darker dirt should be (where its supposed to be underwater). There are some vertices wich are blended, so that the textures have a smooth transition.
I then used a 3dsmax Composite material (3 materials) and set each of the materials inside it to an opacity correspondent to a vertex color (Red, Green and Blue channels respectively).
The result is nice enough for what I need, but only works for max rendering.
How can I get this done with an oFusion Material? I read through the manual but I still can't see any way to do this.
This is what it looks like in 3DS Max (with render window):
Please help, thanks for reading!
Lioric
16-05-2007 17:14:30
The materials used by interactive engines are different (internally), composite material is not supported for performance reasons
You can create the same effect using the oFusion material, probably with the blend mode set to "blend diffuse color" in the texture units or with the manual color setting (all this in the blend section)
Or you can use a pixel shader, add your texture units (the terrain textures) to the pass, and create a pixel shader that samples each texture based on the vertex color (i.e. if pixelColor == green then sample grass texture), this is very easy
Or if you want an advanced blending between your textures (using alpha map) then search for "texture splating"
I can provide a sample scene if you need
gamekill
16-05-2007 23:46:28
Ok,
I will try to set blend mode to "blend diffuse color" or the manual method (if I can figure it out well enough).
The pixel shader sound like a good idea, I will talk to the coder about this. Not sure if he already knows how to make custom shaders (only place we are using shaders for now is normal mapping, and I followed your tutorial for that -- by the way, it looks great on ofusion viewport but the exported mesh has lighting issues, random faces constantly toggling between normal mapped and fully lit). But I am afraid the pixel shader solution won't work for lower end video cards?
I will look into splatting, but I guess it is for smaller portions and not big terrain extensions... I think
Oh and any and all sample scenes you might provide would be really great, because we are a very small team (only 3 people) trying to make a big project come true (an action adventure)!!!
Do you need my email for this?
gamekill
18-05-2007 22:38:43
Hi...
I could not get it to work with blend diffuse color, in the texture units. I am not sure I tried the right way, because I'm not familiar with howw ofusion materials work in max, but I couldn't get it to work.
The shader solution will have to wait unfortunately, because there's a lot of other stuff on the way. And I cannot ise alpha map. I need to blend textures in really big environments and the alpha map would have to be huge...
So I really need to use the vertex color information.
I guess either oFusion is not exporting vertex color (and vertex alpha) information correctly, or the Eihort Ogre3D does not work with this solution anymore:
http://www.ogre3d.org/phpBB2/viewtopic. ... highlight=
Will keep trying, but if you have any ideas, it would be great help!
Thanks!
Lioric
19-05-2007 01:11:06
I have made some tests and vertex color is correctly exported
A sample shader based vertex texture blend scene has been created, it will be uploaded to the Scenes section in the next days
This sample scene uses a vertex and a pixel shader to blend between textures based on the red (terrain), green (mud) and blue (grass) values of each vertex
Click for larger image
Probably for your case its better to use shaders and not the fixed function materials, as with fixed funtion (set scene and texture blend modes) you will need to define the alpha value for the specific vertices where a texture will be and the rgb value of the vertices for the other texture (and you will need to manually define the where a texture will blend with the other, using alpha and rgb for the vertices)
If you use a shader, this will be automatically handled similar to using the Composite material
The shader for this probably will work on any video hardware supporting vs/ps 1 (any video hardware in the last 5 years)
gamekill
19-05-2007 05:13:11
ultramedia
21-05-2007 10:16:29
Woah! I'd be pretty excited about getting my hands on that example file too. I've been trying to sort out blending with alpha stuff, but if this is easier, I'd be more than happy to do geometry chopping and vertex colors instead...
That would be a great addition to the shader collection that was suggested a few months ago. Look forward to seeing the terrain shader too
Lioric
23-05-2007 02:09:46
The sample scene has been posted in the Scenes section, with a video with details on a sample usage of the shader for terrain painting and texturing
Click for the VertexTextureBlend video
gamekill
23-05-2007 06:34:42
gamekill
23-05-2007 09:07:30
I just want to point out that the files are named wrong in the vertextextureBlend3.zip, and when they are put into the ofusion/media/shaders folder, they cause an application error in 3DS Max whenever you try to activate oFusion viewport on any .max file.
The .source files are named
vertexTextureBlend3_ps.source and
vertexTextureBlend3_vs.source but if you look inside the .program file (vertexTextureBlend3.program) they are supposed to be named something else (terrainBlend_ps.source and terrainBlend_vs.source).
So you need to either rename the two .source files accordingly, or edit the .program and make it point to the right .source files.
Anyway, I just finished my first test!!!
Thanks again Lioric/oFusion team!!!!!!!!!!!!!!!!!
Night Elf
31-05-2007 15:21:57
Hi! I'm using the technique described here, but I'm having a little problem: it works OK, but I also get the vertex colouring... It works fine inside oFustion, but not inside my game. Any suggestions?
Lioric
31-05-2007 22:02:40
Is the material in your application using the vertex shader?
See the ogre.log file from your application to see if the vertex shader is correctly loaded
Are you using another pass on the same material?
The shaders dont use the vertex color to colorize the pixels, its probably because you are using fixed function at some point during the rendering of your object
syedhs
21-06-2007 07:12:56
Hi,
Sorry to revive this thread, anyone can figure out the modifications needed for lightmapped scene? I think I cant use the usual fixed-function material, as the scene is rendered using shader, am I right?
Anyone can provide some insight? Thanks.
I was wondering the same thing, I managed to do a similar shader in ShaderFX with normal mapped terrain textures and a lightmap, but havent a clue how to convert it in code
.
I tried to copy and paste just the lightmap data from the shaderFX source to the ofusion terrain shader, the ofusion shader is CG though, whilst the shader I made is HLSL and DX only.
I can paste the source to my shader if anyone wants to take a stab at converting it themselves?
Lioric
22-06-2007 00:28:01
You can use any method that suit your needs:
Add a pass after the vertexTexture shader pass with the lm texture and the proper blend modes, it can be fixed fuction. Each pass is a layer that is painted to the buffer (what is alter displayed in your screen) and can add or use the colors in the buffer to produce the result you want. This method is multipass
A faster method is using a single pass, for this, you can add the lightmap sampler to the shader (a few lines) and modulate with the textures
I will upload an updated sample scene with lm support in the shader
For this sample scene, a bool swithc has been added as parameter to enable the lm usage, and the intensity parameter to control the light and shadows intensity
Click for bigger image
syedhs
22-06-2007 05:53:59
Ooo nice!
. I am pretty new to shader and I can always learn from sample scene.
syedhs
22-06-2007 13:08:34
Lioric,
Why is it I cant get the shader to export? I exported it using Ofusion Pro, and have checked Shader Export in the export dialog. The material of terrain export here only contain 3 texture unit but no vertex/fragment shader. I know I can add it manually but it defeats the purpose of shader automatic export
It is quite strange as the terrain techniques here have been successfully performed as Ofusion viewport it looks nice and as expected.
strange, I exported the example scene with RGB vertex colour blending from ofusion and it loaded and displayed just fine in FlowED. I havent checked for the new lightmap version though.
Lioric
22-06-2007 16:01:51
To export shader parameters you need to have the preview viewport enabled
syedhs
23-06-2007 11:15:20
Okay having the preview window shown while exporting it did solve it!
And another which I had been trying to solve - the scene get displayed okay in Ofusion but not in my app. I have the cg plugin loaded, and material as shown below:-
material texture
{
technique
{
pass
{
ambient 0.7 0.7 0.7 1
diffuse 0.7 0.7 0.7 1
specular 0.9 0.9 0.9 1 20
vertex_program_ref vertexTextureBlendVS
{
param_named scale float 1
param_named_auto worldViewProj worldviewproj_matrix
}
fragment_program_ref vertexTextureBlend
{
param_named scale_tex1 float 110
param_named scale_tex2 float 110
param_named scale_tex3 float 110
}
texture_unit
{
texture_alias base
texture texture_base.png
}
texture_unit
{
texture_alias ground
texture texture_ground_2.bmp
}
texture_unit
{
texture_alias sand
texture texture_sand.bmp
}
}
}
}
Nothing fancy right, but it flickers badly in the scene. It seems to flicker between two materials - shade of red,green,blue (vertices diffuse color) and sand texture I believe. Here is the simplified scene for download:
http://syedhs.googlepages.com/Scene_Report.7z The scene file is compressed with 7zip.
syedhs
30-06-2007 19:11:24
Okay I am coming back to this problem.
So this weekend I decided to take a deep breath, do something different instead of fighting this problem using the same code (without any changes!). So I created a tiny program which simply load the mesh exported from the sample .max in the ofusion website. It works and it is plug and play!
And then I take the actual meshes and textures which I had the problem displaying earlier, and it too get displayed correctly!
A good news indeed.. but hmmm... I dont recall anything different than the one I had before. I will sure get this checked out first thing in Monday morning.
And next, I will try to get the lightmap blended in the scene in a single pass - I think this shouldn't be difficult.
syedhs
02-07-2007 06:10:32
Okay now I got it nailed down!
It is quite simple actually.
You cant use light at all in the scene. If you want to reproduce the problem, insert these lines:
Light *l = mSceneMgr->createLight("SunLight");
l->setType(Light::LT_DIRECTIONAL);
Vector3 light( -100,-200,-300 );
light.normalise();
l->setDirection(light);
l->setCastShadows(true);
Your scene will turn back to shade of RGB. Therefore you cant have dynamic shadow in the scene if you are using this approach of painting the terrain.
Lioric,
I wonder if the shader can be modified further so that dynamic shadow/lighting can exist in this type of scene? Otherwise, I probably have to say bye bye to this approach and adopt back the shader-based terrain splatting method.
Lioric
03-07-2007 16:40:45
This shader can be used with any light in your scene (as the shader is what controls the light results for the material pass)
Are you using shadows?
Probably the light categorization routine is creating another passes for the shadow you are using (additive), test by manually creating an ambient pass (the first pass, before the texture blend pass)
syedhs
03-07-2007 18:02:17
I will be playing around by turning on/off a few things (shadow/light/etc) and post the results here.
hmm, look forward to seeing your test results. I'm not very familiar with shadows on shader materials, might be a handy resource
OgreUser
30-07-2007 00:24:12
Hi,
I had a problem with that tutorial : the terrain/rock/grass textures were displayed correctly, but the RBG map was still visible.
I turned off shadow, and it is working now.
wambli
03-08-2007 17:40:48
Hi,
where can I find the scene sample with the lightmap support in the shader?
I have found only the base version.
Thanks
Lioric
04-10-2007 03:13:55
I will review if the shader is not in the scenes page, and upload it if needed
IFASS
10-10-2007 22:27:29
IFASS
12-10-2007 12:20:20
bump
i can't wait to get my hands on that new shader, sorry ^_^
Lioric
16-10-2007 04:06:27
The sample shader is available in the scenes section
It contains new parameters to control the LightMap settings, if the "use_lm" parameter is 1, the LightMap texture is used, and its intensity can be controlled with the "intensity" parameter
Your objects needs a uv texture coords in the channel 2 in max (1 in your ogre aplpication) for the LM texture
You need to add the LM textureUnit after your diffuse textures in the pass material
See the sample scene for more details
IFASS
16-10-2007 09:55:39
thank you very much Lioric, great as always!
IFASS
16-10-2007 11:05:25
Small problem though:
With the lightmap turned on the model turns black..
Using max9 and the shaders and textures are in the right folder.
Lioric
16-10-2007 16:31:04
Is the intensity value at least 1?
What render system are you using, have you tested with a different render system?
IFASS
16-10-2007 21:34:33
Hi Lioric, here I am again
Yes, the intensity is even set to 2 (like in the example)
Alright, first your scene
Example scene
DirectX: (It only went alright when i reloaded the shaders.. by first selecting another, then changing back to the right ones.. otherwise the model was completely black)
OpenGL:
Own scene:
DirectX
With all shaders enabled:
With the VS disabled (notice the lightmap to appear correctly):
After reloading the shaders: (by first selecting another shader and then back to original)
OpenGL
With all shaders enabled:
With the VS disabled (notice the lightmap to appear correctly):
IFASS
24-10-2007 18:49:22
Bump
Lioric
25-10-2007 01:37:18
If its working on D3D9 but not in OpenGL then its a video drivers issue
Have you tested in a different machine?
madstork91
03-03-2008 06:19:41
Iunno if this is my first post or not on these forums but HI!
I was talking with ifass earlier and he seems to have all but given up on oFussion. I managed to vertex paint the last scene for the openFrag project while using it just fine but after un installing and re installing 3ds9 and then also reinstalling oFusion i've run across several problems.
While using a max file that was already made the model went completely black. NO AMOUNT of reading the tutorials or watching the video helped me with this. I finally got it to work while using the old shaders though.
Then i immediately created a new scene, imported an .obj, set up the material, and vertex painted it. Again, the model wouldn't show correctly in the oFusion view port. This time instead of looking black while not using the lm versions of the shaders it simply looked like a crystallized jagged snowed on clump. (it should have been green grass.) And while using the lm shaders it simply looked black still.
Please help.
Lioric
03-03-2008 22:48:38
It would be better if you can post some screenshots
The incorrect display of the lm version of the shader is related to the video drivers, update it, or test with the Direct3D9 render system
In the lm version of the shader you can disable the lm texture for testing (it was a "use_lm" parameter or similar, set it to 0 to not use the lm texture in the shader)
madstork91
04-03-2008 19:22:49
I managed to get it to work earlier with a small 4x4 plane. :-/ now im having difficulty seeing it on my larger mesh. Ive played with the scaling of the maps in pixel scales but nothing seems to fix this. I do think it is a scaling issue as when I change the vertex paint color the color of the mesh in the oFusion viewer now changes to shade similar to that of the texture. I can put any number in the scaling though and still never see the map.
Also, iunno how the hell this thing fixed itself as I did nothing different with the 4x4 plane, or this time around with the same mesh.
any help thanks in advance and once afterwards i'm sure.
Edit: drivers are also current.
dedesite
10-09-2008 12:42:25
Hi all,
I use this shader for my terrain but I've got problem when I activate the shadow : the blended colors are visible. I saw that other users had this problem. Is there any solution to fix it??
It's very important because I need real time shadow and vertexblend on terrain in my game
.
Greetings,
Andréas
EDIT : I've post too fast, with MODULATIVE shadow it works
Lioric
11-09-2008 04:59:28
dedesite
11-09-2008 09:09:54
Ok, thanks Lioric, I'll look at it as soon as I have some time (which could be never :p).
Greetings,
Andreas
westpointer
19-09-2008 14:43:21
I have problem with vertexpaint.
I create a plane and follow the tips of the VertexTextureBlend video. Everything seems the same as the video until I use the vertexpaint. After I assign red to the plane, the plane in ofusion viewport dispears when I click "Update Sel", Why?
I made a new thread:
http://www.ogre3d.org/phpBB2addons/view ... 7662#47662