Select polygons by texture or light

Hello.
I will want to make a script that will optimize my scene, by removing all polygons that are not visible to any of lights (this lights will not be used to illuminate scene, but just for optimizing).
One of ideas was to render out baked texture of my scene with cranked up intensity of lights and white material on all objects, so that I get more or less black and white texture on all scene objects. Then I was thinking to maybe select all polygons that have all pure black pixels on them (so they are not hit by light in any case), and simply delete them... But I don't know how to do that :(

And second idea was to also use lights, but if is possible to somehow use their light tracing to determine if polygon is hit by light or not...

I think that second method will be best, because it will eliminate texture baking and possible errors due to low resolution of baked texture...

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
koberko's picture

Cool!

@ jos_balcaen

I'm glad that you like idea; to explain it more further, here is example for what I will need it; I'm making low poly terrain for ship simulator, and 3d engine is a bit old and has a lot of limitations (it's sort of industrial simulator), so I can use just 450 000 polygons per scene... And in this case, I have quite large part of terrain with a lot of mountains... So I was thinking to make a script that will remove polygons that are not visible from main sail path. I have planted lights along coastline (attached image 1) and baked texture to see what is visible and what not (image 2). As you can see, a lot of terrain is actually not visible. And that's just relativity small part of whole terrain (see attached image nbr. 3 with whole terrain).

One thing that I was testing, but it didn't give accurate results, was using that baked texture, to bake vertex color, and then use vertex color to select polygons... But, result was not so good.

If you have some tips and ideas what to use to make this work (I personally think that method with just lights will be the best), I will appreciate if you could post it here, so that I can try to make it by my self. And I'll post what ever I make, for further assessment and upgrade (I'm still learning scripting, so I'm not that good at it)

AttachmentSize
__terrain_optimize.jpg 789.11 KB
tree_planting_lvl_1.jpg 194.31 KB
__terrain_all.jpg 369.18 KB
jos's picture

good start

I had the same idea few weeks ago.
I can give you a sample script from cgacademy series.
what you'll need :

theRay = mapScreenToWorldRay mouse.pos
theInt = IntersectRayEx theMesh theRay
if theInt != undefined then
(
	nrFaceHit = theInt[2]
)

i'll attach the script. will write some comments

AttachmentSize
rayintersections.ms 2.82 KB
koberko's picture

Tnx

Tnx; I'll play with it this days to see results... I'm a bit sick, so it won't be as soon as I expected...

jos's picture

no time

Unfortunately I have no time right now, but this would be a very useful script.
as it doesnt exist within one month, i'll write it myself.
" And second idea was to also use lights, but if is possible to somehow use their light tracing to determine if polygon is hit by light or not... " -> yes, is possible

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.