Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: Help with Spot and point lights: maybe a bug?  (Read 451 times)
asia
Customers
Community Member
*****
Posts: 133


« on: January 16, 2010, 04:26:15 PM »

I need help with the lights, in particular with point and spot lights in TV6.5.
I am working with VB2008 and  I got some strange behaviour like the following:

-To see the light I must have a “radius” very big, for example 50 even if the light is only few units from the land
-The light attenuation looks like working the other way round than expected, in other words when you get closer to the land the light attenuates more.

Also more strange behaviour if you try with VB6 or with TV6.3
Is it a bug?
Try this:
Code:

Public Class Form1
    Private TV As TVEngine
    Private Scene As TVScene
    Private TF As TVTextureFactory
    Private Materialfactory As TVMaterialFactory
    Private Lights As TVLightEngine
    Private LightMark As TVMesh
    Private IDLight As Long
    Private Cam As TVCamera
    Private GL As TVGlobals
    Private bLoop As Boolean
    Private land As TVLandscape
    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        bLoop = False
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TV = New TVEngine
        Scene = New TVScene
        TF = New TVTextureFactory
        Cam = New TVCamera
        Materialfactory = New TVMaterialFactory
        Lights = New TVLightEngine
        GL = New TVGlobals
        land = New TVLandscape
        TV.SetDebugFile(System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\debugfile.txt")    ' Set the debug file to the same folder as the program itself. This is very useful, Sylvain is good at catching common mistakes and informing you that you've made them in this files log.
        ' Instanciate the form
        TV.Init3DWindowed(Me.Handle, True)    ' We want to initialize on our windows handle and we have hardware transform and lighting.
        ' material for the land , to be simple: only diffuse
        Dim matLand As Long
        matLand = Materialfactory.CreateMaterial("matLand")
        Materialfactory.SetEmissive(matLand, 0.0#, 0.0#, 0.0#, 1)
        Materialfactory.SetDiffuse(matLand, 1, 1.0#, 1.0#, 1)
        Materialfactory.SetAmbient(matLand, 0, 0, 0, 1)
        ' landscape, something to receive the light
        land = Scene.CreateLandscape
        land.CreateEmptyTerrain(CONST_TV_LANDSCAPE_PRECISION.TV_PRECISION_LOW, 100, 100, -50, 0, -50)
        land.SetMaterial(matLand)
        land.SetLightingMode(CONST_TV_LIGHTINGMODE.TV_LIGHTING_MANAGED)
        Dim phi, theta, radius As Single
        phi = 20
        theta = 20
        radius = 50 ' try to put something smaller, like 10 and see...
        ' Create a point light
        IDLight = Lights.CreateSpotLight(GL.Vector(0, 1, 0), GL.Vector(0, -1, 0), 1, 1, 1, radius, phi, theta, "Lamp", 1)
        '  IDLight = Lights.CreatePointLight(GL.Vector(0, 6, 0), 1, 1, 1, 200, "Lamp", 0)
        Lights.EnableLight(IDLight, True)
        Lights.SetLightAttenuation(IDLight, 1, 0.005, 0) ' try to comment this out
        LightMark = Scene.CreateMeshBuilder()
        LightMark.CreateSphere(0.25)
        LightMark.SetPosition(0, 5, 0)
        Cam.SetCamera(60, 20, 0, 0, 0, 0)
        Cam.SetViewFrustum(45, 2500, 1)
   
        bLoop = True
        Me.Show()

        Dim y As Single
        Dim fTime As Single
        While bLoop
            fTime = TV.AccurateTimeElapsed()
            ' rendering
            TV.Clear()
            land.Render()
            Scene.RenderAllMeshes()
            TV.RenderToScreen()
            '  UpdateScene changing the light height
            y = 20 * Math.Sin(TV.TickCount / 1000) + 20
            Me.Text = y.ToString ' window caption
            LightMark.SetPosition(0, y, 0)
            Lights.SetLightPosition(IDLight, 0, y, 0)
            Application.DoEvents()
        End While
        TV.ReleaseAll()
        TV = Nothing
        End
    End Sub

End Class

Thanks

Fabio
« Last Edit: January 16, 2010, 07:47:10 PM by asia » Logged

Fabio Musmeci
ENEA
CR Casaccia
Via Anguillarese 301
00060 Rome
Italy
musmeci@enea.it
+39 3333934898
Learning to live better on a smaller footprint..
jviper
Community Member
*
Posts: 2049

Discipline in training


« Reply #1 on: January 17, 2010, 12:09:30 PM »

Try creating a Mesh instead of a Landscape.
Use AddFloorGrid with 128, 128 for the iNumCellsX, iNumCellsY. Then see what happens when you decrease these values. This should answer some question about this, though if you are confused about what's going on, I will explain farther.
« Last Edit: January 17, 2010, 12:17:33 PM by jviper » Logged

JAbstract.....Don't just imagine, make it happen!
asia
Customers
Community Member
*****
Posts: 133


« Reply #2 on: January 17, 2010, 01:47:02 PM »

OK, it works! But why? Is it related to the number of verteces? Is the light working on a vertex base? Thank you for your support
Fabio
Logged

Fabio Musmeci
ENEA
CR Casaccia
Via Anguillarese 301
00060 Rome
Italy
musmeci@enea.it
+39 3333934898
Learning to live better on a smaller footprint..
jviper
Community Member
*
Posts: 2049

Discipline in training


« Reply #3 on: January 17, 2010, 02:26:27 PM »

Basically yes. The first thing you should notice is when you have the lighting mode set to managed, you have to have your mesh tessellated. If you created a mesh with 1 by 1 segments, you would find the mesh would never get lit. The effect worked better when the mesh was more tessellated. You will find with lighting mode set to bump mapping, you did not have to worry about this. This is all because, managed lighting mode is per vertex lighting, and bump mapping is per pixel lighting.

So what about the landscape? Well the parameters are not the tvmesh.addfloorgrid. With the landscape, you are always creating 256 by 256 unit chunks. Even though you set the precision to low (which is 2 by 2 segments per chunks), one chuck still covers 256 by 256 units. You have to downscale. So what you did was create 100 by 100 chunks, which would be 25600 by 25600 units. Because of this, placing it at -50,0,-50 did not center it (it would have needed to be at -12800,0,-12800 if you did not downscale it). But the main issue at that point is the lack of tessellated. You had the light only 100 units away from an object which vertexes were 128 units apart from each other.
Logged

JAbstract.....Don't just imagine, make it happen!
asia
Customers
Community Member
*****
Posts: 133


« Reply #4 on: January 18, 2010, 02:49:22 AM »

Yes, I knew about the landscape scaling and chunk stuff and what you mentioned was actually an error of mine. For the light and tessellations part of your explanation it was very useful. Maybe I knew but I did forget! So thank you very much!
Logged

Fabio Musmeci
ENEA
CR Casaccia
Via Anguillarese 301
00060 Rome
Italy
musmeci@enea.it
+39 3333934898
Learning to live better on a smaller footprint..
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks