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, 03 October 2012 - 09:35 AM.






