• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Narf the Mouse

.fx file error - Box comes out blue

8 posts in this topic

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:
[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) ) ;
[/code]
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):
[code]
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( ) ) ) ;
}
}
[/code]

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
0

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

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.
[/quote]
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).
0

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.
[/quote]
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.
1

Share this post


Link to post
Share on other sites
[quote name='AdeptStrain' timestamp='1349281952' post='4986443']
[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.
[/quote]
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
0

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

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).
[/quote]
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
0

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).
[/quote]
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. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
[/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.
1

Share this post


Link to post
Share on other sites
[quote name='AdeptStrain' timestamp='1349363774' post='4986784']
[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).
[/quote]
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. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
[/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.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0