Jump to content

  • Log In with Google      Sign In   
  • Create Account


Image processing D3D10 - implicit truncation vector type


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 bytefx   Members   -  Reputation: 102

Like
0Likes
Like

Posted 19 February 2013 - 06:37 PM

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?



Sponsor:

#2 MJP   Moderators   -  Reputation: 8741

Like
0Likes
Like

Posted 19 February 2013 - 09:12 PM

Your variables "p" and "q" are of type float, and you're trying to add a float4 to those variables. There's no meaningful way to add a float4 to a float, so the compiler truncates the float4 to a float. It also warns you about this, because it's almost always a bug. If you really intended to truncate your values then you should be explicit about it and add a swizzle. It looks like what you really want is this:

 

texSamples[i] = diffuseTexture.Sample( diffuseTextureSampler, float2(texCoords[i])).xyz;
float x = dot(texSamples[i], 0.33333333f);
p += x * pKernel[i];
q += x * qKernel[i]; 


#3 bytefx   Members   -  Reputation: 102

Like
0Likes
Like

Posted 20 February 2013 - 04:49 PM

Thanks. compiles with no complier warnings






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS