Discussion:
Blank Screen
(too old to reply)
ichirouk
2007-11-15 13:15:28 UTC
Permalink
Hello, Iam a newbie to HLSL and DirectX9

Iam trying to get use too DirectX and HLSL.fx Ive created a shader and
it compiles fine. Now when I attach it to DX9 I get a blank window.
Just black window nothing in the window. Help and any suggestions on
books for learning both shaders in HLSL and DirectX9.

thank you
legalize+ (Richard [Microsoft Direct3D MVP])
2007-11-15 18:37:09 UTC
Permalink
[Please do not mail me a copy of your followup]
Post by ichirouk
Iam trying to get use too DirectX and HLSL.fx Ive created a shader and
it compiles fine. Now when I attach it to DX9 I get a blank window.
Just black window nothing in the window. Help and any suggestions on
books for learning both shaders in HLSL and DirectX9.
Do you see black geometry if you change your background color to
white?
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
<http://www.xmission.com/~legalize/book/download/index.html>

Legalize Adulthood! <http://blogs.xmission.com/legalize/>
ichirouk
2007-11-15 18:54:29 UTC
Permalink
I added the device handle and now i get the cube all black. Iam using
DirectX and the code is calling the .fx file. I dont see why the
marble is not working. The vertices are const. in the .cpp file. The
way I understand my vertices are being maniuplated in the .fx and Ive
made the vertices color be const in the .cpp file. So whys it still
all black? Thank you for any advice. Below is my .fx


// Simple Marble effect file
//
// Simple Lighting Model

float4x4 gWVP;
float4x4 worldviewproj : WorldViewProjection;

//transpose the matrix
bool RowMajor = true;


// light direction (view space)
float3 lightDir : Direction <
string UIName = "Light Direction";
string Object = "TargetLight";
= {-0.577, -0.577, 0.577};
// light intensity
float4 I_a = { 0.1f, 0.1f, 0.1f, 1.0f }; // ambient
float4 I_d = { 1.0f, 1.0f, 1.0f, 1.0f }; // diffuse
float4 I_s = { 1.0f, 1.0f, 1.0f, 1.0f }; // specular

// material reflectivity
float4 k_a <
string UIName = "Ambient";
= float4( 0.47f, 0.47f, 0.47f, 1.0f ); // ambient
float4 k_d <
string UIName = "Diffuse";
= float4( 0.47f, 0.47f, 0.47f, 1.0f ); // diffuse
float4 k_s <
string UIName = "Specular";
= float4( 1.0f, 1.0f, 1.0f, 1.0f ); // specular
int n<
string UIName = "Specular Power";
string UIType = "IntSpinner";
float UIMin = 0.0f;
float UIMax = 50.0f;
= 15;
// transformations
float4x4 World : WORLD;
float4x4 View : VIEW;
float4x4 Projection : PROJECTION;
float4x4 WorldViewProj : WORLDVIEWPROJECTION;
float4x4 WorldView : WORLDVIEW;


//Vertex Shader


struct VS_OUTPUT
{
float4 Pos : POSITION0;
float4 col : COLOR0;

};

VS_OUTPUT VS(
float3 Pos : POSITION0,
float3 col : COLOR0,
float3 Norm : NORMAL,
float2 Tex : TEXCOORD0)
{
VS_OUTPUT Out = (VS_OUTPUT)0;

float3 L = -lightDir;
float3 P = mul(float4(Pos, 1), (float4x3)gWVP); // position (view
space)
float3 N = normalize(mul(Norm, (float3x3)gWVP)); // normal (view
space)


float3 R = normalize(2 * dot(N, L) * N - L); //
reflection vector (view space)
float3 V = -normalize(P); // view
direction (view space)

Out.Pos = mul(float4(Pos,1),gWVP); // position (projected)

float4 Diff = I_a * k_a + I_d * k_d * max(0, dot(N, L)); //
diffuse + ambient
float4 Spec = I_s * k_s * pow(max(0, dot(R, V)), n/4); //
specular


// Just pass the vertex color into the pixel shader.
Out.col = Diff + Spec;
// hg should do separate diffuse specular interpolation

return Out;
}


//Pixel Shader

float4 PS(
float4 Diff : COLOR0,
float4 Spec : COLOR1,
float2 Tex : TEXCOORD0,
float2 Tex1 : TEXCOORD1 ) : COLOR
{
float4 color = Diff + Spec;
return color;
}

technique DefaultTechnique
{
pass P0
{
// shaders
VertexShader = compile vs_1_1 VS();
PixelShader = compile ps_1_1 PS();
}
}
[Please do not mail me a copy of your followup]
Post by ichirouk
Iam trying to get use too DirectX and HLSL.fx Ive created a shader and
it compiles fine. Now when I attach it to DX9 I get a blank window.
Just black window nothing in the window. Help and any suggestions on
books for learning both shaders in HLSL and DirectX9.
Do you see black geometry if you change your background color to
white?
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
<http://www.xmission.com/~legalize/book/download/index.html>
Legalize Adulthood! <http://blogs.xmission.com/legalize/>
legalize+ (Richard [Microsoft Direct3D MVP])
2007-11-16 14:48:45 UTC
Permalink
[Please do not mail me a copy of your followup]
Post by ichirouk
I added the device handle and now i get the cube all black.
So you see black geometry on a white background?

That means your geometry is being drawn (its visible and not clipped),
but you've computed black for the color of every pixel.

Instead of debugging your shader for you, I'm going to explain how you
debug these problems in general.

Simplify your shader down to the simplest thing: have your pixel
shader put a constant color (green, for example) on every pixel. You
should get green geometry. If you don't get a green cube, then you
aren't connecting that shader to your device properly. If you are
getting a green cube, then add back one element of your pixel shader
and try it again.

The problem here is that you've started with a complex shader and it
doesn't work and now you have to figure out where the problem is; the
general advice is "divide and conquer" -- divide the shader into
pieces and conquer each one until you find the source of the problem.
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
<http://www.xmission.com/~legalize/book/download/index.html>

Legalize Adulthood! <http://blogs.xmission.com/legalize/>
ichirouk
2007-11-20 14:58:14 UTC
Permalink
Post by legalize+ (Richard [Microsoft Direct3D MVP])
[Please do not mail me a copy of your followup]
Post by ichirouk
I added the device handle and now i get the cube all black.
So you see black geometry on a white background?
That means your geometry is being drawn (its visible and not clipped),
but you've computed black for the color of every pixel.
Instead of debugging your shader for you, I'm going to explain how you
debug these problems in general.
Simplify your shader down to the simplest thing: have your pixel
shader put a constant color (green, for example) on every pixel. You
should get green geometry. If you don't get a green cube, then you
aren't connecting that shader to your device properly. If you are
getting a green cube, then add back one element of your pixel shader
and try it again.
The problem here is that you've started with a complex shader and it
doesn't work and now you have to figure out where the problem is; the
general advice is "divide and conquer" -- divide the shader into
pieces and conquer each one until you find the source of the problem.
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
<http://www.xmission.com/~legalize/book/download/index.html>
Legalize Adulthood! <http://blogs.xmission.com/legalize/>
I got Green

Thank you so much... Iam divided and conquering. I will let you know
as it comes along.

Thank you

Loading...