Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

Beginner fx problem

Started by briantsim Sep 26, 2006 at 5:38 AM 2 replies 500+ views
Original Post
briantsim
briantsim
Hi All, below is my fx file. ======================================================================== float4x4 worldViewProj : WORLDVIEWPROJ; struct a2v { float4 position : POSITION0; float2 texCoord : TEXCOORD0; }; //vertex to pixel shader structure struct v2p { float4 position : POSITION0; float4 color : COLOR0; }; technique simple { pass p0 { vertexshader = compile vs_1_1 vs(); } } ============================================================ below is my game code. ============================================================ public void Render() { try { renderer.BeginRender(Color.Blue); effect.SetValue("worldViewProj", matWorld *camera.MatView *camera.MatProj); effect.Technique = "simple"; effect.Begin(0); effect.BeginPass(0); renderer.Device.Material = mtrlFloor; renderer.Device.Transform.World = matFloor; renderer.Device.SetTexture(0, null); renderer.Device.SetTexture(0, floorTexture); floorMesh.DrawSubset(0); renderer.Device.Material = mtrlBox; renderer.Device.Transform.World = matBox; renderer.Device.SetTexture(0, null); renderer.Device.SetTexture(0, blockTexture); blockMesh.DrawSubset(0); effect.EndPass(); effect.End(); renderer.EndRender(); }catch (Exception) {} } i has 2 mesh in my Game Programmer. i want blockMesh move up and down not camera moveing. But my fx file set position in every time. What method can do this?
webjeff
webjeff
Hey:

Two things
1) What is in your vs function in the shader? You can post your entire shader, make sure to use "source" "/source" (replace "" with []) brackets

2) If thats working ok, then you just need to do stuff with your matWorld. Translate that up and down to move your mesh where you want. Your other mesh will have its own matWorld that you can move seperately too.

Let me know if you have more questions.

Jeff.
briantsim
briantsim
Hi All,

sorry below is my full fx code.
===========================================
float4x4 worldViewProj : WORLDVIEWPROJ;

struct a2v
{
float4 position : POSITION0;
};

struct v2p
{
float4 position : POSITION0;
};

void vs( in a2v IN, out v2p OUT )
{
OUT.position = mul(IN.position, worldViewProj);
}
technique simple
{
pass p0
{
vertexshader = compile vs_1_1 vs();
}
}
===========================================================
For example i want only blockMesh move not camera move. I can't use matWorld move my mesh up down. It is because my fx file set position in every time. What method can do this?
Namethatnobodyelsetook
Namethatnobodyelsetook
Setting the device's material and transforms do nothing when using a vertex shader. You must calculate the matrices your shader requires and use the set functions in the effect class to set your variables to these values.

Since your shader has worldViewProj, and not a world, and viewProj, you need to do more than just set the world matrix. You'll need to mix it with view and proj first.

D3DXMATRIX wvp = world * view * proj;
pEffect->SetMatrix("worldViewProj", &wvp); // note setting by name is slow

You won't have lighting, unless you implement it yourself in your shader. You'll need a place to store material settings, light settings, and code to calculate lighting.

Your texturing won't work as is, as you never pass your texcoord from your vertex input data to your vertex output structure.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.