I just seem to be full of problems. This quite a learning experience for me (albeit frustrating).
For some reason, I have shaders that are being set in my effect file but not being executed. My effect file looks like so:
float4 viewportScale;
float4 viewportBias;
struct INPUT_PPVS {
float4 pos : POSITION;
float2 texCoord : TEXCOORD0;
};
struct OUTPUT_PPVS {
float4 pos : POSITION;
float2 texCoord : TEXCOORD0;
};
OUTPUT_PPVS ppvs(INPUT_PPVS v) {
OUTPUT_PPVS o = (OUTPUT_PPVS) 0;
o.pos = v.pos * viewportScale + viewportBias;
o.texCoord = v.texCoord;
return o;
}
float2 filterSamples[12];
struct INPUT_PPPS {
float2 texCoord : TEXCOORD0;
};
float4 ppps(INPUT_PPPS v) : COLOR {
float4 totalColor = tex2D(ColorMapSampler,v.texCoord); //samplers made earlier
float totalCont = 1.0;
float2 depthBlur = tex2D(DepthBlurMapSampler,v.texCoord);
float cocSize = depthBlur.y * maxCOC;
for (int i = 0; i < 12; i++) {
float2 sampleCoord = v.texCoord + filterSamples * cocSize;
float4 sampleColor = tex2D(ColorMapSampler,sampleCoord);
float2 sampleDepthBlur = tex2D(DepthBlurMapSampler,sampleCoord);
float sampleCont = (sampleDepthBlur.x > depthBlur.x) ? 1.0 : sampleDepthBlur.y;
totalColor += sampleColor * sampleCont;
totalCont += sampleCont;
}
return (totalColor/totalCont);
}
vertexshader postprocessvs = compile vs_2_0 ppvs();
pixelshader postprocessps = compile ps_2_0 ppps();
technique SimCOC {
pass P0 {
...
}
pass P1 {
Sampler[0] = (ColorMapSampler);
Sampler[1] = (DepthBlurMapSampler);
ZEnable = False;
fvf = XYZW | Tex1;
vertexshader = (postprocessvs);
pixelshader = (postprocessps);
}
}
In my rendering code I have tried two things for drawing: one using vertices stored in a vertex buffer, and the other using DrawPrimitiveUP using an array of vertices. Here is what the rendering code looks like:
//effect->Begin done elsewhere
effect->SetTexture("colorMap",colorMap);
effect->SetTexture("depthBlurMap",depthBlurMap);
if(SUCCEEDED(device->BeginScene())) {
effect->BeginPass(1);
device->SetStreamSource(0,vb,0,sizeof(Vertex));
device->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2);
effect->EndPass();
device->EndScene();
}
effect->End();
I've also tried this:
effect->SetTexture("colorMap",colorMap);
effect->SetTexture("depthBlurMap",depthBlurMap);
Vertex vertices[] = {{0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f},
{1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f},
{1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f},//x,y,z,w,u,v
{0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f}};
if(SUCCEEDED(device->BeginScene())) {
effect->BeginPass(1);
device->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, &vertices, sizeof(Vertex));
effect->EndPass();
device->EndScene();
}
effect->End();
The first way neither of the shaders executes. In the second way, the vertex shader will sometimes execute, but only if the pixel shader is deactivated or does next to nothing. The pixel shader runs normally only if the vertex shader is skipped over. What in the world is going on?
[Edited by - ChopperDave on April 17, 2006 12:11:45 AM]