Jump to content
  • Advertisement
Sign in to follow this  
diego2k

HLSL metal.fx effect problem

This topic is 3661 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I am new to DirectX, so i have a problem with importing the metal.fx file from the fx-composer in my C# programm. The textures are wrongly placed on the sphere in my Programm but in the Fx Composer its okay: http://img397.imageshack.us/my.php?image=unbenanntjw9.jpg Code: balltextur = TextureLoader.FromFile(device, "Default_reflection.dds"); balltextur2 = TextureLoader.FromFile(device, "Default_color.dds"); ProjectionMatrix = Matrix.PerspectiveFovLH((float)Math.PI / 4, 1.0f, 1.0f, 100.0f); device.Transform.Projection = ProjectionMatrix; ViewMatrix = Matrix.LookAtLH(new Vector3(_kxx, 7.0f, _kzz), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f)); device.Transform.View = ViewMatrix; world = Matrix.Identity; world = Matrix.Translation(xx, yy, zz); world = Matrix.Scaling(5, 5, 5); device.Transform.World = world; effect.SetValue("gWorldXf", world); effect.SetValue("gWorldITXf", world * Matrix.Invert(world) * Matrix.TransposeMatrix(world)); effect.SetValue("gWvpXf", world * ViewMatrix * ProjectionMatrix); effect.SetValue("gViewIXf", Matrix.Invert(ViewMatrix)); effect.SetValue("gEnvTexture", balltextur); effect.SetValue("gColorTexture", balltextur); effect.SetValue("gEnvTexture", balltextur2); effect.Technique = "Textured"; int passes = effect.Begin(FX.None); for (int pass = 0; pass < passes; pass++) { effect.BeginPass(pass); box.DrawSubset(0); effect.EndPass(); } effect.End(); thx for help

Share this post


Link to post
Share on other sites
Advertisement
Does the mesh you're rendering in your app have texture coordinates?

Share this post


Link to post
Share on other sites
thx
now i have added texture coordinates, but with the coordinats the sphere looks terrible:
http://img145.imageshack.us/my.php?image=unbenannt2pd4.jpg

Code:

public bool InitializeGraphics()
{
....
effect = Effect.FromFile(device, @"dings.fx", null, null, ShaderFlags.None, null);
balltextur = TextureLoader.FromFile(device, "Default_reflection.dds");
balltextur2 = TextureLoader.FromFile(device, "Default_color.dds");

box = Mesh.Sphere(device, 0.5f, 32, 16);
using (VertexBuffer vb = box.VertexBuffer)
{
CustomVertex.PositionNormalTextured[] verts = (CustomVertex.PositionNormalTextured[])vb.Lock(0, typeof(CustomVertex.PositionNormalTextured), LockFlags.None, box.NumberVertices);

try
{
for (int i = 0; i < verts.Length; i++)
{
verts.Tu = Convert.ToSingle(Math.Asin(verts.Nx) / Math.PI + 0.5);
verts.Tv = -1 * Convert.ToSingle(Math.Asin(verts.Ny) / Math.PI + 0.5);
}
}finally{vb.Unlock();}
}

}
//-----------------

private void Render()
{
ProjectionMatrix = Matrix.PerspectiveFovLH((float)Math.PI / 4, 1.0f, 1.0f, 100.0f);
device.Transform.Projection = ProjectionMatrix;

ViewMatrix = Matrix.LookAtLH(new Vector3(_kxx, 7.0f, _kzz), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f));
device.Transform.View = ViewMatrix;

world = Matrix.Identity;
world = Matrix.Translation(xx, yy, zz);
world = Matrix.Scaling(5, 5, 5);
device.Transform.World = world;

effect.SetValue("gWorldXf", world);
effect.SetValue("gWorldITXf", world * Matrix.Invert(world) * Matrix.TransposeMatrix(world));
effect.SetValue("gWvpXf", world * ViewMatrix * ProjectionMatrix);
effect.SetValue("gViewIXf", Matrix.Invert(ViewMatrix));
effect.SetValue("gEnvTexture", balltextur);
effect.SetValue("gColorTexture", balltextur);
effect.SetValue("gEnvTexture", balltextur2);

effect.Technique = "Textured";

int passes = effect.Begin(FX.None);
for (int pass = 0; pass < passes; pass++)
{
effect.BeginPass(pass);
box.DrawSubset(0);
effect.EndPass();
}
effect.End();
}

Share this post


Link to post
Share on other sites
next problem: i want a bumpmapping effect, but Nvidia an ati have no standart effect. So I searched in the web, and i found this:
http://www.mdxinfo.com/tutorials/normalmapping.php

This is perfect, but the effect only work with the box.fx file und not with a normal mash.box. -> crash by box.DrawSubset(0);
Is there a possibility to get it to work?

init[
box = Mesh.FromFile("box.x", MeshFlags.Managed, device);

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 = box.Clone(MeshFlags.Managed, elements, device);

box.Dispose();
box = tempMesh;
]

render[
effect.Technique = "bump";
effect.SetValue("texture0", balltextur2);
effect.SetValue("texture1", balltextur);
effect.SetValue("ModelViewProj", world * ViewMatrix * ProjectionMatrix);
effect.SetValue("ModelViewIT", Matrix.TransposeMatrix( Matrix.Invert(world * ViewMatrix * ProjectionMatrix)));
effect.SetValue("ModelWorld", world);
float time = (float)(Environment.TickCount * 0.001);
effect.SetValue("lightPos", new Vector4((float)(30 * Math.Sin(time)), 0.0f, (float)(30 * Math.Cos(time)), 1.0f));

effect.Begin(0);
effect.BeginPass(0);
box.DrawSubset(0);
effect.EndPass();
effect.End();
]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!