need help with "There was an error compiling expression"

Started by
10 comments, last by Cirno 11 years, 11 months ago
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

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?
}
}

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.~
Advertisement
There's nothing wrong in that shader...
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!

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!


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

typedef struct ScreenL
{
float4 Pixels[SCREEN_SIZE.x];
}ScreenLine;
typedef struct ScreenD
{
ScreenLine Lines[SCREEN_SIZE.y];
}ScreenData;

(#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?
Hi Cirno!


but actually a vertex shader can be left out..i wrote a pass without a vertex shader before and it works well..

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. smile.png) 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.


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?

That’s indeed strange. I don’t have a good answer for that, sorry.


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?

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!

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?


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

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!


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

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


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

This sample here – 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. Here is a small sample.

Cheers!

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.

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

This topic is closed to new replies.

Advertisement