In finally giving in and switching to HLSL from VS/PS assembly to solve a signed value problem in my simple tweening application, I have created the following effect file which seems to compile fine, but does not end up drawing anything:
//uniform variables set by the app:float4x4 world,view,proj;texture modelTexture;float tweenFactor;float4 diffuseDir;float4 ambientColor;float4 diffuseColor;float4 diffuseAmbientDiff;sampler2D modelTextureSampler=sampler_state{// Texture sampler Texture=(modelTexture); MIPFILTER=LINEAR; MAGFILTER=LINEAR; MINFILTER=LINEAR;};struct A2V{//Application to vertex shader float4 pos0:POSITION0; float4 norm0:NORMAL0; float2 texCoord0:TEXCOORD0; float4 pos1:POSITION1; float4 norm1:NORMAL1; float2 texCoord1:TEXCOORD1;};struct V2P{//Vertex shader to pixel shader float4 position:POSITION0; float2 texCoord:TEXCOORD0; float4 norm:TEXCOORD1;};void VS(in A2V IN,out V2P OUT){ float4x4 worldViewProj=world*view*proj; OUT.position=mul(lerp(IN.pos0,IN.pos1,tweenFactor),worldViewProj);//Tween between both positions and project to final coordinates OUT.norm=mul(lerp(IN.norm0,IN.norm1,tweenFactor),worldViewProj);//Tween between both norms and project to final coordinates OUT.texCoord=lerp(IN.texCoord0,IN.texCoord1,tweenFactor);//Tween between texture coordinates}float4 PS(in V2P IN):COLOR{ IN.norm=normalize(IN.norm);//perhaps superfluous; needs testing float NdotL=saturate(dot(IN.norm,diffuseDir));//dot norm with diffuse direction float4 diffuse=NdotL*diffuseColor*diffuseAmbientDiff; return diffuse+ambientColor;}technique Tween{ pass p0{ vertexshader=compile vs_2_0 VS(); pixelshader=compile ps_2_0 PS(); }}
And here are the relevant lines of C++ that call it:
//Init:ID3DXEffect* tweenEffect;if(FAILED(D3DXCreateEffectFromFileW(graphDevice,L"tween.fx",NULL,NULL,NULL,NULL,&tweenEffect,&fehlerMsgs))){ //(Log debug info)}//Then for each model:tweenEffect->SetTechnique("Tween");//used to use device->SetVertexShader() and SetPixelShader()tweenEffect->SetMatrix("proj",&matr);//Used to be SetVertexShaderConstantF()tweenEffect->SetMatrix("view",&matr);//Used to be SetVertexShaderConstantF()tweenEffect->SetMatrix("world",&bMat);//Used to be SetVertexShaderConstantF()tweenEffect->SetTexture("modelTexture",tex[mesh[m][dw].texture]);//was IDirect3DDevice9::SetTexture() beforetweenEffect->SetVector("ambientFarbe",&D3DXVECTOR4(tweenMat.Ambient.r,tweenMat.Ambient.g,tweenMat.Ambient.b,tweenMat.Ambient.a*alpha));//Was SetPixelShaderConstantF()tweenEffect->SetVector("diffuseFarbe",&D3DXVECTOR4(tweenMat.Diffuse.r,tweenMat.Diffuse.g,tweenMat.Diffuse.b,tweenMat.Diffuse.a*alpha));//Was SetPixelShaderConstantF()tweenEffect->SetVector("diffuseAmbientDiff",&D3DXVECTOR4( tweenMat.Diffuse.r-tweenMat.Ambient.r, tweenMat.Diffuse.g-tweenMat.Ambient.g, tweenMat.Diffuse.b-tweenMat.Ambient.b, tweenMat.Diffuse.a*alpha-tweenMat.Ambient.a*alpha ));//Was SetPixelShaderConstantF() tweenEffect->SetFloat("tweenFactor",tween);//Was SetVertexShaderConstantF() tweenEffect->Begin(&passes,0);for(p=0;p<passes;p++){ tweenEffect->BeginPass(p); graphDevice->SetStreamSource(0,bauartVB[m][dw],0,sizeof(MVERTEX));//hasn't changed graphDevice->SetStreamSource(1,bauartVB[m2][dw],0,sizeof(MVERTEX));//hasn't changed graphDevice->SetIndices(bauartIB[m][dw]);//hasn't changed graphDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,modelNumV[m][dw],0,modelNumI[m][dw]);//hasn't changed tweenEffect->EndPass();}
I have directx on debug mode with maximum output, and nothing relevant seems to come in the message window of Visual Studio (then again, nothing complained even when I did have variable names wrong in SetFloat() that didn't match the names in the shader). Parts of the scene not drawn with the shader, ie. fixed-function line lists and text fonts, are still drawn fine. Something glaringly missing? If you'd like me to post the old code that worked, let me know.
I'm on a Dell Studio laptop, i5 proc, ATI Radeon 1GB RAM, DirectX 9.0c SDK (June 2010) on Visual Studio 2010 Express.
Thanks.
--
Bababooey