Evaluate to 3D Texture

3D Texture using GLScene.

 

What Is It?

Evaluate to 3D Texture is a program that lets you specify a formula, that determines the properties of a 3D texture.

The textures become fairly large, even though I only use a resolution of 64x64x64 pixels, with 4 bytes of color data per pixel (Red, Green, Blue and Aplha channel). That comes out to 1024 kb. The system could easily handle 128x128x128 pictures, but generating them becomes prohibitive. Rendering at 64^3 takes 5 seconds on my computer. Rendering at 128^3 should take about 40 seconds.

Who Made It?

The original code was created by Jens Krüger, and can be found here. Eric Grange ported the demo to GLScene, and Jürgen Abel and Ivan Lee Herring made changes to the code. Jurgen Abel made the x/y/z cutting plane.

The Evaluate code was created by mattias fagerlund, I am also maintained this page.

A couple of images

Showing still 2D versions of the images don't do them justice - each of these textures can be rotated in real time on a fast computer, showing them from any angle with transparancy and all. But all the same, here are a couple of 2D renderings for you to look at. Below each image you can see the formula used to generate the image.

SetPixelRGBA(x, (x+y)/2, z, Max(x/6, IfThen(r-0.5,0,1)))

 

SetPixelRGBA(x, (x+y)/2, z, IfThen(r-0.7,1,0))

 

IfThen(r-0.7, SetPixelRGBA(x, (x+y)/2, z, 1), SetPixelBWA(1, r/8))

 

Same as above, but using a much lower resolution

 

(Function is fairly complex, download demo)

 

(Another complex function)

 

Noise example

 

Noise example

 

Noise example

Email images to me!

If you create any interesting images, please send the code to me, and I'll include it in the latest distro.

Download the demo / source

Note that the first time you run the demo, you will be required to generate a 3D Texture, because none are included in the download. The code requires a late model gfx card to function properly.

  Click here to download the 3DTexture demo.
Size=352,06 kb, created 2005-10-04 07:04:08.

  Click here to download the full source - requires late version (CVS) of GLScene.
Size=933,47 kb, created 2005-10-04 07:04:03.
  Click here to download the source only (no bin) - requires late version (CVS) of GLScene.
Size=23,73 kb, created 2005-02-28 19:39:36.

The Formula Language

The language that describes the formulas is actually quite simple, try to follow the examples and you should be allright. If you find a formula that's valid and won't compile, please send it to me. If you find a formula that's invalid, and makes the program crash, please send it to me.

Operator / Operand name

  Description
x / y / z   Returns x,y and z value of the pixel being painted, in the range 0 to 1
ox / oy / oz   Returns x,y and z value of the pixel being painted, but in the range -1 to 1.
r   The distance from the center of the cube, in the range 0 to 1
     
Constants   Use '.' for decimals, as in 0.75 or 23.23. Of course, values without decimals are also valid.
 
Parenthesis   Parenthesis work as you'd expect, go ahead and use them!
     
SetPixelRGBA   Will set the color and alpha of the pixel to four distinct values. It takes three arguments, corresponding to Red, Green, Blue and Alpha values. Values are capped to [0..1]

SetPixelRGBA(Red, Green, Blue, Alpha)
 

SetPixelBWA

  Will set the color of the pixel and the alpha of the pixel to two distinct values. All pixels outputted using this method will be grey, because R=G=B. See SetPixelRGBA for more information.

SetPixelBW(RGB, Alpha)
 
SetPixelBW   Will set the color and alpha of the pixel to a single value. All pixels outputted using this method will be grey, because R=G=B. See SetPixelRGBA for more information.

SetPixelBW(RGBAndAlpha)
     
+, *, /, -   Function as you would expect.

SetPixelBWA(x*(z-0.5)+y*2-3, 0.3)
 
>   Returns true (1) if first argument is larger than second argument. Otherwise it returns false (-1)

x>y
<   see >
     
Max   Requires two arguments, returns the bigger of the two
Min   Requires two arguments, returns the smaller of the two
Sin   Requires one argument, returns the sine
OSin   A modified version of sin, that works in the range of 0 to 1 and returns values in the range 0 to 1

OSin(x)=(Sin(x*2*pi+1)/2
 
Abs   Requires one argument, returns the absolute value (always positive)
SQR   Requires one argument, returnes the square of the argument
SQRT   Requires one argument, returnes the square root of the argument
     
IfThen   Requres three arguments. If the first argument is above zero, the second argument is executed. If the first argument is below or equal to zero, the thirg argument is executed.

IfThen(Test, IfTrue, IfFalse)
 
And   Requires two arguments, returns true (1) if both are true (>0), otherwise it returns false (-1).

IfThen(and(x>0.2,y>0.2), 1, 0)
 

Or   Works like and, but instead of and it ors. Or?
Xor   Works like or, but only if one of them. Xor?
     
NoiseXYZ   Basic perlin noise function. Requires three arguments that determin the noise behavoiur. Typically, you would input x,y,z - but you can imput anything you want.
 
NoiseFull   Similar to basic noise function but also implements amplitude and octave. It requires 5 arguments (x,y,z,octave and amplitude).

NoiseFull(ax, ay, az, oct, amp)=NoiseXYZ(ax*Oct, ay*Oct, az*Oct)*Amp
 
NoiseOctAmp   Another noise function that uses the image x,y,z - you don't need to input them.

NoiseOctAmp(Oct, Amp) = NoiseXYZ(x*Oct, y*Oct, z*Oct)*Amp

Typically, you will want to add several octaves with different amplitudes for a nice noise pattern;

SetPixelBWA(1,
  NoiseOctAmp(2,1/2) +NoiseOctAmp(4,1/4) +
  NoiseOctAmp(8,1/8)+ NoiseOctAmp(16,1/16))
 

     
?   Feel free to suggest further functions

If you have any questions, suggestions or comments, don't hesitate to email the to me at mattias@hypeskeptic.com.

Click here to go back to mattias homepage.