• Advertisement
Sign in to follow this  

Using Effects/Techniques vs. Not using Effects

This topic is 755 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

I'm sure this question is trivial, but here goes.

 

Up till now, I've done everything I needed to do using Shaders without Effects. Now I've added a most basic Effect, with a single Technique, to my code and now I can't get anything to render to the screen.

 

I have the standard Begin,Beginpass,Endpass,End loop with DrawPrimitive within the loop. The thing that is most frustrating is that I also have a DrawPrimitive command outside of that loop. If I uncomment that line, so the code is just using the Shader, it renders fine. Based on that, I know that the vertex and associated set-up code is OK.

 

I have debug code set up so that I know that the Technique is being created, that I have acquired the global world view matrix variable within the technique code and that I am able to pass my WorldView matrix back to the Technique code. Also, with the debug code, I can verify that the code is looping through the technique, just not doing anything with it.

 

I've spent about a week on this, but I'm sure someone will come back with something trivial that I'm missing;

 

Any ideas on what can cause such behavior. Here's the code around the rendering loop and below that is the shader code, just taken from the Microsoft tutorial. Note that I'm just setting the WorldViewProj matrix to an identity matrix. This works when just using the Shader, is there something else that happens when using an Effect/Technique?

 

thanks!

 

Steve

 

 

UINT numPasses = 1;

 

mfx->Begin(&numPasses, 0);

 

for(UINT i = 0; i < numPasses; ++i)

{

mfx->BeginPass(i);

mfx->SetMatrix(h_mWorldViewProj,&identity);

mfx->CommitChanges();

 

g_pd3dDevice_1->SetVertexDeclaration(Decl);

g_pd3dDevice_1->SetStreamSource( 0, g_pVB_1, 0,

 

sizeof(CUSTOMVERTEX) );

HR = g_pd3dDevice_1->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 8 );

 

mfx->EndPass();

}

 

mfx->End();

 

//end c++ code

 

//begin shader code:

 

 

//-----------------------------------------------------------------------------

// File: HLSLwithoutEffects.vsh

//

// Desc: The effect file for the BasicHLSL sample. It contains a vertex

// shader which animates the vertices.

//

// Copyright (c) Microsoft Corporation. All rights reserved.

//-----------------------------------------------------------------------------

// note: variables that are declared, but not used in the code, will be removed when the code is compiled.

//-----------------------------------------------------------------------------

// Global variables

//-----------------------------------------------------------------------------

uniform extern float4x4 mWorldViewProj; // World * View * Projection transformation

 

//-----------------------------------------------------------------------------

// Vertex shader output structure

//-----------------------------------------------------------------------------

struct VS_OUTPUT

{

float4 Position : POSITION; // vertex position

float4 Diffuse : COLOR0; // vertex diffuse color

};

?

//-----------------------------------------------------------------------------

// Name: Ripple

// Type: Vertex shader

// Desc: This shader ripples the vertices

//-----------------------------------------------------------------------------

VS_OUTPUT Ripple(

 

float3 vPosition : POSITION, float4 color : COLOR0 )

{

VS_OUTPUT Output;

 

 

// This HLSL intrinsic computes returns both the sine and cosine of x

sincos( x, fSin, fCos );

Output.Position = mul(float4( vPosition.x, vPosition.y, vPosition.z, 1.0f ), mWorldViewProj );

Output.Diffuse = float4(0.0f, 0.0f, 0.0f, 1.0f);//color;

 

return Output;

}

 

float4 ColorPS(float4 c : COLOR0) : COLOR

{

 

return c;

 

}

 

Technique mytechnique

{

 

pass PO

{

 

 

//SetVertexShader( CompileShader( vs_2_0, Ripple()));

vertexShader = compile vs_2_0 Ripple();

pixelShader = compile ps_2_0 ColorPS();

FillMode = WIREFRAME;

CullMode = NONE;

 

}

}

?

Share this post


Link to post
Share on other sites
Advertisement

Never mind, found it. Funny how these things work. As I was reviewing the code I had posted, I noticed that I was passing an identity matrix into the technique in this line;

 

mfx->SetMatrix(h_mWorldViewProj,&identity);

 

where I should have been passing in the mWorldViewProj matrix variable created a few lines earlier in the code with this line;

 

D3DXMATRIX mWorldViewProj = identity*(matView)*(matProj);

 

Everything work great now!

 

Engineer, heal thyself!

 

Steve

Share this post


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

  • Advertisement