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

need help with "There was an error compiling expression"

11 posts in this topic

hi everybody..i am a beginner to HLSL and i met with a problem that the compiler says 'There was an error compiling expression'.
here is some of the code
[CODE]
float4 PassTest(float2 coord:TEXCOORD) : COLOR0
{
return float4(0, 0, 0, 0);
}
technique Main
{

pass P0
{
PixelShader = compile ps_2_0 PassTest(); //the error is in this line?
}
}
[/CODE]
i do not know what may cause this..and some HLSL code written before can work well...
my English is poor ,so if it is not described clearly enough, please point out...thanks.~
0

Share this post


Link to post
Share on other sites
Hi!

The code compiles just fine, but I think in practice it won’t help you much. You need a vertex shader. Otherwise the rasterizer has no idea, where to invoke the pixel shader. In case you want the pixel shader to be invoked for every pixel, you have to render a quad covering the whole viewport. For this you can pass in the vertices of the quad in post-clipping space ([-1,-1]..[1,1]) and let the vertex shader directly output them unchanged.

Cheers!
0

Share this post


Link to post
Share on other sites
[quote name='Tsus' timestamp='1335426957' post='4934990']
Hi!

The code compiles just fine, but I think in practice it won’t help you much. You need a vertex shader. Otherwise the rasterizer has no idea, where to invoke the pixel shader. In case you want the pixel shader to be invoked for every pixel, you have to render a quad covering the whole viewport. For this you can pass in the vertices of the quad in post-clipping space ([-1,-1]..[1,1]) and let the vertex shader directly output them unchanged.

Cheers!
[/quote]

Thanks very much~
but actually a vertex shader can be left out..i wrote a pass without a vertex shader before and it works well..
A friend told me that maybe the compiling error is caused by a structure(or an array?)..
[CODE]
typedef struct ScreenL
{
float4 Pixels[SCREEN_SIZE.x];
}ScreenLine;
typedef struct ScreenD
{
ScreenLine Lines[SCREEN_SIZE.y];
}ScreenData;
[/CODE]
(#define SCREEN_SIZE int2(800, 480))

i thought the structure has nothing to do with the compiling..but he changed the 'SCREEN_SIZE' and the error disappeared..
why the structure caused the compiling error..it seems that the structure has nothing to do with compiling?

i want to write a GPU particle system, and need a structure to save the data of the texture consisting of all particles.So what type of structure should i use?
0

Share this post


Link to post
Share on other sites
Hi Cirno!

[quote name='Cirno' timestamp='1335435640' post='4935027']
but actually a vertex shader can be left out..i wrote a pass without a vertex shader before and it works well..
[/quote]
Are we talking about Dx9? The old fixed function pipeline kicks in, if no vertex shader is bound but with Dx10/11 a vertex shader is required. (At least it yells error messages in the output window at me. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]) If you don’t explicitly write in the effect pass “SetVertexShader( 0 );” the vertex shader of the last effect is still bound (Dx10/11) – a very dangerous behavior.
Edit: I've just seen the XNA tag. In that case I'd expect that the last vertex shader was still bound. Otherwise I wasn't aware that XNA still has the fixed-function pipeline behind the scenes.

[quote name='Cirno' timestamp='1335435640' post='4935027']
i thought the structure has nothing to do with the compiling..but he changed the 'SCREEN_SIZE' and the error disappeared..
why the structure caused the compiling error..it seems that the structure has nothing to do with compiling?
[/quote]
That’s indeed strange. I don’t have a good answer for that, sorry.

[quote name='Cirno' timestamp='1335435640' post='4935027']
i want to write a GPU particle system, and need a structure to save the data of the texture consisting of all particles.So what type of structure should i use?
[/quote]
Did you take a look at the ParticlesGS sample in the DxSDK? If you don’t dependent on Dx9 it might be easier and faster to use the stream output instead of textures to store the state of the particles.
Edit: Alright, irrelevant for you because of XNA.

Cheers!
0

Share this post


Link to post
Share on other sites
[quote name='Cirno' timestamp='1335435640' post='4935027']
i want to write a GPU particle system, and need a structure to save the data of the texture consisting of all particles.So what type of structure should i use?
[/quote]

Large arrays in a shader won't work. For anything big you need to use a texture or render target.
0

Share this post


Link to post
Share on other sites
[quote name='Tsus' timestamp='1335448331' post='4935068']
Did you take a look at the ParticlesGS sample in the DxSDK? If you don’t dependent on Dx9 it might be easier and faster to use the stream output instead of textures to store the state of the particles.
Edit: Alright, irrelevant for you because of XNA.

Cheers!
[/quote]

Thanks all the same..
And there is a 3D particle example for XNA in MSDN..but maybe it lacks some....extendability....? Edited by Cirno
0

Share this post


Link to post
Share on other sites
[quote name='Adam_42' timestamp='1335454570' post='4935106']
Large arrays in a shader won't work. For anything big you need to use a texture or render target.
[/quote]

Thanks..
I looked up some documents and articles and haven't found ways for textures to save pixels in HLSL..
0

Share this post


Link to post
Share on other sites
Hi!

This sample [url="http://create.msdn.com/en-US/education/catalog/sample/particle_3d"]here[/url] – I think you mean this one ? – explicitly computes the position based on the initial position, the initial velocity and the life time. If you can describe your particle system by this simple means, it’s totally fine to go this way. If you want more complex behavior you probably want to numerically integrate the particle paths. This means, you compute with each iteration the new particle position (based on gravity, wind sources etc) and store it – to be input for the next iteration.

So the question is, how to store the data, right? You can maintain the particle positions in textures. Since you can’t read and write from/to the same resource (at least not before Dx11) you create two textures – one to read from and one to write to. After each iteration you swap both textures, thus the texture you wrote to in the last frame, is the one you read from in the current frame. This paradigm is called ping-pong btw. You can write to a texture by creating a RenderTarget2D and binding it to the pipeline. The pixel shader then writes its results to the texture somewhere hidden in the RenderTarget2D class. Since RenderTarget2D inherits from Texture2D (if i recall correctly) you just read from it as from any other texture. In XNA a RenderTarget2D is so to say a texture you can write to. [url="http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series3/Render_to_texture.php"]Here[/url] is a small sample.

Cheers!
0

Share this post


Link to post
Share on other sites
[quote name='Tsus' timestamp='1335960753' post='4936740']
You can write to a texture by creating a RenderTarget2D and binding it to the pipeline. The pixel shader then writes its results to the texture somewhere hidden in the RenderTarget2D class. Since RenderTarget2D inherits from Texture2D (if i recall correctly) you just read from it as from any other texture. In XNA a RenderTarget2D is so to say a texture you can write to.
[/quote]
Maybe it is because I don't know how to draw on a Texture2D object in HLSL..if the drawing code is in XNA(and the HLSL code only computes the particle positions), it seems not to have made full use of HLSL..
Also, binding the texture to the pipeline may cause some strange problems, for example, if a rander target is current render target of the graphics device, sampling on that render may get strange color(when I was trying to write an additive color mixing type)...
0

Share this post


Link to post
Share on other sites
Hi!

[quote name='Cirno' timestamp='1336042028' post='4937054']
Maybe it is because I don't know how to draw on a Texture2D object in HLSL..if the drawing code is in XNA(and the HLSL code only computes the particle positions), it seems not to have made full use of HLSL..
[/quote]
The XNA code is used to build a command list that tells the GPU what to do. Thus, at some point you need XNA code. The work is done on the GPU. Or what else do you mean with drawing code?

[url="http://www.catalinzima.com/tutorials/4-uses-of-vtf/particle-systems/"]Here[/url] is an example that basically does what you want. It’s fairly detailed, so I hope you can work your way through it. If you have questions, feel free to ask!

[quote name='Cirno' timestamp='1336042028' post='4937054']
Also, binding the texture to the pipeline may cause some strange problems, for example, if a rander target is current render target of the graphics device, sampling on that render may get strange color(when I was trying to write an additive color mixing type)...
[/quote]
That’s right. Reading from and writing to the same resource yields undefined behavior (before Dx11). For this reason, we maintain the data in two textures and toggle between them (ping-pong). Thus, you read from another texture than you write to. The sample above builds a temporary buffer to which the results are written. Afterwards the result is copied back to the other “original” texture. Actually, this is not necessary, since you can toggle between both textures, like this:
[CODE]bool ping = true;
RenderTarget2D positionsPing;
RenderTarget2D positionsPong;

Draw() {
if (ping) { // Pong -> Ping
// Bind texture positionsPong
// Bind render target positionsPing
}
else { // Ping -> Pong
// Bind texture positionsPing
// Bind render target positionsPong
}
// Bind rendertarget 0. (Unbind render target)
ping = !ping; // Toggle ping pong.
}[/CODE]

Best regards!
0

Share this post


Link to post
Share on other sites
[quote name='Tsus' timestamp='1336056899' post='4937114']
bool ping = true;
RenderTarget2D positionsPing;
RenderTarget2D positionsPong;

Draw() {
if (ping) { // Pong -> Ping
// Bind texture positionsPong
// Bind render target positionsPing
}
else { // Ping -> Pong
// Bind texture positionsPing
// Bind render target positionsPong
}
// Bind rendertarget 0. (Unbind render target)
ping = !ping; // Toggle ping pong.
}
[/quote]
Thanks very much..now I understand the 'ping-pong' technique:)
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