• Advertisement
Sign in to follow this  

.fx file error - Box comes out blue

This topic is 1938 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
SlimDX.D3DCompiler.ShaderFlags.Debug,
#else
SlimDX.D3DCompiler.ShaderFlags.OptimizationLevel1,
#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 ;
};

VSOutput VShader( VSInput input )
{
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 PShader( PSInput input )
{
PSOutput output ;

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


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

technique10 Shader
{
Pass P0
{
SetVertexShader( CompileShader( vs_4_0, VShader( ) ) ) ;
SetGeometryShader( NULL ) ;
SetPixelShader( CompileShader( ps_4_0, PShader( ) ) ) ;
}
}


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. Edited by Narf the Mouse

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites

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).

Share this post


Link to post
Share on other sites

[quote name='AdeptStrain' timestamp='1349279113' post='4986423']
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).
[/quote]

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

Share this post


Link to post
Share on other sites

[quote name='Narf the Mouse' timestamp='1349279766' post='4986430']
[quote name='AdeptStrain' timestamp='1349279113' post='4986423']
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).
[/quote]

You can verify exactly what values its reading and see what the cbuffer is actually filled with if you run it through PIX.
[/quote]
The buffer contains (in the Diffuse slot):
0 0.000
1 -1.#QO
2 1.000
3 1.000

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

[quote name='AdeptStrain' timestamp='1349289070' post='4986481']
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. smile.png
[/quote]

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.

Share this post


Link to post
Share on other sites

[quote name='Narf the Mouse' timestamp='1349296790' post='4986526']
[quote name='AdeptStrain' timestamp='1349289070' post='4986481']
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. smile.png
[/quote]

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.
[/quote]
Thanks. :) And thanks for pointing out PIX to me - I've already improved my code with it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement