Simple reflection seems not working


14-08-2008 14:07:02


i'm trying to implement some simple reflexion in my project, but if i arrive to have a texture on my plane, I have no reflection in it, as if the render to texture have not working. here my code :

Private Sub preRenderTargetUpdate()
mPlaneEnt.Visible = False
mReflectCam.Position = myCamera.Position
mReflectCam.Orientation = myCamera.Orientation
End Sub

Private Sub postRenderTargetUpdate()
mPlaneEnt.Visible = True
End Sub

Private Sub Reflect(ByVal mReflectSceneNode As Mogre.SceneNode)

ReflectionPlane.normal = Mogre.Vector3.UNIT_Y
ReflectionPlane.d = 0
Mogre.MeshManager.Singleton.CreatePlane("ReflectPlane", Mogre.ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, ReflectionPlane, 1024, 1024, 16, 16, True, 1, 1, 1, Mogre.Vector3.UNIT_Z)

mPlaneEnt = mySceneManager.CreateEntity("ReflectPlaneEnt", "ReflectPlane")
mPlaneNode = mySceneManager.RootSceneNode.CreateChildSceneNode
mPlaneNode.Position = mReflectSceneNode.Position
mPlaneNode.Orientation = mReflectSceneNode.Orientation

Dim texture As Mogre.TexturePtr = Mogre.TextureManager.Singleton.CreateManual("RttTex", Mogre.ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, Mogre.TextureType.TEX_TYPE_2D, CType(512, UInteger), CType(512, UInteger), 0, Mogre.PixelFormat.PF_R8G8B8, Mogre.TextureUsage.TU_RENDERTARGET)
Dim rttTex As Mogre.RenderTarget = texture.GetBuffer.GetRenderTarget

mReflectCam = mySceneManager.CreateCamera("ReflectCam")
mReflectCam.NearClipDistance = myCamera.NearClipDistance
mReflectCam.FarClipDistance = myCamera.FarClipDistance
mReflectCam.AspectRatio = MyWindow.GetViewport(0).ActualWidth / MyWindow.GetViewport(0).ActualHeight
Dim v As Mogre.Viewport = rttTex.AddViewport(mReflectCam)
v.BackgroundColour = Mogre.ColourValue.Black

Dim toto As Mogre.Entity = mReflectSceneNode.GetAttachedObject(CType(0, UShort))
' Dim MatToBlend As Mogre.MaterialPtr = toto.GetSubEntity(CType(0, UShort)).GetMaterial()
'Dim tus As Mogre.TextureUnitState = MatToBlend.CreateTechnique().CreatePass().CreateTextureUnitState("RttText")
Dim MatToBlend As Mogre.MaterialPtr = Mogre.MaterialManager.Singleton.Create("rttMat", Mogre.ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME)
Dim t As Mogre.TextureUnitState = MatToBlend.GetTechnique(CType(0, UShort)).GetPass(CType(0, UShort)).CreateTextureUnitState("RustedMetal.jpg")
t = MatToBlend.GetTechnique(CType(0, UShort)).GetPass(CType(0, UShort)).CreateTextureUnitState("RttText")

t.SetColourOperationEx(LayerBlendOperationEx.LBX_BLEND_MANUAL, LayerBlendSource.LBS_TEXTURE, LayerBlendSource.LBS_CURRENT, Mogre.ColourValue.White, Mogre.ColourValue.White, 0.75F)
Dim addrMod As Mogre.TextureUnitState.UVWAddressingMode = New Mogre.TextureUnitState.UVWAddressingMode

addrMod.u = TextureUnitState.TextureAddressingMode.TAM_CLAMP
addrMod.v = TextureUnitState.TextureAddressingMode.TAM_CLAMP
addrMod.w = TextureUnitState.TextureAddressingMode.TAM_CLAMP
t.SetProjectiveTexturing(True, mReflectCam)

AddHandler rttTex.PostRenderTargetUpdate, AddressOf postRenderTargetUpdate
AddHandler rttTex.PreRenderTargetUpdate, AddressOf preRenderTargetUpdate



toto.Visible = False
End Sub

the Toto variable are here for test and the scenenode passed in parameter are because I want to choose what object is the target of the reflexion. I comment it all to simplyfy the sub and to turn around possible side effect of getting the material of the object.

pre an post render target are well executed. I don't see why it doesn't work. I adapt it from several example here and there.

The only things I do not adapt is the framelistener of the texture. In my example I have :

ReflectionListener *refListener = new ReflectionListener();

and this


But I don't see how ro implement under mogre and I found no example in C# or VB....I'm suck.

Someone could help?



14-08-2008 20:45:17

But I don't see how ro implement under mogre and I found no example in C# or VB....I'm suck.
Did you check the Fresnel sample ?


18-08-2008 07:02:48


No I didn't check it, but now, I did it. But I don't understand what difference are in my code anf it's code.

Thanks fo your answer.

Edit : OK I go deeper into the C# example but it did'nt work, I manage to compile and run it, but I get a white plane where I do have watter. So I think it was my graphic card but I run the original demo from Ogre and it works fine. So what now? Reflection didn't work at all under Mogre?

here a screenshot of the mogre example:

and here from the ogre demo :