Click or drag to resize
DigitalRuneFAQ
General

Debugging tips

Use the DebugRenderer to visualize debug information: bounding shapes, skeletons of skinned meshes, etc.

If you are using deferred lighting, visualize the intermediate render targets as shown in the samples.

To debug rendering problems or problems with effects use a graphics debugging tool, for example PIX for Windows, Visual Studio Graphics Diagnostics or NVIDIA Nsight.

Effects and effect bindings

How can I add an effect parameter for absolute time?

Here is the quick-and-dirty solution: Add the time parameter to the effect file:

C#
float time : TIME;

Load the mesh and manually set the time in every frame:

C#
var effectBinding = myMeshNode.Mesh.Materials[index]["render pass"];
effectBinding.Set("time", currentTimeInSeconds);

Or set a callback method once that automatically sets the current time:

C#
// Assuming there is a method GetCurrentTimeInSeconds() that returns the time
// as float, you can write the following:
var effectBinding = myMeshNode.Mesh.Materials[index]["render pass"];
effectBinding.Set("time", (binding, context) => GetCurrentTimeInSeconds());

Effect parameter binding is not working

If the effect parameter binding does not work, try this:

Lights

How should I handle LDR rendering and HDR rendering in the same game?

In HDR scenes you usually render the scene into a HdrBlendable render target. For best performance you should render LDR scenes into a Color render target. The light classes usually have Diffuse/SpecularIntensity properties and a HdrScale. Try to set the correct Diffuse/SpecularIntensity for the LDR scene and use the HdrScale to tweak the HDR scene.

For materials and particles you can also apply a custom "HdrScale" factor if necessary. (They do not have a built-in HdrScale property.)

PointLights/Spotlights/ProjectorLights are not working

Point lights, spotlight and projector lights should work automatically for opaque objects if you use deferred rendering, as shown in the deferred lighting samples. If you do not use deferred rendering, then it depends on the used effect. The XNA stock effects (e.g. BasicEffect, SkinnedEffect) and the built-in forward rendering effects of DigitalRune Graphics (e.g. DigitalRune/Materials/Forward, ForwardTwoSided) support only ambient lights and directional lights. That means, if you do not use deferred lighting or the object uses alpha-blending, you have to write your own effect which supports point lights.

Models and meshes

Can I load models from .STL/… files?

XNA supports .X and .FBX files. To load .STL files or other file formats, you need a XNA Content Importer or a custom loader. For common formats you will usually find an open source implementation or an example on the Internet.

How to create a mesh in code

See ProceduralObject.cs in the Samples.

Model appears only black

If all models are black, then please check if the 3D scene contains any light sources.

Sometimes exported models have a wrong alpha value of 0. Correct this in a 3D modeling tool or in set a correct alpha value (usually 1) in code after you have loaded the model.

Can I use the Shape of the ModelNode for collision tests?

The ModelNode is just a SceneNode that groups other SceneNodes. In most cases the ModelNode has child of type MeshNode. The Shape of the ModelNode is usually an EmptyShape. You can try to use the shape of the MeshNode. However, the Shape of a SceneNode is just a simple bounding shape - usually just a TransformedShape with a BoxShape or a SphereShape. For example, the bounding shape of the "Dude" model is just a fixed size box. The bounding shapes are used for frustum culling and scene queries. But the shapes are usually not accurate enough for physics or collision detection.

Miscellaneous

NotSupportedException: "XNA Framework HiDef profile requires TextureFilter to be Point when using texture format HdrBlendable/Vector4/..."

In XNA floating-point textures (e.g. surface format HdrBlendable, Vector4, etc.) can only be sampled with point sampling. Hardware filtering is not supported for floating-point textures. Therefore, effects which sample floating-point textures must set the sampler state to point filtering.

But sometimes the exception is thrown while rendering a mesh without a texture or with a normal texture. In this case, the problem might be that a previous renderer read from one or more floating-point textures and did not reset the texture stages of the graphics device. To solve the problem, call GraphicsHelperResetTextures(GraphicsDevice) before the render action which throws the exception.