Terrain Lights Issue
Re: Terrain Lights Issue
Is it one solid terrain or many that are connected?
If possible could you post some example code?
If possible could you post some example code?
Re: Terrain Lights Issue
I looked through the OGRE forums a bit and from what I can tell the terrain system has a single pass for lights.
Meaning the last light assigned will be the one rendered on the terrain.
Kinda a bummer if it's true, but I'm sure there is a good reason for it.
If the terrain could use a material script you could change the terrain materials from single to multi pass.
Which will create a pass for every light created.
Not sure if that's possible though without creating your own mesh for the terrain. One that you can assign a material to.
The terrain system has several advantages over a standard mesh though. So, this may not even be an option for you.
Maybe someone with a better terrain knowledge can help. I'm not even 100% sure if I'm correct on the
single pass for the light system.
I'll do some more looking around and let you know if I find something.
Meaning the last light assigned will be the one rendered on the terrain.
Kinda a bummer if it's true, but I'm sure there is a good reason for it.
If the terrain could use a material script you could change the terrain materials from single to multi pass.
Which will create a pass for every light created.
Not sure if that's possible though without creating your own mesh for the terrain. One that you can assign a material to.
The terrain system has several advantages over a standard mesh though. So, this may not even be an option for you.
Maybe someone with a better terrain knowledge can help. I'm not even 100% sure if I'm correct on the
single pass for the light system.
I'll do some more looking around and let you know if I find something.
Re: Terrain Lights Issue
extract from this tutorial
But you can change this light to change the lightmap. Use F5The Terrain component uses a directional light to compute the terrain lightmap, so let's put a directional light into our scene:
Code: Select all
;
; ------------------------------------------------------------
;
; PureBasic - Terrain : Create 9 terrains in one TerrainGroup
;
; (c) 2012 - Fantaisie Software
;
; ------------------------------------------------------------
;
; It can take few minutes to build all terrains (it will be more faster after saving it)
MessageRequester("Warning !", "It can take a few minutes to build all terrains...", 0)
IncludeFile "Screen3DRequester.pb"
#CameraSpeed = 2
#TerrainMiniX = 0
#TerrainMiniY = 0
#TerrainMaxiX = 0
#TerrainMaxiY = 0
Define.f KeyX, KeyY, MouseX, MouseY
Declare InitBlendMaps()
; OpenGL needs to have CG enabled to work (Linux and OS X have OpenGL by default)
;
CompilerIf #PB_Compiler_OS <> #PB_OS_Windows Or Subsystem("OpenGL")
Flags = #PB_Engine3D_EnableCG
CompilerEndIf
If InitEngine3D(Flags)
InitSprite()
InitKeyboard()
InitMouse()
If Screen3DRequester()
Add3DArchive("Data/Textures/", #PB_3DArchive_FileSystem)
Add3DArchive("Data/Textures/nvidia", #PB_3DArchive_FileSystem)
Add3DArchive("Data/Packs/desert.zip", #PB_3DArchive_Zip)
;- Light
;
light = CreateLight(#PB_Any ,RGB(190, 190, 190), 4000, 1200, 1000,#PB_Light_Directional)
SetLightColor(light, #PB_Light_SpecularColor, RGB(255*0.4, 255*0.4,255*0.4))
LightDirection(light ,0.55, -0.3, -0.75)
AmbientColor(RGB(255*0.2, 255*0.2,255*0.2))
For i=0 To 200
CreateLight(#PB_Any ,#Gray, Random(8000), Random(8000), 1000)
Next
;- Camera
;
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 800, 400, 80, #PB_Absolute)
CameraBackColor(0, RGB(5, 5, 10))
;- Terrain definition
SetupTerrains(LightID(Light), 3000, 0)
; initialize terrain
CreateTerrain(0, 513, 12000, 600, 3, "TerrainGroup", "dat")
; set all texture will be use when terrrain will be constructed
AddTerrainTexture(0, 0, 100, "dirt_grayrocky_diffusespecular.jpg", "dirt_grayrocky_normalheight.jpg")
AddTerrainTexture(0, 1, 30, "grass_green-01_diffusespecular.jpg", "grass_green-01_normalheight.jpg")
AddTerrainTexture(0, 2, 200, "growth_weirdfungus-03_diffusespecular.jpg", "growth_weirdfungus-03_normalheight.jpg")
; Build terrains
For ty = #TerrainMiniY To #TerrainMaxiY
For tx = #TerrainMiniX To #TerrainMaxiX
Imported = DefineTerrainTile(0, tx, ty, "terrain513.png", ty % 2, tx % 2)
Next
Next
BuildTerrain(0)
If imported = #True
InitBlendMaps()
UpdateTerrain(0)
; If enabled, it will save the terrain as a (big) cache for a faster load next time the program is executed
; SaveTerrain(0, #False)
EndIf
; SkyBox
;
;SkyBox("desert07.jpg")
CreateWater(0, 0, 100, 0, 0, #PB_World_WaterLowQuality | #PB_World_WaterCaustics | #PB_World_WaterSmooth | #PB_World_WaterFoam | #PB_World_WaterGodRays)
Sun(10000, 10000, -100000, RGB(238, 173, 148))
Repeat
Screen3DEvents()
If ExamineKeyboard()
If KeyboardReleased(#PB_Key_F5)
;- Light
;
light = CreateLight(#PB_Any ,RGB(0, 0, 0), 4000, 200, 1000,#PB_Light_Directional)
SetLightColor(light, #PB_Light_SpecularColor, RGB(0*0.4, 0*0.4,0*0.4))
LightDirection(light ,0.55, -0.3, -0.75)
AmbientColor(RGB(5*0.2, 5*0.2,5*0.2))
CameraBackColor(0, RGB(0, 0, 0))
UpdateTerrain(0)
EndIf
If KeyboardPushed(#PB_Key_Left)
KeyX = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX = #CameraSpeed
Else
KeyX = 0
EndIf
If KeyboardPushed(#PB_Key_Up)
KeyY = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = #CameraSpeed
Else
KeyY = 0
EndIf
EndIf
If ExamineMouse()
MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
EndIf
MoveCamera(0, CameraX(0), TerrainHeight(0, CameraX(0), CameraZ(0)) + 20, CameraZ(0), #PB_Absolute)
MoveCamera (0, KeyX, 0, KeyY)
RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
End
EndIf
Else
CompilerIf #PB_Compiler_OS <> #PB_OS_Windows Or Subsystem("OpenGL")
;
; Terrain on Linux/OSX and Windows with OpenGL needs CG toolkit from nvidia
; It can be freely downloaded and installed from this site: https://developer.nvidia.com/cg-toolkit-download
;
MessageRequester("Error","Can't initialize engine3D (Please ensures than CG Toolkit from nvidia is correcly installed)")
CompilerElse
MessageRequester("Error","Can't initialize engine3D")
CompilerEndIf
EndIf
Procedure Clamp(*var.float, min.f, max.f)
If *var\f < min
*var\f = min
ElseIf *var\f > max
*var\f = max
EndIf
EndProcedure
Procedure InitBlendMaps()
minHeight1.f = 70
fadeDist1.f = 40
minHeight2.f = 70
fadeDist2.f = 15
For ty = #TerrainMiniY To #TerrainMaxiY
For tx = #TerrainMiniX To #TerrainMaxiX
Size = TerrainTileLayerMapSize(0, tx, ty)
For y = 0 To Size-1
For x = 0 To Size-1
Height.f = TerrainTileHeightAtPosition(0, tx, ty, 1, x, y)
val.f = (Height - minHeight1) / fadeDist1
Clamp(@val, 0, 1)
SetTerrainTileLayerBlend(0, tx, ty, 1, x, y, val)
val.f = (Height - minHeight2) / fadeDist2
Clamp(@val, 0, 1)
SetTerrainTileLayerBlend(0, tx, ty, 2, x, y, val)
Next
Next
UpdateTerrainTileLayerBlend(0, tx, ty, 1)
UpdateTerrainTileLayerBlend(0, tx, ty, 2)
Next
Next
EndProcedure Please correct my english
http://purebasic.developpez.com/
http://purebasic.developpez.com/
Re: Terrain Lights Issue
For a workaround what about adding a texture that's the same color as the light to the terrain itself.
Similar to how the example TerrainBlend.pb works, but instead of a grass texture you would use your light color.
http://purebasic.developpez.com/documen ... nd.pb.html
Wherever you add a lamppost you could then blend the plain colored texture onto the terrain below it.
You could still add a light to the lamppost too. Then your entities will still receive light from it.
Similar to how the example TerrainBlend.pb works, but instead of a grass texture you would use your light color.
http://purebasic.developpez.com/documen ... nd.pb.html
Wherever you add a lamppost you could then blend the plain colored texture onto the terrain below it.
You could still add a light to the lamppost too. Then your entities will still receive light from it.
Re: Terrain Lights Issue
I didn't even think about that. Unfortunately, I have no clue how. Normally, I disable the materials lighting effects, but terrains don't use materials.Alexi wrote:A nice idea, can we disable the Lights for the Terrain? Otherwise it would still render those artefacts on the terrain.![]()
Maybe someone else has a clue how to do that.
Looks like it's using two compositors. A G-buffer and a light compositor.Alexi wrote: I recently found a "deffered shading" technique for Ogre, but I'm not sure if it just need a compositor or anything other we can't access from PB.
Instead of using one pass per light it seems to handle all the lights in one pass. Which sounds like a good speed boost when dealing with multiple lights.
Since terrains seem to be single pass for lights this may be exactly what you need. Although it is possible the terrains may still block this from working too.
I don't know enough about the terrain system to say for sure.
I might be able to fiddle with this later, but I'm not very skilled when it comes to compositors.
In the past I've had some success setting them up. Sadly, most of the time I can't get them running properly and this one here
seems to be a little bit more complex. At least to me.
Re: Terrain Lights Issue
It uses the default lights. It's very similar to how the lights you use now work. It just handles all the lights in one go instead of multiple passes like it does now.Alexi wrote: Would the deffered shading use the default lights? Or does it use meshes with a material?
So, Deferred shading is mainly a performance boost.
From the examples I've seen so far. The lighting effects will look similar to how a per pixel shader looks.
Re: Terrain Lights Issue
Well, I'm not sure how you set up your code, but I don't think you need to do anything extra with the lights......I think.
I don't know if I understand this compositor correctly, but I believe you only need to use the DeferredShading/ShowLit in your PB code.
DeferredShading/ShowLit uses the G-Buffer as texture reference for the lighting.
So, if you used CreateCompositorEffect(#Effect, CameraID, DeferredShading/GBuffer) you would most likely get a black screen.
You could try the ShowLit compositor by itself. Just make sure the G-Buffer is in the same folder as the ShowLit.
So, ShowLit can still get a hold of the G-Buffer.
Of course I could be very wrong about how all of this works. So, don't take my word as fact.
Also, it may help you to find bugs if you take a peek at your OGRE log from time to time.
I don't know if I understand this compositor correctly, but I believe you only need to use the DeferredShading/ShowLit in your PB code.
DeferredShading/ShowLit uses the G-Buffer as texture reference for the lighting.
So, if you used CreateCompositorEffect(#Effect, CameraID, DeferredShading/GBuffer) you would most likely get a black screen.
You could try the ShowLit compositor by itself. Just make sure the G-Buffer is in the same folder as the ShowLit.
So, ShowLit can still get a hold of the G-Buffer.
Of course I could be very wrong about how all of this works. So, don't take my word as fact.
Also, it may help you to find bugs if you take a peek at your OGRE log from time to time.
Re: Terrain Lights Issue
It seems like most people in the OGRE community create there own terrain material generator.
They just copy OGRE's default one and edit it to their liking.
Like this one http://www.ogre3d.org/tikiwiki/tiki-ind ... ht+Terrain
I'm not sure what you should do.
All I can say is I personally don't use OGRE's terrain system. I created my own setup. I know it's not ideal for you to create a regular mesh
for your terrain, but it may be something to consider. LOD, Texture Splatting/Layering , Normal mapping, and Physics are all possible on
a regular mesh just like OGRE's terrain. It requires script and a little shader knowledge, but if you have that. With a couple hours of work
you could have a terrain system on par or greater than OGRE's terrain system. Plus you will have the use of multiple lights because you'll be using material scripts.
You also won't be limited to OGRE's command setup. You'll be able to change and adapt things to how you like.
Just my two cents on the subject.
They just copy OGRE's default one and edit it to their liking.
Like this one http://www.ogre3d.org/tikiwiki/tiki-ind ... ht+Terrain
I'm not sure what you should do.
All I can say is I personally don't use OGRE's terrain system. I created my own setup. I know it's not ideal for you to create a regular mesh
for your terrain, but it may be something to consider. LOD, Texture Splatting/Layering , Normal mapping, and Physics are all possible on
a regular mesh just like OGRE's terrain. It requires script and a little shader knowledge, but if you have that. With a couple hours of work
you could have a terrain system on par or greater than OGRE's terrain system. Plus you will have the use of multiple lights because you'll be using material scripts.
You also won't be limited to OGRE's command setup. You'll be able to change and adapt things to how you like.
Just my two cents on the subject.
Re: Terrain Lights Issue
The ability to add more lights to the terrain materials would solve this in an instant, but since we can't get a hold of those materials.Alexi wrote: How could a material act like light? Like a Sphere of Fog or Glow brighten everything behind/in it's range (blendmode "add"), i really just need simple light, without strange artifacts.
We have very slim chances of doing that.
So I guess we'll just have to think up some alternatives.
Just some thoughts, but what about a particle emitter or billboards system. I've heard of people using these to create lighting effects.
Like light shafts and such.
That or maybe something like a shape with a rotating alpha material on it to look like light particles.
These won't be as efficient as a shader, but they might be worth a try.
I'll keep thinking on this and I'll let you know if I get anymore ideas.
Re: Terrain Lights Issue
If it's too dark you could try SetMaterialColor(#Material, #PB_Material_SelfIlluminationColor, Color) to lighten it up a bit.Alexi wrote: I'm not sure it will lighten the background with scene_blend add if it's really dark and no ogre light source placed.
Re: Terrain Lights Issue
I plan on setting up a volumetric light compositor, but at the moment I have very little time.
So, it might take two or three weeks to get it up and running.
If your interested and I can get it working properly. I'll post the code here on the forums for you and others to use.
One issue you may have though is the speed. I've heard of volumetric lights causing slow downs with certain viewing angles.
I guess I'll know the limits better when it's closer to being finished.
So, it might take two or three weeks to get it up and running.
If your interested and I can get it working properly. I'll post the code here on the forums for you and others to use.
One issue you may have though is the speed. I've heard of volumetric lights causing slow downs with certain viewing angles.
I guess I'll know the limits better when it's closer to being finished.
Re: Terrain Lights Issue
I have seen a few topics on volumetric lighting on the OGRE forums. The problem was most topics were a few years old and the source downloadsAlexi wrote:a historic contribution to PB, as this even isn't available at the O3D Community.
had gone and died. I found a older sample on light shafts that I'm going to use as a base. Hopefully everything will work out.
That's good to hear. It's a good idea for you to have other options for your lighting. Just in case I mess this up and can't get it workingAlexi wrote:This actual solution works mostly good.
correctly.
Re: Terrain Lights Issue
I stumbled across another volumetric light demo from the ogre forums.
The demo wasn't the best looking example around, but I think it's a pretty accurate example for performance.
Here's what I've found out so far.
I got a pretty big drop in FPS when the camera got too close to the light shafts. With a resolution of 1080 the FPS dropped down to about 20 when zooming in.
I swapped the resolution to 720 and the lowest it went was 40 FPS which isn't too bad. I consider my gpu's capabilities to be about average for today's standards.
This is just one light though. I'm not sure how many you need, but I could see this being a major performance cost if you have many visible lights in the same area.
I guess it all depends on if you plan on supporting lower end computers. I guess you could always have them disabled on low graphic settings.
Anyways, I still have quite a ways to go before it's up and running in Purebasic. I've been getting a lot of error messages from OGRE.
Which I think has a lot to do with the age of this example.
EDIT:
Also it won't work on graphic cards older then ATI Radeon HD 2000+ or nVidia GeForce FX 6 series.
The demo wasn't the best looking example around, but I think it's a pretty accurate example for performance.
Here's what I've found out so far.
I got a pretty big drop in FPS when the camera got too close to the light shafts. With a resolution of 1080 the FPS dropped down to about 20 when zooming in.
I swapped the resolution to 720 and the lowest it went was 40 FPS which isn't too bad. I consider my gpu's capabilities to be about average for today's standards.
This is just one light though. I'm not sure how many you need, but I could see this being a major performance cost if you have many visible lights in the same area.
I guess it all depends on if you plan on supporting lower end computers. I guess you could always have them disabled on low graphic settings.
Anyways, I still have quite a ways to go before it's up and running in Purebasic. I've been getting a lot of error messages from OGRE.
Which I think has a lot to do with the age of this example.
EDIT:
Also it won't work on graphic cards older then ATI Radeon HD 2000+ or nVidia GeForce FX 6 series.
Re: Terrain Lights Issue
It uses a compositor with 4 HLSL shaders at the moment. It doesn't run off of the default lighting.Alexi wrote: How the volumetric light works? A compositor using default lights?
You need to set the light parameters in a material script. So, if you need to update the light data during run time. I'll need to set up custom parameters
in the material script.
Re: Terrain Lights Issue
LOD should be supported out of the box, you just need to specify lod level in your mesh and in your materials: http://www.ogre3d.org/forums/viewtopic.php?f=2&t=48795


