Hi
i'm new using DirectX for image processing.
I'm looking to convert this code tutorial to be DX10 compatible.
In the compiler i'm using visual studio 2012. I get an error with current code "DX9 compatible mode is disabled".
From the blog it mentioned I should switch back to shader model 3.0 .... i'm not keen.
So I decided I will convert the original code and make it compatible with the compiler which uses shader model 4 or greater
The original code in HLSL looks like:
sampler InputImage;
float2 sampleOffsets[8] : register (c10);
struct PS_INPUT
{
float2 texCoord:TEXCOORD0;
};
float4 main( PS_INPUT In ) : COLOR
{
int i =0;
float4 result;
float Magnitude, Theta;
float p=0,q=0;
float pKernel[4] = {-1, 1, -1, 1};
float qKernel[4] = {-1, -1, 1, 1};
float2 texCoords[4];
float3 texSamples[4];
float PI = 3.1415926535897932384626433832795;
texCoords[0] = In.texCoord + sampleOffsets[1];
texCoords[1] = In.texCoord + sampleOffsets[2];
texCoords[2] = In.texCoord;
texCoords[3] = In.texCoord + sampleOffsets[4];
for(i=0; i <4; i++)
{
texSamples[i].xyz = tex2D( InputImage, texCoords[i]);
texSamples[i] = dot(texSamples[i], 0.33333333f);
p += texSamples[i] * pKernel[i];
q += texSamples[i] * qKernel[i];
}
p /= 2.0;
q /= 2.0;
Magnitude = sqrt((p*p)+(q*q));
result = Magnitude;
// Now we compute the
// line to prep for Nonmaxima supression
// Nonmaxima supression - If this texel isn
//
// make it 0 (hence, supress it) -pi to pi
Theta = atan2(q,p); // result is
result.a = (abs(Theta) / PI);
// Now result
// Just so it can be write
return result;
}
Revised code looks like:
//////////////////////
//// GLOBALS
//////////////////////
Texture2D diffuseTexture : register(t0);
SamplerState diffuseTextureSampler : register(s0);
float2 sampleOffsets[8] : register (t1);
//////////////////////
//// TYPES
//////////////////////
struct PixelInputType
{
float4 position : SV_POSITION;
float2 texCoord : TEXCOORD0;
float4 color : COLOR;
};
//////////////////////
//// Pixel Shader
/////////////////////
float4 main(PixelInputType input) : SV_Target
{
int i =0;
int count = 4;
float4 result;
float Magnitude, Theta;
float p=0,q=0;
float4 pKernel = {-1, 1, -1, 1};
float4 qKernel = {-1, -1, 1, 1};
float2 texCoords[4];
float3 texSamples[4];
float PI = 3.1415926535897932384626433832795;
texCoords[0] = input.texCoord + sampleOffsets[1];
texCoords[1] = input.texCoord + sampleOffsets[2];
texCoords[2] = input.texCoord;
texCoords[3] = input.texCoord + sampleOffsets[4];
for(i=0; i <4; i++)
{
texSamples[i] = diffuseTexture.Sample( diffuseTextureSampler, float2(texCoords[i])).xyz;
texSamples[i] = dot(texSamples[i], 0.33333333f);
p += float4(texSamples[i],0) * pKernel[i];
q += float4(texSamples[i],0) * qKernel[i];
}
p /= 2.0;
q /= 2.0;
Magnitude = sqrt((p*p)+(q*q));
result = Magnitude;
// Now we compute the line to prep for Nonmaxima supression
// Nonmaxima supression - If this texel is not
// make it 0 (hence, supress it) -pi to pi
Theta = atan2(q,p); // result is
result.a = (abs(Theta) / PI);
// Now result
// Just so it can be write
return result;
}
However when I compile the revised code, I get a warning - " implicit truncation vector code" in the loop.
p += float4(texSamples[i],0) * pKernel[i];
q += float4(texSamples[i],0) * qKernel[i];
i'm not sure why the compiler's still complaining but my cue is its still not compatible.
Advice welcome on how to make the original code more complaint?