Jump to content
  • 0
vblack

Hide Terrain by code

Question

I'm doing a fps game and for optimisation (entering into a building), I need to hide the terrain entirely with a script. How to do that ? Can't find a 'terrain' object I can manipulate.

Share this post


Link to post

18 answers to this question

Recommended Posts

  • 1

Ah, that makes sense.

Do this once after your map is loaded to get the terrain entity:

local n
for n=0,world:CountEntities()-1 do
	local entity = world:GetEntity(n)
	if entity:GetClassName()=="Terrain" then
		terrain = entity
		break
	end
end

 

Share this post


Link to post
  • 1

Was playing with terrain the other day for fun so I put it in the workshop. It's too bad not all the terrain commands are working/exposed to lua.

" terrainCutter.lua Lowers terrain the size of the model/CSG it's attached to. terrainRemove.lua lowers it when you enter the model's AABB then restores it when not in it's AABB. "

https://www.leadwerks.com/workshopitem?tags=&queryType=1&fileType=0&fileid=938356115

Share this post


Link to post
  • 0

The renderer will automatically hide parts of terrain that are not visible.

Share this post


Link to post
  • 0

The problem is that we have a basement in that building and the terrain is sometimes visible (overlapping walls), we try to extrude, but hiding the whole would be better.

 

Share this post


Link to post
  • 0
1 hour ago, Josh said:

Ah, that makes sense.

Do this once after your map is loaded to get the terrain entity:


local n
for n=0,world:CountEntities()-1 do
	local entity = world:GetEntity(n)
	if entity:GetClassName()=="Terrain" then
		terrain = entity
		break
	end
end

terrain:Hide() removes collision from terrain, but it remains visible.

Share this post


Link to post
  • 0
4 minutes ago, Genebris said:

terrain:Hide() removes collision from terrain, but it remains visible.

That's actually going to be a problem, even if I fix that.  You don't want all your objects outside to fall out of the level.

The reason this occurs is that technically each terrain patch is its own entity, and is not parented to the terrain entity itself.

Share this post


Link to post
  • 0
5 minutes ago, Josh said:

That's actually going to be a problem, even if I fix that.  You don't want all your objects outside to fall out of the level.

The reason this occurs is that technically each terrain patch is its own entity, and is not parented to the terrain entity itself.

But how do you disable rendering of terrain then? You can do this, but I guess it won't help performance-wise.

 

Share this post


Link to post
  • 0
4 minutes ago, Genebris said:

But how do you disable rendering of terrain then? You can do this, but I guess it won't help performance-wise.

Well, at this point you don't.

What the user needs is for me to add another terrain tool to remove patches of the terrain.

Share this post


Link to post
  • 0

Couldn't a shader just not draw the terrain while still having it physically in place?

Share this post


Link to post
  • 0

Couldn't you set the entities alpha to 0? It' be nice if the renderer didn't even try to draw entities with an alpha color of 0.

Share this post


Link to post
  • 0

@Rick This won't help much with performance (and can actually worsen performance). You aren't saving CPU processing due to draw calls/state changes being made, and you still have to go through vertex shading, tessellation, geometry shading (unless you discard here, but you get geometry shader overhead), and rasterization. If you discard in the fragment shader (because the terrain quads are too large or something), then you compromise early-z discard, which is a GPU hardware optimization that prevents fragment shaders from running. In fact, if you are rendering terrain and drawing it last, it can be faster allowing it to render normally than trying to discard it in a shader.

Share this post


Link to post
  • 0
On ‎6‎/‎5‎/‎2017 at 11:53 AM, SGB said:

Was playing with terrain the other day for fun so I put it in the workshop. It's too bad not all the terrain commands are working/exposed to lua.

" terrainCutter.lua Lowers terrain the size of the model/CSG it's attached to. terrainRemove.lua lowers it when you enter the model's AABB then restores it when not in it's AABB. "

https://www.leadwerks.com/workshopitem?tags=&queryType=1&fileType=0&fileid=938356115

The workshop is not working for this page (got 4.3 version). Can you put the script ? I can find the entity "Terrain" as explained, but cannot control it (Hide(), Move() doesn't work)

Share this post


Link to post
  • 0
1 minute ago, vblack said:

Hi;

In  TerrainRemove.lua, tSize and terrain are undefined ?

They are defined in Main.lua

Share this post


Link to post
  • 0

OK, tried the code, but it doesn't work, when I go inside, it just flicker and the terrain is still visible

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...