IPB

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Sampling a texture at a given point
xargon
post Nov 6 2009, 07:55 AM
Post #1


Member
**

Group: Members
Posts: 7
Joined: 6-September 09
Member No.: 9,270



Hello everyone,

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:

CODE

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 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:

CODE

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
Go to the top of the page
 
+Quote Post
Nigel @ NVIDIA
post Nov 9 2009, 03:53 PM
Post #2


Advanced Member
***

Group: Moderators
Posts: 264
Joined: 17-October 07
Member No.: 1,524



For more modern profiles, the texture lookup can be done in the vertex shader,
and the color passed along to the fragment shader. (same for all fragments)

- Nigel
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Copyright © 2008 NVIDIA® Corporation.  Terms of Use | Legal Info | Privacy Policy Time is now: 23rd November 2009 - 12:58 PM