Procedural textures via a DLL or callback?

Use this forum for general user support and related questions.
Post Reply
hjalfi
Posts: 4
Joined: Tue Jan 16, 2018 11:42 am

Procedural textures via a DLL or callback?

Post by hjalfi » Tue Jan 16, 2018 12:14 pm

Hello,

I'm wanting to do some work with procedural objects and I'm looking at LuxCoreRender. I'm trying to render planets, and want things like procedural clouds and atmospheric effects. See http://cowlark.com/flooded-moon/ for some pictures (done with Povray).

Does LuxCoreRender have the ability to call arbitrary user functions in order to evaluate textures or volumetric density functions? Either as a callback if I'm using the C++ API, or via a dynamically loaded DLL, or something similar. I'm aware this won't be GPU-friendly but I'm not particularly bothered by that.

I'm going to be doing standalone rendering with scenes created in code, so I don't care about Blender/Maya integration.

User avatar
Dade
Developer
Posts: 3909
Joined: Mon Dec 04, 2017 8:36 pm
Location: Italy

Re: Procedural textures via a DLL or callback?

Post by Dade » Tue Jan 16, 2018 11:52 pm

Yes and no:

- No because there are no callbacks, not during the pre-processing phase, nor during the rendering (however, as far I understand from your link, POV-ray has callbacks during the geometry pre-processing phase but not during the rendering).

- Yes because you can build your scene by using Python/C++: it is not LuxCore API to callback you but you to call LuxCore API to procedural build the scene.
For instance, this fragment of Python code create a scene with a plane and a distant light source (cut&paste from one of the API samples):

Code: Select all

def BuildPlane(objectName, materialName):
	prefix = "scene.objects." + objectName + "."
	props = pyluxcore.Properties()
	props.SetFromString(
	prefix + "material = " + materialName + "\n" +
	prefix + "vertices = -1.0 -1.0 0.0  -1.0 1.0 0.0  1.0 1.0 0.0  1.0 -1.0 0.0\n" +
	prefix + "faces = 0 1 2  2 3 0\n" +
	prefix + "uvs = 0.0 0.0  0.0 1.0  1.0 1.0  1.0 0.0\n"
	)
	
	return props

def CreateScene():
	# Create the scene
	scene = pyluxcore.Scene()

	# Create the scene properties
	scnProps = pyluxcore.Properties()
	
	# Set the camera position
	scnProps.SetFromString("""
		scene.camera.lookat.orig = 0.0 5.0 2.0
		scene.camera.lookat.target = 0.0 0.0 0.0
		""")
	
	# Define a white matte material
	scnProps.SetFromString("""
		scene.materials.whitematte.type = matte
		scene.materials.whitematte.kd = 0.75 0.75 0.75
		""")

	# Add a plane
	scnProps.Set(BuildPlane("plane1", "whitematte"))
	
	# Add a distant light source
	scnProps.SetFromString("""
		scene.lights.distl.type = sharpdistant
		scene.lights.distl.color = 1.0 1.0 1.0
		scene.lights.distl.gain = 2.0 2.0 2.0
		scene.lights.distl.direction = 1.0 1.0 -1.0
		""")

	scene.Parse(scnProps)
	
	return scene
Your code could build the surface, instantiate the trees, etc. like it is described in the link.
Support LuxCoreRender project with salts and bounties

hjalfi
Posts: 4
Joined: Tue Jan 16, 2018 11:42 am

Re: Procedural textures via a DLL or callback?

Post by hjalfi » Wed Jan 17, 2018 10:12 am

Thanks, but I think that's not quite what I asked.

Povray has its own shader language, which you can use to implement procedural textures --- it's not very quick, because it's interpreted. For my own experiments I hacked in support for DLL textures in my own copy of Povray by using dlopen() to dynamically call out to external code. This allows textures to be generated procedurally on-the-fly. This is the functionality I'm looking for in LuxCore. Does it contain anything like this, or could it be easily added?

What this allows is defining shapes mathematically, or from external data sources. I mainly want this for planet-sized procedural volumetric clouds, where the density map is far too large to exist in memory, but you can do other cool things with it. For example, in Povray:

http://dataduppedings.no/subcube/POV-Ra ... _Noise.jpg

...that shape contains no geometry at all; the entire shape is a volumetric rendering based on a mathematical description of the shape (well, it's actually an isosurface, but it's essentially the same thing). For a more mind-blowing example, try this one:

http://news.povray.org/povray.binaries. ... 7&toff=800

There are no triangles at all in that image --- the source file which generated it contains a single isosurface and is about 20 lines long...

User avatar
Dade
Developer
Posts: 3909
Joined: Mon Dec 04, 2017 8:36 pm
Location: Italy

Re: Procedural textures via a DLL or callback?

Post by Dade » Wed Jan 17, 2018 10:53 am

hjalfi wrote:
Wed Jan 17, 2018 10:12 am
Povray has its own shader language, which you can use to implement procedural textures --- it's not very quick, because it's interpreted. For my own experiments I hacked in support for DLL textures in my own copy of Povray by using dlopen() to dynamically call out to external code. This allows textures to be generated procedurally on-the-fly. This is the functionality I'm looking for in LuxCore. Does it contain anything like this, or could it be easily added?
You talk about "textures" but you always link renderings related to geometries. The question here is if POV-ray builds the linked geometries during pre-processing or on-the-fly during the rendering ?

I have some doubt about the second because it would be very slow. For the second case, the answer is no because LuxCore is monotheistic and has only one God: the triangle.

For the first case (during the pre-processing), LuxCore has something similar with fixed functions: for instance, it can transform hairs descriptions in meshes or apply "pointiness" to meshes (http://www.luxrender.net/wiki/New_in_1-5#Pointiness).
It would be possible to add new function to call something external written in whatever you want. But, again, only during the pre-processing stage, not on-the-fly during the rendering.
Support LuxCoreRender project with salts and bounties

hjalfi
Posts: 4
Joined: Tue Jan 16, 2018 11:42 am

Re: Procedural textures via a DLL or callback?

Post by hjalfi » Wed Jan 17, 2018 11:08 am

The two images I posted don't use geometry at all (other than the primitives used to contain the volumes being rendered). They're not rendered using triangles or meshes. They're (effectively) heterogeneous volumetric renderings based on a 3D texture, which is generated procedurally, which is why I'm asking about textures. I'm not interested in procedurally generating geometry, as it's easier and faster to just bake the geometry into a mesh and load it.

This is probably a clearer example:

http://news.povray.org/povray.binaries. ... ainers.png

The top image has volume rendering disabled and shows the raw geometry; the bottom one has volumetric rendering enabled. A 3D procedural texture supplies the density function for the heterogenous volume which makes up the cloud.

User avatar
Sharlybg
Donor
Posts: 1817
Joined: Mon Dec 04, 2017 10:11 pm
Location: Ivory Coast

Re: Procedural textures via a DLL or callback?

Post by Sharlybg » Wed Jan 17, 2018 11:28 am

The top image has volume rendering disabled and shows the raw geometry; the bottom one has volumetric rendering enabled. A 3D procedural texture supplies the density function for the heterogenous volume which makes up the cloud.
Your question make me maybe discover How this earth render was done in tungsten gallery :

https://benedikt-bitterli.me/tungsten.html
museum.jpg
Support LuxCoreRender project with salts and bounties

Portfolio : https://www.behance.net/DRAVIA

User avatar
B.Y.O.B.
Developer
Posts: 3348
Joined: Mon Dec 04, 2017 10:08 pm
Location: Germany
Contact:

Re: Procedural textures via a DLL or callback?

Post by B.Y.O.B. » Wed Jan 17, 2018 12:13 pm

I did something similar in the past, but with the built-in voronoi texture: http://www.luxrender.net/forum/viewtopi ... 11#p119011

hjalfi
Posts: 4
Joined: Tue Jan 16, 2018 11:42 am

Re: Procedural textures via a DLL or callback?

Post by hjalfi » Wed Jan 17, 2018 12:30 pm

I've been looking at Tungsten (and Mitsuba, too) --- it's a really nice picture. Tungsten's got a specialised heterogeneous atmospheric renderer which does Rayleigh shading; the clouds are volumetric, but it uses a height map for the source rather than a proper 3D density function. Both were designed specifically for that picture. Writeup here: http://noobody.org/is-report/advanced.html

I did produce a moon-from-space picture with Povray and volumetric procedural clouds, but it was broken and bandy and like an idiot I didn't save the source code. The only copy of the picture disappeared with twitpic (if anyone knows where the twitpic archive went, I want to see that picture again). It was creakingly slow to render.

Tungsten and Mitsuba are both really nice, and easy to hack, but I'd really like to find a modern renderer that supported volumetric procedural volumes via DLLs *without* having to patch in support myself. Hence my question...

Post Reply