• Create Account

## .fx file error - Box comes out blue

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.

8 replies to this topic

### #1Narf the Mouse  Members

Posted 03 October 2012 - 08:51 AM

After some refactoring (that, among other things, added texturing by semantic), I ran my test display and the box came out blue.

Turns out, no matter what I've tried, it reads the red and green of the Material.Diffuse float4 as zero. Blue and Alpha are read properly. I'm setting the material in only one place, and commenting it out and changing the default values in the shader works exactly the same. The other colours in the in the material read properly.

The Effect file compilation code:
	SlimDX.Direct3D10.Effect.FromMemory(
graphicsDevice.Device,
memory,
"fx_4_0",
#if DEBUG
#else
#endif
SlimDX.D3DCompiler.EffectFlags.None) ) ;

And why does copy-pasting spaces no longer work? Makes formatting harder.

Effect file, cut down to the bare bones to show the problem (Yes, I know it's probably badly-written. I've ordered a book):
row_major matrix Projection ;
row_major matrix View ;
row_major matrix World ;
float3 CameraPosition ;

struct DrawMaterial
{
float4 Diffuse ;
float4 Emissive ;
float4 Specular ;
float4 SpecularExponent ;
} ;

cbuffer ColourSomething : register( c0 )
{
DrawMaterial Material = { float4( 1.0, 1.0, 1.0, 1.0 ), float4( 0.0, 0.0, 0.0, 1.0 ), float4( 0.0, 0.0, 0.0, 1.0 ), float4( 0.0, 0.0, 0.0, 0.0 ) } ;
} ;

struct VSInput
{
float4 VertexPosition : POSITION ;
float4 VertexNormal : NORMAL ;
float2 UV : TEXCOORD ;
};
struct VSOutput
{
float4 ScreenPosition : SV_POSITION ;
float4 VertexNormal : NORMAL ;
float2 UV : TEXCOORD0 ;
float4 WorldPosition : TEXCOORD1 ;
float4 CameraPosition : TEXCOORD2 ;
};

{
input.VertexNormal.w = 0 ;
input.VertexPosition.w = 1.0 ;

VSOutput output ;
output.VertexNormal = mul( input.VertexNormal, World ) ;
output.UV = input.UV ;
output.WorldPosition = mul( input.VertexPosition, World ) ;
output.CameraPosition = mul( mul( output.WorldPosition, View ), Projection ) ;
output.ScreenPosition = output.CameraPosition ;
return output ;
}

struct PSInput
{
float4 ScreenPosition : SV_POSITION ;
float4 WorldNormal : NORMAL ;
float2 UV : TEXCOORD0 ;
float4 WorldPosition : TEXCOORD1 ;
float4 CameraPosition : TEXCOORD2 ;
} ;
struct PSOutput
{
float4 Colour : SV_TARGET ;
float Depth : SV_DEPTH ;
} ;

{
PSOutput output ;

output.Colour = float4( Material.Diffuse.rgb, 1 ) ;
output.Colour = saturate( output.Colour ) ;

output.Depth = input.CameraPosition.z / input.CameraPosition.w ;
return output ;
}

{
Pass P0
{
}
}


Just in case this isn't clear for anyone, have a picture of a blue box on a green screen. Why green? Because it contrasts with blue and black.

#### Attached Thumbnails

Edited by Narf the Mouse, 03 October 2012 - 09:35 AM.

Posted 03 October 2012 - 09:45 AM

And you're not setting the constant buffer values anywhere in code? I've never seen a constant buffer initialized in a shader... only declared. Slightly shocked that works.

### #3Narf the Mouse  Members

Posted 03 October 2012 - 09:56 AM

And you're not setting the constant buffer values anywhere in code? I've never seen a constant buffer initialized in a shader... only declared. Slightly shocked that works.

If I am, I haven't found it. And I've looked using multiple techniques. Plus, that changing (and using both) the blue and alpha colours causes the box to change colours, makes it unlikely. (What I mean is, trying something swizzling blue, alpha and green on Material.Diffuse gets yellow. Which is one way I know it's reading the blue and alpha colours correctly).

Posted 03 October 2012 - 10:32 AM

And you're not setting the constant buffer values anywhere in code? I've never seen a constant buffer initialized in a shader... only declared. Slightly shocked that works.

If I am, I haven't found it. And I've looked using multiple techniques. Plus, that changing (and using both) the blue and alpha colours causes the box to change colours, makes it unlikely. (What I mean is, trying something swizzling blue, alpha and green on Material.Diffuse gets yellow. Which is one way I know it's reading the blue and alpha colours correctly).

You can verify exactly what values its reading and see what the cbuffer is actually filled with if you run it through PIX.

### #5Narf the Mouse  Members

Posted 03 October 2012 - 11:28 AM

And you're not setting the constant buffer values anywhere in code? I've never seen a constant buffer initialized in a shader... only declared. Slightly shocked that works.

If I am, I haven't found it. And I've looked using multiple techniques. Plus, that changing (and using both) the blue and alpha colours causes the box to change colours, makes it unlikely. (What I mean is, trying something swizzling blue, alpha and green on Material.Diffuse gets yellow. Which is one way I know it's reading the blue and alpha colours correctly).

You can verify exactly what values its reading and see what the cbuffer is actually filled with if you run it through PIX.

The buffer contains (in the Diffuse slot):
0 0.000
1 -1.#QO
2 1.000
3 1.000

Posted 03 October 2012 - 12:31 PM

Yea, looks like uninitialized memory to me (that 1.#Q is a good hint and probably NaN). I'd look at the Direct3D 11 Tutorials that come with the SDK (specifically tutorial #4) and create a constant buffer, fill it with the data you want, and then set it for your pixel shader so it can access the data. Very simple process and will give you more control/better results of your data anyway.

I've used SlimDX before and its going to be VERY similar to the D3D tutorial (just more object based since SlimDX is a simple wrapper on top of the normal SDK).

### #7Narf the Mouse  Members

Posted 03 October 2012 - 02:39 PM

Yea, looks like uninitialized memory to me (that 1.#Q is a good hint and probably NaN). I'd look at the Direct3D 11 Tutorials that come with the SDK (specifically tutorial #4) and create a constant buffer, fill it with the data you want, and then set it for your pixel shader so it can access the data. Very simple process and will give you more control/better results of your data anyway.

I've used SlimDX before and its going to be VERY similar to the D3D tutorial (just more object based since SlimDX is a simple wrapper on top of the normal SDK).

As noted, it's my DX10 code; I need to get a new video card. And other expenses...

Edit: Just to clarify, I meant to ask if DX10 versus DX11 changes the tutorial I should look at, but the question probably wasn't clear. Don't want to implement DX11 code that has a silent error if ported to DX10 or something, after all.

Edited by Narf the Mouse, 03 October 2012 - 04:09 PM.

Posted 04 October 2012 - 09:16 AM

Yea, looks like uninitialized memory to me (that 1.#Q is a good hint and probably NaN). I'd look at the Direct3D 11 Tutorials that come with the SDK (specifically tutorial #4) and create a constant buffer, fill it with the data you want, and then set it for your pixel shader so it can access the data. Very simple process and will give you more control/better results of your data anyway.

I've used SlimDX before and its going to be VERY similar to the D3D tutorial (just more object based since SlimDX is a simple wrapper on top of the normal SDK).

As noted, it's my DX10 code; I need to get a new video card. And other expenses...

Edit: Just to clarify, I meant to ask if DX10 versus DX11 changes the tutorial I should look at, but the question probably wasn't clear. Don't want to implement DX11 code that has a silent error if ported to DX10 or something, after all.

Ah, sorry, missed that. Regardless, Tutorial 4+ in the DirectX10 Tutorials directory of the SDK shows the same stuff. Looks like there is some small differences between 10 and 11 but not much.

### #9Narf the Mouse  Members

Posted 04 October 2012 - 09:32 AM

Yea, looks like uninitialized memory to me (that 1.#Q is a good hint and probably NaN). I'd look at the Direct3D 11 Tutorials that come with the SDK (specifically tutorial #4) and create a constant buffer, fill it with the data you want, and then set it for your pixel shader so it can access the data. Very simple process and will give you more control/better results of your data anyway.

I've used SlimDX before and its going to be VERY similar to the D3D tutorial (just more object based since SlimDX is a simple wrapper on top of the normal SDK).

As noted, it's my DX10 code; I need to get a new video card. And other expenses...

Edit: Just to clarify, I meant to ask if DX10 versus DX11 changes the tutorial I should look at, but the question probably wasn't clear. Don't want to implement DX11 code that has a silent error if ported to DX10 or something, after all.

Ah, sorry, missed that. Regardless, Tutorial 4+ in the DirectX10 Tutorials directory of the SDK shows the same stuff. Looks like there is some small differences between 10 and 11 but not much.

Thanks. And thanks for pointing out PIX to me - I've already improved my code with it.

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.