• 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
DJTN

HLSL If Statement

14 posts in this topic

I'm trying to blend two textures together in a pixel shader. To get started I have 2 texture samplers and a position (float4) passed into the pixel shader from the vertex shader. I want to use this position to determin which sampler to sample from. So I do the following:

[code]

float4 texel;

if ( input.Position.y < 50 )
{
texel = tex2D(texsampler1, input.TexCoords);
}
else
{
texel = tex2D(texsampler2, input.TexCoords);
}

return texel;

[/code]


This code fails and will not compile...


If I hard code the input.position.y to a number 1, I can compile but that is useless for obvious reasons.

I've also tried to implement a situation where I didnt need an "if statement" at all by adding the two pixels together after I multiplied them by a 1 or 0 passed in from the vertex shader but again, it fails.
0

Share this post


Link to post
Share on other sites
It's not the if that's the problem, it's your use of position. This isn't actually readable from a pixel shader under normal circumstances, so you should pass it in another slot as well, e.g. a spare texcoord slot.
0

Share this post


Link to post
Share on other sites
[quote name='mhagain' timestamp='1331671453' post='4921751']
It's not the if that's the problem, it's your use of position. This isn't actually readable from a pixel shader under normal circumstances, so you should pass it in another slot as well, e.g. a spare texcoord slot.
[/quote]

I changed the input from the position to a new var I created in the vertex shader output strucure:

[code]
float height : COLOR4;

[/code]

still fails to compile...

It doesnt matter if I hard code the value in the VS, change it to a float, float2, float4, or change the slot to TEXCOORD0, POSITION0, COLOR0.
It still fails.

I have no more hair to pull out [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img]
0

Share this post


Link to post
Share on other sites
Error: Compilation failed.

I think I've run out of slots. POSITION0, TEXCOORD0, TEXCOORD1, TEXCOORD2, TEXCOORD3, TEXCOORD4, COLOR0, COLOR1, COLOR2, and COLOR3.

COLOR4 is what I used for the height. But it also failed with TEXCOORD5. If I use another float in the passed in structure it works.
0

Share this post


Link to post
Share on other sites
Ok I can confirm I've run out of slots. I'm using PS 3.0 and I thought the units/slots were software (dx) dependant but it appears that they're hardware/device dependant.

Anyone have any ideas how I can work around this? Is it possible to set a global var and change it in the VS then read it in PS?

Also

What is the most common specs for devices in the last couple of years, in regards to texturecoords and color slot counts? My Nvidia GeForce 8500 GT only has 4 slots. Its not new but by no means was it a buget device.
0

Share this post


Link to post
Share on other sites
10 ps input slots is max in SM 3 (you should be actually guaranteed 10, so I don't know why your 8400 only has 4, unless NV are pulling a GeForce 4 MX with it again). Also - beware of the color slots; they're not [i]supposed[/i] to be any different with SM 3 class hardware, but some - particularly older/cheaper stuff - may interpolate at lower precision (on the assumption that they'll always contain color data and therefore you only need a 0 to 1 range).

If you're not using all 4 floats in any of your texcoord slots you could pack 2 into 1; e.g. if you've got 2 that are float2, pack them into a single float4 to free up a slot. Your code will look a little uglier but hey! You get an extra slot. Alternatively if some of your slots are used for passing the result of a calculation you might be able to get away with moving the calculation to the PS (which may even improve performance slightly if it gives better workload balancing between VS and PS - but then again it may not).

You can't set a global in the VS then read it in the PS; shaders don't work that way.
1

Share this post


Link to post
Share on other sites
[quote name='DJTN' timestamp='1331675144' post='4921779']
Error: Compilation failed.
[/quote]

That's not the compile error. That's an error telling you that compilation failed. The compile errors will be in the ID3DXBuffer that you get from the ppCompilationErrors parameters of D3DXCreateEffectFromFile or D3DXCompileShaderFromFile (assuming that you're compiling at runtime).
0

Share this post


Link to post
Share on other sites
When I said 4 I meant 4 textcoord but after your post it's clear I've went past the 10 ps input slots. My vert output struc has 10 slots being used. When I add the last one ( making it the 11th) for the texure blending is when it fails but only when I do a calculation with that 11th slot's data.

Thanks Mhagain, I got some decisions to make.
0

Share this post


Link to post
Share on other sites
[quote name='MJP' timestamp='1331683573' post='4921815']
[quote name='DJTN' timestamp='1331675144' post='4921779']
Error: Compilation failed.
[/quote]

That's not the compile error. That's an error telling you that compilation failed. The compile errors will be in the ID3DXBuffer that you get from the ppCompilationErrors parameters of D3DXCreateEffectFromFile or D3DXCompileShaderFromFile (assuming that you're compiling at runtime).
[/quote]


Thanks MJP. I'll look into that too but I'm pretty sure my issue is that I've reached the PS input slot limit for PS 3.0.
0

Share this post


Link to post
Share on other sites
[url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb509656(v=vs.85).aspx"]SM3[/url] is guaranteed to give you [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb172924(v=vs.85).aspx"]eight general float4 interpolators[/url] (TEXCOORD0-7) and [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb219859(v=vs.85).aspx"]two colour interpolators[/url] (COLOR0/1) that may have 8 bit precision.
That requirement is defined by the D3D software.
0

Share this post


Link to post
Share on other sites
[quote name='Hodgman' timestamp='1331684964' post='4921822']
[url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb509656(v=vs.85).aspx"]SM3[/url] is guaranteed to give you [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb172924(v=vs.85).aspx"]eight general float4 interpolators[/url] (TEXCOORD0-7) and [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb219859(v=vs.85).aspx"]two colour interpolators[/url] (COLOR0/1) that may have 8 bit precision.
That requirement is defined by the D3D software.
[/quote]

Hmmm - I was working off this page: http://msdn.microsoft.com/en-us/library/windows/desktop/bb172920%28v=vs.85%29.aspx which seems to contradict your links a little.
0

Share this post


Link to post
Share on other sites
until you write what the compiler says this looks more like a tv quiz show than a thread to help.
0

Share this post


Link to post
Share on other sites
ERROR: Invalid register number: 10. Max allowed for v# register is 9. Compilation failed

-Which is what I suspected after mhagain's comment and realizing that nothing changed in this working shader except the addition of a TEXCOORD in my VS output struc.

Thanks to mhagain for pointing me in the right direction and MJP, sorry it took so long to post the error as I had an issue that took priority yesterday afternoon.


For anyone else that finds this thread, you can only have 10 input slots with PS 3.0 and DX 9.
0

Share this post


Link to post
Share on other sites
[quote name='DJTN' timestamp='1331731463' post='4921959']
ERROR: Invalid register number: 10. Max allowed for v# register is 9. Compilation failed

-Which is what I suspected after mhagain's comment and realizing that nothing changed in this working shader except the addition of a TEXCOORD in my VS output struc.

Thanks to mhagain for pointing me in the right direction and MJP, sorry it took so long to post the error as I had an issue that took priority yesterday afternoon.


For anyone else that finds this thread, you can only have 10 input slots with PS 3.0 and DX 9.
[/quote]

Oh, and I should also note that my solution will be to pack 2 slots into 1 as I use 2 float2s that take up 2 slots. I will combine them into one leaving me an open slot to use for the blending data. I'll just have to clearly document and comment the shader as to what this new var consist of as well as be creative when naming the thing for future reference.

Thanks again,
DJTN
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