Hello,
This is more of a CG question but I did not know which forum it should belong to. So, apologies for posting on the wrong forum. Please feel free to remove the thread.
I have a simple particle system implemented on the GPU (one that I borrowed from the CG book) and I am trying to make some simple changes to it.
Now, my pixel shader takes a texture as an input and what I am trying to do is figure out the colour of the texture at the current location. My plan was to change the brightness of the particles based on the underlying colour.
So, my vertex shader looks as follows:
struct fragment
{
float4 position : POSITION;
float4 colour : COLOR0;
float2 texcoord0 : TEXCOORD0;
float pointSize : PSIZE;
};
fragment main(float3 pInitial : POSITION,
float3 vInitial : TEXCOORD0,
float tInitial : TEXCOORD1,
uniform float globalTime,
uniform float particleSize,
uniform float4x4 modelViewProj)
{
fragment OUT;
float t = globalTime - tInitial;
float4 final = float4(pInitial, 1) + (float4(vInitial, 0) + float4(0, (-4.9f), 0, 0) * t * t;
OUT.position = mul(modelViewProj, final);
OUT.texcoord0 = OUT.position; // store the position for the pixel shader
OUT.pointSize = particleSize;
return OUT;
}
So, I store the position (x, y) value (in the range -1, 1) in the texcoord0 parameter and my plan is to sample the colour at this position and use it as the particle colour.
My pixel shader looks as follows:
struct fragment
{
float4 position : POSITION;
float4 colour0 : COLOR0;
float2 texcoord0 : TEXCOORD0;
};
struct pixel
{
float4 colour : COLOR;
};
pixel main( fragment IN,
uniform sampler2D inputTexture,
uniform float brightness,
uniform float contrast,
uniform float gamma)
{
pixel OUT;
OUT.colour = tex2D(inputTexture, IN.texcoord0);
return OUT;
}
What I was expecting was the particle to have the sampled colour but what I actually see is that the texture gets mapped to the particle. I would actually like it to take a simple colour value rather than doing texture mapping. I have played around with the code in many ways but am unable to get the desired functionality.
I would really appreciate any help as this is driving me up the wall!
Thanks,
xarg