Entity Colour, Transparency and Reflectiveness

madjam002

11-09-2010 13:30:32

I'm new to Mogre and I think it's fantastic, but one of the things I find confusing from using other 3d engines is the whole entity system.
I want to draw some lego bricks on the screen, which I can manage fine, however I can't find out how to change the colour, transparency and reflectiveness on the materials.
I have had a look around the Mogre and Ogre forums but I don't understand how all the material files work, and I can't seem to find any tutorials on the material file construction.
Here is the code I am using at the moment:

' Code in VB.NET
Dim block As ManualObject = mySceneManager.CreateManualObject()
' Times size by 10 to take the stud size into account
Size = New Vector3(Size.x * 10, Size.y * 10, Size.z * 10)

' Front Face
block.Begin("Examples/Rockwall", RenderOperation.OperationTypes.OT_TRIANGLE_STRIP)
block.Position(-(Size.x / 2), (Size.y / 2), -(Size.z / 2))
block.Position((Size.x / 2), (Size.y / 2), -(Size.z / 2))
block.Position(-(Size.x / 2), -(Size.y / 2), -(Size.z / 2))
block.Position((Size.x / 2), -(Size.y / 2), -(Size.z / 2))
block.End()
' Back Face
block.Begin("Examples/Rockwall", RenderOperation.OperationTypes.OT_TRIANGLE_STRIP)
block.Position(-(Size.x / 2), -(Size.y / 2), (Size.z / 2))
block.Position((Size.x / 2), -(Size.y / 2), (Size.z / 2))
block.Position(-(Size.x / 2), (Size.y / 2), (Size.z / 2))
block.Position((Size.x / 2), (Size.y / 2), (Size.z / 2))
block.End()
' Top Face
block.Begin("Examples/Stud", RenderOperation.OperationTypes.OT_TRIANGLE_STRIP)
block.Position(-(Size.x / 2), (Size.y / 2), (Size.z / 2)) : block.TextureCoord(0, 0)
block.Position((Size.x / 2), (Size.y / 2), (Size.z / 2)) : block.TextureCoord(0, 1)
block.Position(-(Size.x / 2), (Size.y / 2), -(Size.z / 2)) : block.TextureCoord(1, 0)
block.Position((Size.x / 2), (Size.y / 2), -(Size.z / 2)) : block.TextureCoord(1, 1)
block.End()
' Bottom Face
block.Begin("Examples/Rockwall", RenderOperation.OperationTypes.OT_TRIANGLE_STRIP)
block.Position(-(Size.x / 2), -(Size.y / 2), -(Size.z / 2))
block.Position((Size.x / 2), -(Size.y / 2), -(Size.z / 2))
block.Position(-(Size.x / 2), -(Size.y / 2), (Size.z / 2))
block.Position((Size.x / 2), -(Size.y / 2), (Size.z / 2))
block.End()
' Left Face
block.Begin("Examples/Rockwall", RenderOperation.OperationTypes.OT_TRIANGLE_STRIP)
block.Position(-(Size.x / 2), (Size.y / 2), (Size.z / 2))
block.Position(-(Size.x / 2), (Size.y / 2), -(Size.z / 2))
block.Position(-(Size.x / 2), -(Size.y / 2), (Size.z / 2))
block.Position(-(Size.x / 2), -(Size.y / 2), -(Size.z / 2))
block.End()
' Right Face
block.Begin("Examples/Rockwall", RenderOperation.OperationTypes.OT_TRIANGLE_STRIP)
block.Position((Size.x / 2), -(Size.y / 2), (Size.z / 2))
block.Position((Size.x / 2), -(Size.y / 2), -(Size.z / 2))
block.Position((Size.x / 2), (Size.y / 2), (Size.z / 2))
block.Position((Size.x / 2), (Size.y / 2), -(Size.z / 2))
block.End()

block.CastShadows = True
o_Entity = block

o_SceneNode = mySceneManager.RootSceneNode.CreateChildSceneNode()
o_SceneNode.AttachObject(block)
o_SceneNode.Position = New Vector3(0, 0, 0)


The code works absolutely fine and draws a brick on the screen. Ignore the fact I haven't done the texture co-ordinates on all of the faces... I know I haven't done that :lol:
My textures are transparent PNGs. With the reflectiveness, I have a skybox so would it be possible to reflect the skybox or just draw a shiny skybox merged into the stud texture?

Also, if you think the way I am going about drawing a brick on screen with the manualobject is wrong in some way, just let me know because like I said I am new :D

Thanks for everyones help!

issingle

12-09-2010 15:50:50

u can find what u want in material manual.
and u can get some info from ogresdk\example\cubemapping about reflect and env mapping

madjam002

12-09-2010 16:08:36

Ok so I understand how to do the reflectiveness in the material file, and thanks for the material manual link, I am surprised I didn't find that before.
So:
colour_op_ex source1 src_manual src_current 1 0 0
alpha_op_ex source1 src_manual src_current 0.5


is for a half transparent red, but how can I set a custom colour from Mogre Code, because the reflectiveness, colour and transparency needs to be controllable via code.
Also, how can I merge my stud texture with the colour/transparent/reflective texture?

Thanks!

Beauty

13-09-2010 21:18:33

I'm new to Mogre and I think it's fantastic, but one of the things I find confusing from using other 3d engines is the whole entity system.
Welcome to our Mogre world. It's nice that you find it FANTASTIC, just after your start into Mogre.

Which engines did you try before?
What were the good/bad sides of these ones?
What you like much at Ogre/Mogre?
It would be interesting (at least to me) to see a comparison.


I have had a look around the Mogre and Ogre forums
There is also much useful information in the wiki.
http://www.ogre3d.org/wiki (or click the wiki button on top right positon at the forums)
Unfortunatelly our new wiki software has a bad search. (I hope this will be improved in the future.)
Often it's better to search by Google. Add site:ogre3d.org as additional search param - then there are only results from the Ogre Website.
You also can use the tag search of the wiki. This works well for pages, which still are still tagged. (not all, but many)
For this click to toolbox (at top menu of the wiki) and then to the first entry (Freetags).
http://www.ogre3d.org/tikiwiki/tiki-browse_freetags.php

A central page for Mogre related stuff you find on our Mogre wiki page.
http://www.ogre3d.org/tikiwiki/MOGRE


I have had a look around the Mogre and Ogre forums [...]
how can I set a custom colour from Mogre Code, because the reflectiveness, colour and transparency needs to be controllable via code.

Here I added interesting links related to materials:
http://www.ogre3d.org/tikiwiki/-material

On page MOGRE Line 3D I published some Mogre code how to create a material with custom colour and transparency by code. Here is a snippet from the page:
// create material (colour)
MaterialPtr moMaterial = MaterialManager.Singleton.Create("line_material", "debugger");
moMaterial.ReceiveShadows = false;
moMaterial.GetTechnique(0).SetLightingEnabled(true);
moMaterial.GetTechnique(0).GetPass(0).SetDiffuse(0, 0, 1, 0);
moMaterial.GetTechnique(0).GetPass(0).SetAmbient(0, 0, 1);
moMaterial.GetTechnique(0).GetPass(0).SetSelfIllumination(0, 0, 1);
moMaterial.Dispose(); // dispose pointer, not the material


For creating objects by code, use ManualObject.
More information here:
http://www.ogre3d.org/tikiwiki/ManualObject

And here a code snippet that I published for creating a tetrahedron, by use of ManualObject:
http://www.ogre3d.org/tikiwiki/Create+T ... with+MOGRE

I hope I could help you. :wink:

madjam002

14-09-2010 16:24:40

Thanks for your reply :D
I will get back to you on how it goes.

Which engines did you try before?
I used something called Dark GDK .NET from "The Game Creators". It is actually payware and isn't fantastic, but it was slightly easier to use in terms of what I need to do with the colour and transparency, because they were actually properties onto the entity object.
However, all this material stuff I see makes it much more flexible so hopefully I will get the hang of it. Also there was an annoying problem (not sure if I will get it with Mogre as I don't know if it's a COM component) where when you build your project and share it with others, they have to register COM libraries which doesn't even work.

What you like much at Ogre/Mogre?
It's free! Also it's really powerful from what I have seen and I can use the power of .NET now making games as well!

Thanks!

Beauty

14-09-2010 17:51:59

colour and transparency, because they were actually properties onto the entity object
In Ogre the material definition is independent from entities.
An advantage: You can load a material (or create it on the fly) and this material can be used by as many enties as you like.

By the way: You also can modify a material while it's still in use. The changes will be shown immediately.

Also there was an annoying problem (not sure if I will get it with Mogre as I don't know if it's a COM component) where when you build your project and share it with others, they have to register COM libraries which doesn't even work.
I'm not shure what you mean and don't know much about COM libraries. If you think it could be a Mogre bug, please report it in the thread Mogre 1.7.1.
When you want to run Mogre applications on other computers, they need to have installed the Mogre depencies, too.

AndroidAdam

15-09-2010 01:45:28

Editing a material via code. Note only SubEntites actually have a material. If your entity consists of only one Mesh, you'll still need to use the .GetSubMesh() method and pass 0 as parameter.

Programatically make an entity semi-transparent

MaterialPtr actualMat = Entity.GetSubEntity(0).GetMaterial();
MaterialPtr transMat = actualMat.Clone(actualMat.Name + "_transparency");
Pass pass = transMat.GetTechnique(0).GetPass(0);
pass.SetSceneBlending(SceneBlendType.SBT_TRANSPARENT_ALPHA);
pass.LightingEnabled = false;
pass.DepthWriteEnabled = false;
pass.GetTextureUnitState(0).SetAlphaOperation(LayerBlendOperationEx.LBX_SOURCE1, LayerBlendSource.LBS_MANUAL, LayerBlendSource.LBS_CURRENT, 0.1f); //the 0.1f is how transparent to make it. 1 is completely solid and 0 is completely invisible
Entity.SetMaterial(transMat);


I apologize that it's in C# when you're a VB user.

Beauty

15-09-2010 11:13:22

Modify materials only for submeshes?
I never heard this. But it could be.
Do you know, why materials apply only on submeshes?
I used an other way of changing materials:

The material I create by code as I posted above.
When I want to update an existing material, I just call one other line of code:

// for creation:
MaterialPtr myMaterial = MaterialManager.Singleton.Create(materialName, "myMaterialGroup");

// for update:
MaterialPtr myMaterial = MaterialManager.Singleton.GetByName(materialName, "myMaterialGroup");

After this line I use the same code for definition of colour, etc.

Ok, I see there is a little difference to the code of AndroidAdam.
For my code you need to know the material name, which is in use by your entity. And the change will apply for each entity which uses the same material.
AndroidAdams code creates a modified copy. You don't need to know the material name and the change will only apply to the single entity.


Important for creating materials (and for use of AndroidAdams code):
Each material name must be unique (or part of an other resource group).
An easy way is to use the node name as prefix.
In case of AndroidAdams code you could do this:

// change this:
MaterialPtr transMat = actualMat.Clone(actualMat.Name + "_transparency");

// to this:
MaterialPtr transMat = actualMat.Clone(mySceneNode.Name + "_" + actualMat.Name + "_transparency");



colour and transparency, because they were actually properties onto the entity object
One more advantage of Ogre: You can define multiple "layers" for painting an entity surface by alpha splatting. There are nice example pictures for this in the wiki, but I couldn't find it now.


Also I found 2 fresh tutorials. Maybe they aren't ready now, but you could have a look to it:
http://www.ogre3d.org/tikiwiki/tutorial+basic+material
http://www.ogre3d.org/tikiwiki/tutorial ... aterials+2



If you are too lazy for code porting from C# to VB, you can use online converter tools. For example this:
http://www.developerfusion.com/tools/co ... harp-to-vb

madjam002

16-09-2010 17:33:22

Okay thanks for all your help :D
I've got some new problems now with Lighting. I want to create a sun in my game and to do this I am using this code:

Dim myLight As Light = mySceneManager.CreateLight("Light1")
myLight.Type = Light.LightTypes.LT_POINT
myLight.Position = New Vector3(0, 150, 0)
myLight.DiffuseColour = ColourValue.White
myLight.SpecularColour = ColourValue.White

mySceneManager.RootSceneNode.CreateChildSceneNode().AttachObject(myLight)


Now for some reason the light has no effect what-so-ever on my bricks I am creating with my manual object code above.
I've read a thing saying things about "NormaliseNormals" and I have tried:

moMaterial.GetTechnique(CType(0, UShort)).GetPass(CType(0, UShort)).NormaliseNormals = True


but that doesn't work...

Does anyone know how to fix this?

Beauty

16-09-2010 19:12:27

I don't know the problem.
Maybe it's one of these reasons:

* You spotlight is inside of an object (in your case this should be not the reason)
* Your camera can see only surfaces, which don't receive light (shadow side)
* Your material has bad settings (e.g. no reflection)
* Your bricks are not in the scene
* Your bricks are on a place that is not visible by the aperture angle settings of your camera
* You don't render the scene
* The transparency value of the material is wrong and so the bricks are invisible

Check the file ogre.log for warnings. (e.g. something couldn't be found)

Can you see your bricks with black or white colour or are they not visible?

You can try to replace the brick(s) by a mesh (e.g. the ninja.mesh of the basic tutorial 2).
When you see the ninja, then it seems to be a problem with your ManualObject or its material.
If you don't see the ninja, then it seems to be a problem of your light.

By the way - for sun light it's more realistic to choose the light type LT_DIRECTIONAL.
Some information and example code you find here. (the light settings are a little bit different in comparism to the point light)

If you think, it's a problem of the ManualObject, then you could try to display my tetrahedron snippet. (use an existing material name)
If you think, it's a problem of the material, then you could try to use the material of my snippet Mogre Line 3D. (pay attention of the same material name as used for your ManualObject)

Good luck :mrgreen:

madjam002

23-09-2010 18:17:47

Okay I still can't get the ManualObject lighting to work.
I copied your Tetrahedron script and set the material to Examples/Rockwall which works nicely with lighting as my base, but it won't display the material on my tetrahedron.
There is no lighting whatsoever. It's just a solid colour which is the ambientcolour.

Does anyone know why? Thanks!

Beauty

24-09-2010 00:51:27

I copied your Tetrahedron script and set the material to Examples/Rockwall which works nicely with lighting as my base
Ok, then it doesn't seem to be a problem of the material.

but it won't display the material on my tetrahedron.
Do you mean the material of the wiki page will not be displayed on your lego bricks?
Did I understand right?

Maybe you can create a tiny test application and upload it (inlcuding source and dll files)?
For a quick application creation you can use our new Mogre Tutorial Framework.
Then you can add your bricks similar to way teached in Mogre Basic Tutorial 1.

Beauty

24-09-2010 19:57:43

I got an idea. (Just an idea!)
Maybe you need to change the position in the RenderQueueGroup and set the Depth Check of the material to Off.

You also can search in the Ogre main forum for transparency. Maybe there you find more information or a solution.

madjam002

30-09-2010 20:15:22

Thanks for the help.
Unfortunately I set the Depth Check to Off on the material and then the object didn't move properly as I moved the camera.
I can't seem to find a RenderQueueGroup property in the material, but I can in the ManualObject.