Re: [Flightgear-devel] Functions to textures?

2012-07-25 Thread Renk Thorsten
 Actually, the code that creates the texture is in
 scene/util/StateAttributeFactory.cxx, but you would have to do
 something similar to the noise texture code in TextureBuilder to
 access your texture from a texture. It would be nice if the Effects
 framework had a way to load arbitrary textures and make them available
 to effects.

  These days you aren't limited to 8 bit texture components. There is a
 rich set of data formats for textures: 32 bit floats, 16 bit floats,
 exotic combinations of different length floats per RGB component... I
 don't know if there is a better way to create your texture offline
 than write C++ code in simgear. OSG will read a TIFF file with 32bits
 per component as a floating point texture... assuming you can create
 such a thing.

Thanks for the explanations and locations.

After some experiments, it seems the way to do this is to implement the noise 
function directly as GLSL code in the fragment shader. This has a whole bunch 
of advantages:

1) Creating a 4-component noise vector corresponding to what is in the texture 
beats the texture lookup call by (very roughly) ~20% on my system
2) Unlike a noise texture, noise generated on the fly never has tiling 
artefacts, so there is no need to superimpose nearby wavelengths in the first 
place, saving between a third and half of the total use of noise
3) Unlike texture lookup, the noise function can be evaluated just when needed, 
even inside a non-uniform conditional,i.e. for instance respecting a distance 
cut which makes a lot of sense for LOD, again that saves a lot of un-needed work

(and 4), I can write it in a completely intuitive way by passing a wavelength 
in and getting a number between 0 and 1 out, so there's no need to do any 
re-scaling and mental arithmetics).

So, that just means I have to change a few numbers everywhere...

* Thorsten
--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


[Flightgear-devel] Functions to textures?

2012-07-24 Thread Renk Thorsten
First of all, a big thanks to Tim - Akenine-Moller Co. is indeed quite an 
interesting read, and in addition to gaining a better understanding, I've so 
far experimented successfully with a heightfield for parallax and normal 
mapping and a simple irrandiance map instead of the ambient term in lighting. 

For those not inclined to read through a longer email, my question up front: I 
have a function, I want a texture holding the function values  pairs - how do I 
map this without editing every pixel offline? And can we do this also online? 
Where is for instance the 3d noise texture defined and filled - is it simple to 
change the procedure?

For those interested in the context:

I have managed to create quite compelling terrain visuals from close-up (see 
here 
http://www.flightgear.org/forums/viewtopic.php?f=47t=16884start=15#p162613 
for two examples), but rendering seems to get too slow too soon for anything 
really fancy (of course, a big roadblock is that I'm implementing all this on 
top of atmospheric light scattering which is slow to begin with - I think in 
the default light and fog scheme it might run with decent speed).

One problem that really kills framerate is de-tiling. In order to de-tile 
properly, one needs to mix noise from different wavelengths such that the 
interference creates a pattern with a much larger periodicity. Three 
wavelengths usually do the job well, two are marginally acceptable, one is 
quite bad.

So, for each texture component (snow, gradient texture, detailed texture, 
height map, fog) I ideally need three noise wavelengths. In the current 3d 
noise, noise[0] contains structures with a qualitatively different 
distribution, so I have to discard that component. noise[3] is too fine and 
runs into texture resolution problems, so I have to discard that as well. Since 
the noise pattern associated with different texture components needs to be 
uncorrelated (otherwise there's yet another form of tiling around the corner) I 
need to do different noise lookups for every texture component, arranging them 
in a slightly different wavelength interval.

And that's a lot of texture3D() calls which really make the system slow.

I could do it in half the time if I would get 4 useful components for every 
texture3D() call, but that requires that I either create a suitable texture 
offline or change the way it is done in the code (I'm also exploring if there 
is perhaps a function that evaluates faster than a texture lookup call...).

Somewhat inversely, I'm also wondering if a simple texture1D() lookup might not 
be faster than evaluating the light function e / pow((1.0 + a * exp(-b * (x-c)) 
),(1.0/d)) three times to get an (rgb)-triplet. However, I have no clue how to 
dump the function into a texture without hand-crafting every pixel.

Finally, I think given that we have cloud position and sizes available, it'd be 
fairly trivial to cast that into a function that defines a shadow-map for 
clouds (I would not render the clouds to create that map, first because of 
transparency, second because they're really billboards and likely to come out 
wrong, third because the map wouldn't change fast and finally because it's 
faster to do one analytical function per cloudlet than to go through the 40 
texture sheets that are in a cloudlet.

So, any pointers along that front would be appreciated for a number of 
reasons... Thanks in advance!

* Thorsten
--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


Re: [Flightgear-devel] Functions to textures?

2012-07-24 Thread Arnt Karlsen
On Tue, 24 Jul 2012 07:02:44 +, Renk wrote in message 
e495a106ff5f31448739e79d34138c19196d3...@mbs1.ad.jyu.fi:

 First of all, a big thanks to Tim - Akenine-Moller Co. is indeed
 quite an interesting read, and in addition to gaining a better
 understanding, I've so far experimented successfully with a
 heightfield for parallax and normal mapping and a simple irrandiance
 map instead of the ambient term in lighting. 
 
 For those not inclined to read through a longer email, my question up
 front: I have a function, I want a texture holding the function
 values  pairs - how do I map this without editing every pixel
 offline? And can we do this also online? Where is for instance the 3d
 noise texture defined and filled - is it simple to change the
 procedure?
 
 For those interested in the context:
 
 I have managed to create quite compelling terrain visuals from
 close-up (see here
 http://www.flightgear.org/forums/viewtopic.php?f=47t=16884start=15#p162613
 for two examples), but rendering seems to get too slow too soon for
 anything really fancy (of course, a big roadblock is that I'm
 implementing all this on top of atmospheric light scattering which is
 slow to begin with - I think in the default light and fog scheme it
 might run with decent speed).
 
 One problem that really kills framerate is de-tiling. In order to
 de-tile properly, one needs to mix noise from different wavelengths
 such that the interference creates a pattern with a much larger
 periodicity. Three wavelengths usually do the job well, two are
 marginally acceptable, one is quite bad.
 
 So, for each texture component (snow, gradient texture, detailed
 texture, height map, fog) I ideally need three noise wavelengths. In
 the current 3d noise, noise[0] contains structures with a
 qualitatively different distribution, so I have to discard that
 component. noise[3] is too fine and runs into texture resolution
 problems, so I have to discard that as well. Since the noise pattern
 associated with different texture components needs to be uncorrelated
 (otherwise there's yet another form of tiling around the corner) I
 need to do different noise lookups for every texture component,
 arranging them in a slightly different wavelength interval.
 
 And that's a lot of texture3D() calls which really make the system
 slow.
 
 I could do it in half the time if I would get 4 useful components for
 every texture3D() call, but that requires that I either create a
 suitable texture offline or change the way it is done in the code
 (I'm also exploring if there is perhaps a function that evaluates
 faster than a texture lookup call...).
 
 Somewhat inversely, I'm also wondering if a simple texture1D() lookup
 might not be faster than evaluating the light function e / pow((1.0 +
 a * exp(-b * (x-c)) ),(1.0/d)) three times to get an (rgb)-triplet.
 However, I have no clue how to dump the function into a texture
 without hand-crafting every pixel.
 
 Finally, I think given that we have cloud position and sizes
 available, it'd be fairly trivial to cast that into a function that
 defines a shadow-map for clouds (I would not render the clouds to
 create that map, first because of transparency, second because
 they're really billboards and likely to come out wrong, third because
 the map wouldn't change fast and finally because it's faster to do
 one analytical function per cloudlet than to go through the 40
 texture sheets that are in a cloudlet.
 
 So, any pointers along that front would be appreciated for a number
 of reasons... Thanks in advance!

..maybe this is a place for Lisp?
http://www.paulgraham.com/icad.html
http://www.paulgraham.com/avg.html

-- 
..med vennlig hilsen = with Kind Regards from Arnt Karlsen
...with a number of polar bear hunters in his ancestry...
  Scenarios always come in sets of three: 
  best case, worst case, and just in case.

--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


Re: [Flightgear-devel] Functions to textures?

2012-07-24 Thread Chris Forbes
 Somewhat inversely, I'm also wondering if a simple texture1D() lookup might 
 not be faster than evaluating the light function e / pow((1.0 + a * exp(-b * 
 (x-c)) ),(1.0/d)) three times to get an (rgb)-triplet.

That depends a lot on the GPU, and how coherent the texture
coordinates are across a triangle. You also need enough ALU work
elsewhere in the shader to mask the latency of the texture lookup.

For the existing noise texture generation, take a look at
make3DNoiseImage in scene/material/TextureBuilder.cxx in the simgear
tree. This particular texture is filled CPU-side, but if you're more
comfortable expressing things in a shader, you/someone could rig up
some FBO wiring to quickly render a shader-defined function into a
texture.

-- Chris

--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


Re: [Flightgear-devel] Functions to textures?

2012-07-24 Thread Tim Moore
On Wed, Jul 25, 2012 at 12:16 AM, Chris Forbes chr...@ijw.co.nz wrote:
 Somewhat inversely, I'm also wondering if a simple texture1D() lookup might 
 not be faster than evaluating the light function e / pow((1.0 + a * exp(-b * 
 (x-c)) ),(1.0/d)) three times to get an (rgb)-triplet.

 That depends a lot on the GPU, and how coherent the texture
 coordinates are across a triangle. You also need enough ALU work
 elsewhere in the shader to mask the latency of the texture lookup.

 For the existing noise texture generation, take a look at
 make3DNoiseImage in scene/material/TextureBuilder.cxx in the simgear
 tree. This particular texture is filled CPU-side, but if you're more
 comfortable expressing things in a shader, you/someone could rig up
 some FBO wiring to quickly render a shader-defined function into a
 texture.

Actually, the code that creates the texture is in
scene/util/StateAttributeFactory.cxx, but you would have to do
something similar to the noise texture code in TextureBuilder to
access your texture from a texture. It would be nice if the Effects
framework had a way to load arbitrary textures and make them available
to effects.

 These days you aren't limited to 8 bit texture components. There is a
rich set of data formats for textures: 32 bit floats, 16 bit floats,
exotic combinations of different length floats per RGB component... I
don't know if there is a better way to create your texture offline
than write C++ code in simgear. OSG will read a TIFF file with 32bits
per component as a floating point texture... assuming you can create
such a thing.

Tim

--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel