Shadow problem (VB.NET)

Irrlicht.Net is no longer developed or supported, Irrlicht.Net Cross Platform is a much more complete wrapper. Please ask your C# related questions on their forums first.
Locked
jingquan
Posts: 222
Joined: Sun Aug 20, 2006 4:10 am
Contact:

Shadow problem (VB.NET)

Post by jingquan »

I wanted to create realtime shadows in my map but I think there's something wrong with my code, the map shows flickering black textures in certain areas. Below is my code in VB.NET. Anything I had done wrong?

Code: Select all

Imports System
Imports Irrlicht
Imports Irrlicht.Video
Imports Irrlicht.Core
Imports Irrlicht.Scene

Module Module1
    Private device As IrrlichtDevice
    Private cam As ICameraSceneNode
    Private Camcol As ISceneNodeAnimator




    Public Class MyEventReceiver
        Implements IEventReceiver

        Public Function OnEvent(ByVal e As [Event]) As Boolean Implements IEventReceiver.OnEvent
            If e.Type = EventType.KeyInput Then
                '37=leftkey,38=upkey,39=rightkey,40=downkey, 
                If e.Key = KeyCode.KEY_ESCAPE Then
                    End
                End If
            End If
                Return False
        End Function


    End Class

    Sub Main()

        ' The Engine

        device = New IrrlichtDevice(DriverType.OPENGL, New Dimension2D(1024, 768), 32, False, True, False)

        device.ResizeAble = True

        ' The Scene

        Dim smgr As ISceneManager = device.SceneManager
        Dim driver As IVideoDriver = device.VideoDriver

        Dim mesh As IAnimatedMesh = smgr.GetMesh("devmap.3ds")
        Dim mapnode As ISceneNode = smgr.AddAnimatedMeshSceneNode(mesh, Nothing, 0)

        Dim xnode As IAnimatedMeshSceneNode = CType(mapnode, IAnimatedMeshSceneNode)
        xnode.AddShadowVolumeSceneNode()

        Dim selector As ITriangleSelector = Nothing
        If Not (mapnode Is Nothing) Then
            mapnode.Position = New Vector3D(0, 0, 0)
            selector = smgr.CreateOctTreeTriangleSelector(mesh.GetMesh(0), mapnode, 128)
        End If

        mapnode.SetMaterialFlag(MaterialFlag.LIGHTING, True)
        mapnode.SetMaterialFlag(MaterialFlag.NORMALIZE_NORMALS, True)

        smgr.AddLightSceneNode(Nothing, New Vector3D(0, 10, 0), New Colorf(1.0F, 1.0F, 1.0F, 1.0F), 100, 0)

        smgr.ShadowColor = New Color(100, 0, 0, 0)

        ' The Camera

        cam = smgr.AddCameraSceneNodeFPS(smgr.RootSceneNode, 100, 50, -1)
        cam.Position = New Vector3D(0, 5, 0)
        Dim anim As ISceneNodeAnimator = smgr.CreateCollisionResponseAnimator(selector, cam, New Vector3D(2, 4, 2), New Vector3D(0, -2, 0), New Vector3D(0, 0, 0), 0)
        'cam.AddAnimator(anim)


        device.CursorControl.Visible = False

        ' Drawing Loop

        Dim fps As Integer = 0

        While device.Run() = True
            If device.WindowActive Then

                device.VideoDriver.BeginScene(True, True, New Color(0, 100, 100, 100))

                device.SceneManager.DrawAll()

                device.VideoDriver.EndScene()

                device.EventReceiver = New MyEventReceiver()

                If (fps <> device.VideoDriver.FPS) Then
                    fps = device.VideoDriver.FPS
                    device.WindowCaption = "Test1 [" + device.VideoDriver.Name + "] fps:" + fps.ToString
                End If

            End If
        End While

    End Sub

End Module
Riki
Posts: 30
Joined: Tue Feb 27, 2007 9:12 pm
Location: Croatia

Post by Riki »

I think Irrlicht has a problem casting shadows on level geometry. Big meshes or closed meshes (rooms) are most likely to cause such a behaviour.
But than again I am not an Irrlicht expert - just an user 8)


cheers
Riki
Locked