some clarifications please
Is this correct? A vertex shader has to be applied to an entire object (mesh). A pixel Shader has to be applied to the entire object, or a material? Can a material on one mesh have a different pixel shader from another on the same mesh?
A vertex shader is applied to all vertices sent by the DrawPrimitive calls during which the vertex shader is set, and the pixel shader is applied to all pixels that result from rasterizing the vertices from the vertex shader.
It's very easy to have two portions of your mesh have different shaders. Just set your shaders and then render the first portion with a draw primitive call, and then set your next shaders and issue your second draw primitive call.
It's very easy to have two portions of your mesh have different shaders. Just set your shaders and then render the first portion with a draw primitive call, and then set your next shaders and issue your second draw primitive call.
why is it that i never see any of these calls in any samples or anything? I really hate this shader system. Is there a way to just generically load shaders? There all of these vertex structures, shader constants etc etc are driving me crazy. The only thing I have been abel to do is this
I have no idea what to do next. I dont know how to set shader constants, I dont know how to set up vertex structures, and dont know how to render the effect with passes and the samples are all different from each other. This is just vertex shading. I havn't even started on pixel shaders.
void SceneObject::SetEffect(char* m_effectname){if(m_effectname == NULL) m_effectname = "./Assets/default.fx"; ID3DXBuffer *errorBuffer = NULL; HRESULT result = D3DXCreateEffectFromFile( g_engine->GetDevice(), m_effectname, NULL, NULL, D3DXSHADER_DEBUG, NULL, &m_effect, &errorBuffer ); if( result != D3D_OK ) { const char *error = NULL; if( errorBuffer ) error = (const char*)errorBuffer->GetBufferPointer(); else error = ("Error loading effect file."); MessageBox( NULL, error, "Error", MB_OK ); // Display any errors. }
I have no idea what to do next. I dont know how to set shader constants, I dont know how to set up vertex structures, and dont know how to render the effect with passes and the samples are all different from each other. This is just vertex shading. I havn't even started on pixel shaders.
Its actually very simple and straightforward, I'm not sure what exactly is giving you trouble, but here is a quick run-down:
Use the FX format and D3DXEFFECT interface.
First load the effect as your code shows.
When you want to draw something with an effect you can set the textures like this:
eff->SetTexture("name_of_texture_in_fx_file", texpointer);
set things like vectors and matrices like this:
eff->SetVector("name_of_float4_in_fx_file", &yourvector );
eff->SetMatrix("name_of_float4x4_in_fx_file", &yourmatrix);
fx files are broken into "techniques" so you must select a technique like this:
eff->SetTechnique( "yourtechnique" );
then draw (this does only one pass, so if your technique has more passes you need to do some other stuff):
eff->Begin( 0, 0 );
eff->BeginPass( 0 );
mesh->DrawSubset( 0 ); //draw something..can be anything, even D3DXSprites
eff->EndPass();
eff->End();
...and that's it basically. You can find lots of sample effect files around.
Obviously more sophisticated apps may not explicitly state the name of textures, constants, etc, but use handles and so on, but is the most straightforward method.
Remember, when explicitly setting textures and constants the name you give in the string must match exactly with what the texture and constant are called in the fx file. You can set texture and constants at any time, but if you do it after you have called effect->Begin you must then call effect->CommitChanges.
------------------------------------------------------------------------------
You mentioned vertex structures and so on, this is important, but most meshes and other vertex data use a pretty consistent vertex format...this means shaders might have a similar input structure like:
VS_OUT VS(
float4 inPos : POSITION,
float3 inNormal : NORMAL,
float2 inTex : TEXCOORD0,
)
obviously some meshes or vertex data have other data like tangents, binormals, additional texture coords, etc...if you use such things you will know what they are...
Use the FX format and D3DXEFFECT interface.
First load the effect as your code shows.
When you want to draw something with an effect you can set the textures like this:
eff->SetTexture("name_of_texture_in_fx_file", texpointer);
set things like vectors and matrices like this:
eff->SetVector("name_of_float4_in_fx_file", &yourvector );
eff->SetMatrix("name_of_float4x4_in_fx_file", &yourmatrix);
fx files are broken into "techniques" so you must select a technique like this:
eff->SetTechnique( "yourtechnique" );
then draw (this does only one pass, so if your technique has more passes you need to do some other stuff):
eff->Begin( 0, 0 );
eff->BeginPass( 0 );
mesh->DrawSubset( 0 ); //draw something..can be anything, even D3DXSprites
eff->EndPass();
eff->End();
...and that's it basically. You can find lots of sample effect files around.
Obviously more sophisticated apps may not explicitly state the name of textures, constants, etc, but use handles and so on, but is the most straightforward method.
Remember, when explicitly setting textures and constants the name you give in the string must match exactly with what the texture and constant are called in the fx file. You can set texture and constants at any time, but if you do it after you have called effect->Begin you must then call effect->CommitChanges.
------------------------------------------------------------------------------
You mentioned vertex structures and so on, this is important, but most meshes and other vertex data use a pretty consistent vertex format...this means shaders might have a similar input structure like:
VS_OUT VS(
float4 inPos : POSITION,
float3 inNormal : NORMAL,
float2 inTex : TEXCOORD0,
)
obviously some meshes or vertex data have other data like tangents, binormals, additional texture coords, etc...if you use such things you will know what they are...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement