Problem with ParallaxMapping
I have tried to use the ParallaxMapping effect from coding4fun.
But the effect only workt correctly in the FX Composer, in the app i have exactly the same parameters but it looks very different:
http://img509.imageshack.us/my.php?image=unbenannt4ri4.jpg
Has anybody an idea what could be wrong?
Code:
create mesh.box
set vertax coordinats
set vertax elements
set effect parameters
effect beginn
Are you generating a tangent basis for each of your vertices? Parallax mapping won't work correctly without proper normals, binormals, and tangent vectors.
I do not know whether it is right, but a normal bumpmap works.
I initialize the box that way:
boden = Mesh.Box(device, 10.0f, 1.15f, 10.0f);
VertexFormats format = VertexFormats.PositionNormal | VertexFormats.Texture1;
Mesh tempBox = boden.Clone(boden.Options.Value, format, device);
boden.Dispose();
boden = tempBox;
CustomVertex.PositionNormalTextured[] verts2 =(CustomVertex.PositionNormalTextured[])boden.VertexBuffer.Lock(0,typeof(CustomVertex.PositionNormalTextured), LockFlags.None, boden.NumberVertices);
for (int i = 0; i < verts2.Length; ++i)
{
if (i >= 0 && i <= 3)
{
verts2.Tv = verts2.Y * 0.3f;
verts2.Tu = verts2.Z * 0.3f;
}
else if (i >= 4 && i <= 7){ ...}
boden.VertexBuffer.Unlock();
VertexElement[] elements = new VertexElement[]
{
new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0),
new VertexElement(0, 12, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Normal, 0),
new VertexElement(0, 24, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0),
new VertexElement(0, 36, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Tangent, 0),
new VertexElement(0, 48, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.BiNormal, 0),
VertexElement.VertexDeclarationEnd,
};
VertexDeclaration decl = new VertexDeclaration(device, elements);
Mesh tempMesh = boden.Clone(MeshFlags.Managed, elements, device);
boden.Dispose();
boden = tempMesh;
I initialize the box that way:
boden = Mesh.Box(device, 10.0f, 1.15f, 10.0f);
VertexFormats format = VertexFormats.PositionNormal | VertexFormats.Texture1;
Mesh tempBox = boden.Clone(boden.Options.Value, format, device);
boden.Dispose();
boden = tempBox;
CustomVertex.PositionNormalTextured[] verts2 =(CustomVertex.PositionNormalTextured[])boden.VertexBuffer.Lock(0,typeof(CustomVertex.PositionNormalTextured), LockFlags.None, boden.NumberVertices);
for (int i = 0; i < verts2.Length; ++i)
{
if (i >= 0 && i <= 3)
{
verts2.Tv = verts2.Y * 0.3f;
verts2.Tu = verts2.Z * 0.3f;
}
else if (i >= 4 && i <= 7){ ...}
boden.VertexBuffer.Unlock();
VertexElement[] elements = new VertexElement[]
{
new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0),
new VertexElement(0, 12, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Normal, 0),
new VertexElement(0, 24, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0),
new VertexElement(0, 36, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Tangent, 0),
new VertexElement(0, 48, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.BiNormal, 0),
VertexElement.VertexDeclarationEnd,
};
VertexDeclaration decl = new VertexDeclaration(device, elements);
Mesh tempMesh = boden.Clone(MeshFlags.Managed, elements, device);
boden.Dispose();
boden = tempMesh;
Cloning a mesh with new vertex elements will not fill in those elements, they will be empty. You have to fill in the appropriate values for the normal, tangent, and binormal at each vertex. Mesh.ComputeTangentFrame can calculate all 3 for you.
However I feel I should mention that ManagedDX is no longer being developed or supported, so you may want to consider using either the XNA Framework or the community-managed SlimDX.
However I feel I should mention that ManagedDX is no longer being developed or supported, so you may want to consider using either the XNA Framework or the community-managed SlimDX.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement