Horde3D

Next-Generation Graphics Engine
It is currently 23.11.2024, 04:34

All times are UTC + 1 hour




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: 05.01.2009, 01:48 
Offline

Joined: 04.01.2009, 00:34
Posts: 3
Hi everyone.

I'm new to Horde3D. I have been using Jun OpenGL on VisualWorks for many years, and want something better.

I'm building an external interface between VisualWorks (VW) Smalltalk and the Horde3D.dll and Horde3dUtils.dll libraries, which I've just built. I'm looking for examples that show how to use the two libraries to setup an OpenGL window (this seems to be done mostly with Horde3DUtils) and to construct a multiviewport scene in that window.

I have read through most of the doc, but am still wanting general guidelines on scene construction strategies--things always to do, things never to do, invariants concerning scene construction, and similar.

The most useful example I can think of now would be a program in any language (C/C++ is OK) using the APIs in the two libraries to place a single primitive, say, a sphere or cube in a scene with a light and a camera. I've checked-out source from https://horde3d.svn.sourceforge.net/svnroot/horde3d and am looking at the Knight example. My application is less about gaming and more about scientific visualization and educatiion. I need to choreograph the movements of primitives and cameras programmatically. I have not used the editor yet, but suppose that this does not allow us to specify scene transformation scenarios (including camera moves).

Needed geometric resources, for the time being, are the sphere, cube, and parallelipiped. Instances of the first two will be simply colored; the last will be textured. Has anyone created textures for wood and stone?

All resources in H3D seem to be described by XML documents. Can anyone suggest the simplest way to make a cube and a sphere on the fly, programmatically, without using a DCC like Maya? I am used to using a Quadric and gluSphere, but these now seem to be the wrong choice in a shader-based framework.

Does anyone have a working 2D GUI that I can overlay on a 3D scene? I need the usual buttons, lists, sliders, etc.

Apart from how text would be displayed in a flat GUI, does anyone have experience using TT fonts with Horde3D to place text in overlays on a 3D scene, whilst translating/scaling the text? The dynamic text must look very smooth in all respects. I'll be using the best antialiasing settings.

All suggestions are welcome.

Regards,

Shaping


Top
 Profile  
Reply with quote  
PostPosted: 08.01.2009, 13:52 
Offline

Joined: 08.11.2006, 03:10
Posts: 384
Location: Australia
Shaping wrote:
I have read through most of the doc, but am still wanting general guidelines on scene construction strategies--things always to do, things never to do, invariants concerning scene construction, and similar. I need to choreograph the movements of primitives and cameras programmatically.
I created a C++ class called Node which is the base class for several other classes: GroupNode, ModelNode, MeshNode, JointNode, EmitterNode, LightNode, CameraNode and TerrainNode.

The constructors of these classes call Horde3D functions like: addGroupNode, addNodes, addModelNode, etc. in order to create the actual node within the Horde scene-graph. These classes have only one member variable, which contains an integer handle to Horde's node.

The constructors place constraints on how nodes can be created.
E.g. A terrain node can be constructed with a GroupNode to act as the parent in the scene, and a SceneGraph-resource to load the actual TerrainNode from (this resource must contain a Terrain node at it's root, or construction will fail).
A Joint node must use a Model node as the parent, and a name and index must be supplied.
A Camera node can only attach to a group node, and requires a name and a Pipeline resource.
Code:
      TerrainNode( const GroupNode& pParent, const SceneGraph& );
      JointNode( const ModelNode& pParent, const std::string& name, uint index );
      CameraNode( const GroupNode& pParent, const std::string& name, const Pipeline& res );


These classes provide member functions which use their handle to call Horde3D functions like setNodeParamf.

Shaping wrote:
Needed geometric resources, for the time being, are the sphere, cube, and parallelipiped. Instances of the first two will be simply colored; the last will be textured. ... Can anyone suggest the simplest way to make a cube and a sphere on the fly, programmatically, without using a DCC like Maya?
The user manual describes the binary layout of the horde geometry files and the XML layout of model/scene files. With a bit of study is should be possible to programmatically generate these files within the language of your choice. Horde's resource loading model is abstracted, so if data buffers are present in memory (as opposed to a file on the disc) it is very simple to load the data into the Horde engine.

Shaping wrote:
Does anyone have a working 2D GUI that I can overlay on a 3D scene? I need the usual buttons, lists, sliders, etc.
There's a topic about integrating Horde3D with AntTweakbar, which is a very utilitarian GUI. Most GUI libraries that contain an OpenGL renderer should be able to be integrated though..

Shaping wrote:
Apart from how text would be displayed in a flat GUI, does anyone have experience using TT fonts with Horde3D to place text in overlays on a 3D scene, whilst translating/scaling the text? The dynamic text must look very smooth in all respects. I'll be using the best antialiasing settings.
I haven't done this with Horde3D, but on Gamebryo I implemented smooth/scalable fonts using a series of quads with a grey-scale texture map and a fragment shader.
The paper at http://www.valvesoftware.com/publications/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf describes both a pre-processing step and the rendering (shader) technique.
To create the texture files:
1.1) I used a Win32 program to render each glyph/character to a high resolution 1 bit-per-pixel bitmap (e.g. 8196x8196)
1.2) Record the corner positions of each glyph for use as texture coordinates later.
2) Calculate a high resolution (floating-point) distance field from the bitmap.
3) Scale the field down to a lower resolution (e.g. 256x256) using a decent filter (e.g. box/liner, not point/NN!)
4) Encode the field in a 8 bit-per-pixel bitmap ( (clamp(f/range, -1, 1)+1)/2.0 * 255 )
To render the text:
1) Use the glyph texture coordinates to create 1 quad per character, using the distance field texture.
2) Write a fragment shader that samples the texture, and "discards" the fragment if the sample is less than 0.5 (0.5 represents the edge of the shape).
3) As well as being used to detect the edge, you can even use this texture-sample to programmatically generate efficient soft-shadows, outlines, color-gradients, etc for your text.


Top
 Profile  
Reply with quote  
PostPosted: 09.01.2009, 05:42 
Offline

Joined: 04.01.2009, 00:34
Posts: 3
DarkAngel wrote:
Shaping wrote:
I have read through most of the doc, but am still wanting general guidelines on scene construction strategies--things always to do, things never to do, invariants concerning scene construction, and similar. I need to choreograph the movements of primitives and cameras programmatically.
I created a C++ class called Node which is the base class for several other classes: GroupNode, ModelNode, MeshNode, JointNode, EmitterNode, LightNode, CameraNode and TerrainNode.

The constructors of these classes call Horde3D functions like: addGroupNode, addNodes, addModelNode, etc. in order to create the actual node within the Horde scene-graph. These classes have only one member variable, which contains an integer handle to Horde's node.

Quote:
The constructors place constraints on how nodes can be created.
E.g. A terrain node can be constructed with a GroupNode to act as the parent in the scene, and a SceneGraph-resource to load the actual TerrainNode from (this resource must contain a Terrain node at it's root, or construction will fail).

I need rigorous definitions, and do not see a glossary anywhere, just an API list. These details are great when you get down to coding, but without intermediate- and high-level concepts for organizing those details, I have trouble applying the details coherently--hence the orientation of this posting. On that node, is the scenegraph-resource a node also or by "resource" to you alway mean an "XML document"?
DarkAngel wrote:
Shaping wrote:
Apart from how text would be displayed in a flat GUI, does anyone have experience using TT fonts with Horde3D to place text in overlays on a 3D scene, whilst translating/scaling the text? The dynamic text must look very smooth in all respects. I'll be using the best antialiasing settings.
I haven't done this with Horde3D, but on Gamebryo I implemented smooth/scalable fonts using a series of quads with a grey-scale texture map and a fragment shader.
The paper at http://www.valvesoftware.com/publications/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf describes both a pre-processing step and the rendering (shader) technique.
Quote:
To create the texture files:
1.1) I used a Win32 program to render each glyph/character to a high resolution 1 bit-per-pixel bitmap (e.g. 8196x8196)
1.2) Record the corner positions of each glyph for use as texture coordinates later.
2) Calculate a high resolution (floating-point) distance field from the bitmap.
3) Scale the field down to a lower resolution (e.g. 256x256) using a decent filter (e.g. box/liner, not point/NN!)
4) Encode the field in a 8 bit-per-pixel bitmap ( (clamp(f/range, -1, 1)+1)/2.0 * 255 )
To render the text:
1) Use the glyph texture coordinates to create 1 quad per character, using the distance field texture.
2) Write a fragment shader that samples the texture, and "discards" the fragment if the sample is less than 0.5 (0.5 represents the edge of the shape).
3) As well as being used to detect the edge, you can even use this texture-sample to programmatically generate efficient soft-shadows, outlines, color-gradients, etc for your text.

I don't understand why we would do any of this except as an exercise of a step in building a framework for manipulating text smoothly. Why aren't we using TT fonts?


Last edited by Volker on 09.01.2009, 10:10, edited 1 time in total.
Fixed Quotes


Top
 Profile  
Reply with quote  
PostPosted: 09.01.2009, 22:37 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
Shaping, I don't want to discourage you from using Horde but for visualizing a few simple objects it could be an overkill. It can render complex scenes with an impressive quality but it requires you to have a good graphics (including shader) programming knowledge to do that. If you just need a few cubes without any eyecandy you won't have any benefit from Horde and I guess there are libraries which bring you faster to that goal.


Top
 Profile  
Reply with quote  
PostPosted: 10.01.2009, 01:57 
Offline

Joined: 08.11.2006, 03:10
Posts: 384
Location: Australia
Shaping wrote:
On that note, is the scenegraph-resource a node also or by "resource" to you alway mean an "XML document"?
In Horde, "resources" and "nodes" are distinctly different things. Resources are simply data loaded from disc, whereas nodes form the actual scene-graph (and reference many resources).
Check out the Resource management section of the manual for a description of each of the resource types. Take special note of the "SceneGraph" resource, which is used to create nodes.
The "Scene Graph" section which follows afterward is also required reading ;)

Also note that in the API listing, "scene graph functions" and "resource management functions" are well separated.

Shaping wrote:
I need rigorous definitions, and do not see a glossary anywhere, just an API list. These details are great when you get down to coding, but without intermediate- and high-level concepts for organizing those details, I have trouble applying the details coherently--hence the orientation of this posting.
The manual contains a lot more than the API listing. The sections that I mentioned above give a high-level view of the different resource and node types.

Shaping wrote:
I don't understand why we would do any of this except as an exercise of a step in building a framework for manipulating text smoothly. Why aren't we using TT fonts?
I chose to use this distance-field technique in our Gamebryo engine after having tried several approaches.
We were originally using basic texture-mapped fonts, which look terrible if stretched. We then tried using geometric/vector font rendering (glyphs made out of triangles instead of textures), but they often looked distorted due to bad AA quality. Finally we decided to use distance-fields, because after pre-processing they are as simple as basic tex-mapped fonts, but they have excellent quality.

Distance-field fonts can be scaled with very smooth edges, while remaining compatible with *any* graphics hardware that supports texture-mapping and alpha-testing.

Example font texture, the glyph for "1" is about 40px tall.
Example results, the glyph for "1" is about 320px tall (scaled 8x). Outline, blurred shadow, bevel and gradient effects are enabled.
Inspection of texture in photoshop showing imaginary line between "outside" and "inside" the shape.

To draw TT fonts natively, you would have to interpret the TT file-format yourself (or use a library like FreeType), extract the raster instructions or outline shape, convert into a 3D mesh, load this mesh into Horde, and then render the mesh.

So I guess I should answer your question with a question - why should we be using TT fonts? ;)
I don't mean to say that you shouldn't use TT fonts directly, but just that TT isn't always the best choice (hence why most games don't use them).

Basic Texture-mapped fonts (already supported via Horde3D Utils):
* Requires simple pre-processing tool (render TT to bitmap)
* Doesn't scale well
* Supports basic effects (shadow)
* 2 Triangles per glyph

Distance-field texture-mapped fonts:
* Requires complex pre-processing tool (render TT, calculate/compress distance field to bitmap)
* Scales very well
* Supports high quality effects (blurred shadow, outline, bevel)
* 2 Triangles per glyph

TT Geometry-based fonts:
* No pre-processing
* Requires TT file format parsing tool (calculate geometry from TT instructions)
* Interpreting the TT file format may require patent license fees
* Scales very well
* Requires AA support for decent quality
* Very many triangles per glyph
* Supports basic effects


Top
 Profile  
Reply with quote  
PostPosted: 11.01.2009, 07:46 
Offline

Joined: 19.03.2008, 01:22
Posts: 79
That's cool. First time i've heard of distance fields. I've played around with the technique and came up with a very simple method to generate them using Photoshop. First, an example result:

64x64 distance field:
Image


512x512 blowup of distance field, alpha tested:
Image

This was done easily with photoshop layer effects. Step by step:

1. Create a new high resolution image that will hold the distance field (I used 1024x1024 in the above example)
1. Use a black background
2. Put your high resolution shape in a layer above the black background. The shape needs to be transparent on the outside and a solid color on the inside.
3. Apply these layer effects to your shape layer:
- Color overlay (#808080, normal blend mode)
- Outer glow (#808080, normal blend mode, 100% opacity, technique:precise, spread:0, size:150)
- Inner glow (#FFFFFF, normal blend mode, 100% opacity, technique:precise, source:center, choke:0, size:150)
4. You can adjust the inner and outer glow size, but they must have the same value for best effect.
5. (optional) Use "Image->Reveal All" to resize the canvas to show all the glow parts.
6. Use "Image->Canvas Size" to make the image square (just copy the larger number over the smaller one and click ok)

At this point you can save this high resolution version of the distance field for archiving.

7. Use "Layer->Flatten Image" to bake all the effects in.
8. Resize the image down to something much smaller (preferably power of two size)
9. (optional) Use "Image->Mode->Grayscale" (flatten if prompted) to reduce file size.

Done! Save a copy of this small distance field and enjoy.

Bonus: you can get a preview of what the rendered distance field looks like inside photoshop:
1. Use "Layer->New Adjustment Layer->Threshold" and accept the default threshold value 128.
2. Put the threshold adjustment layer above the distance field layer so that it affects the layers beneath.
Simply toggle that new adjustment layer's visibility to turn the preview on/off.
3. Use "Image->Image Size" to scale up the image by some amount (like 800%), specify bilinear filtering to better approximate the result in your game.

Hope this comes in handy to someone :)


I should probably put this in the wiki?


Last edited by Vurlix on 11.01.2009, 20:31, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: 11.01.2009, 15:08 
Offline

Joined: 22.11.2007, 17:05
Posts: 707
Location: Boston, MA
Vurlix wrote:
That's cool. First time i've heard of distance fields. I've played around with the technique and came up with a very simple method to generate them using Photoshop.

This was done easily with photoshop layer effects. Step by step:

1. Create a new high resolution image that will hold the distance field (I used 1024x1024 in the above example)
1. Use a black background
2. Put your high resolution shape in a layer above the black background. The shape needs to be transparent on the outside and a solid color on the inside.
3. Apply these layer effects to your shape layer:
- Color overlay (#808080, normal blend mode)
- Outer glow (#808080, normal blend mode, 100% opacity, technique:precise, spread:0, size:150)
- Inner glow (#FFFFFF, normal blend mode, 100% opacity, technique:precise, source:center, choke:0, size:150)
4. You can adjust the inner and outer glow size, but they must have the same value for best effect.
5. (optional) Use "Image->Reveal All" to resize the canvas to show all the glow parts.
6. Use "Image->Canvas Size" to make the image square (just copy the larger number over the smaller one and click ok)

At this point you can save this large version of the distance field for archiving, resize the image down to something much smaller (preferably power of two size) and save that to your final image.

Bonus: you can get a preview of what the rendered distance field looks like inside photoshop:
1. Use "Layer->New Adjustment Layer->Threshold" and accept the default threshold value 128.
2. Put this layer above the distance field layer so that it affects the layers beneath.
Simply toggle that new adjustment layer's visibility to turn the preview on/off.

Hope this comes in handy to someone :)

I should probably put this in the wiki?
Woah, awesome! I messed around with Valve's method of distance field generation, but put it on a back burner because of the generation cost (can't run in real time). Pretty sure I could adapt you photoshop technique for real time use though - those glow effects can be done with GLSL and render to texture.

_________________
Tristam MacDonald - [swiftcoding]


Top
 Profile  
Reply with quote  
PostPosted: 11.01.2009, 15:56 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
Perhaps Vurlix can post his excellent description as a short tutorial to the wiki, and if swiftcoder is possible to realize the distance field calculation using GLSL shaders we can extend the article with that. Would be great!

I'm currently struggling with setting up my OpenSuse linux to finally finish the release of the editor version for 1.0.0 Beta2.


Top
 Profile  
Reply with quote  
PostPosted: 11.01.2009, 22:54 
Offline

Joined: 19.03.2008, 01:22
Posts: 79
I made a wiki article about distance field textures. Feel free to improve it :)


Top
 Profile  
Reply with quote  
PostPosted: 12.01.2009, 05:24 
Offline

Joined: 08.11.2006, 03:10
Posts: 384
Location: Australia
swiftcoder wrote:
Woah, awesome! I messed around with Valve's method of distance field generation, but put it on a back burner because of the generation cost (can't run in real time). Pretty sure I could adapt you photoshop technique for real time use though - those glow effects can be done with GLSL and render to texture.
I've implemented most of the standard Photoshop effects in HLSL before - but the best way I found to reproduce photoshop's glow effect was to use a distance field! :lol: (I did first write a brute force glow shader, but the distance-field glow shader was over 50x more efficient ;) )


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group