feanor91
14-08-2008 14:07:02
Hello
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 :
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 :
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?
Thanks.
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.EnableReflection(ReflectionPlane)
mReflectCam.Position = myCamera.Position
mReflectCam.Orientation = myCamera.Orientation
End Sub
Private Sub postRenderTargetUpdate()
mReflectCam.DisableReflection()
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.AttachObject(mPlaneEnt)
mPlaneNode.Position = mReflectSceneNode.Position
mPlaneNode.Orientation = mReflectSceneNode.Orientation
mPlaneNode.Scale(mReflectSceneNode.GetScale)
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.SetClearEveryFrame(True)
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.SetTextureAddressingMode(addrMod)
t.SetProjectiveTexturing(True, mReflectCam)
'MatToBlend.SetSceneBlending(SceneBlendType.SBT_ADD)
AddHandler rttTex.PostRenderTargetUpdate, AddressOf postRenderTargetUpdate
AddHandler rttTex.PreRenderTargetUpdate, AddressOf preRenderTargetUpdate
mReflectCam.EnableReflection(ReflectionPlane)
mPlaneEnt.SetMaterialName(MatToBlend.Name)
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
rttTex->addListener(refListener);
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?
Thanks.