Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


[Solved]Calculate interpolation in pixel shader


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 hossainiir   Members   -  Reputation: 1030

Like
0Likes
Like

Posted 26 January 2013 - 02:39 AM

hi evryone ,

assume i have a quad(for each vertex : vec4:Position; vec2:TextureCoord; vec3:ExtraData) and i send this to vertex shader and vertex shader without any transformation send them to pixel shader.

I want to remove ExtraData from quad and send ExtraData as a cbuffer to pixel shader, Now how can i calculate the interpolated ExtraData with normalized TextureCoord in pixel shader that it becomes quite similar to vertex shader interpolation???

 

thanks.


خلیج تا ابد فارس

Persian Gulf


Sponsor:

#2 nfactorial   Members   -  Reputation: 731

Like
0Likes
Like

Posted 26 January 2013 - 04:45 AM

Not sure you explained what you'd like that I understand it sorry.

 

But, if I follow you correctly you don't want the value interpolated. You didn't state which shader language you are using, but on shader model 4 (HLSL) or higher you can specify nointerpolation.

 

eg.

 

struct VertexOutput
{
    nointerpolation float  value;
};

 

Otherwise, you will need to specify the same value on each vertex which will give you the same value (because lerp(valueA, valueA) = valueA). ie. in you example if extraData is the same for each vertex it will arrive unaltered in the pixel shader, if it is not the same for each vertex then I would presume you actually wanted the data interpolated.

 

n!



#3 eppo   Crossbones+   -  Reputation: 2621

Like
0Likes
Like

Posted 26 January 2013 - 05:41 AM

You can output barycentric coordinates from the vertex shader and use those to do custom interpolation in the pixel shader.

You'll have to duplicate shared vertices on the quad or use a geometry shader.



#4 hossainiir   Members   -  Reputation: 1030

Like
0Likes
Like

Posted 26 January 2013 - 09:12 AM

thanks,

But, if I follow you correctly you don't want the value interpolated.

no, i want to interpolated extraData  as same as vertex shader do but in pixel shader, in a quad we have 4 vertex and also 4 different extraData ,i don't want extradata pass by vertex shader ,i pass them as a cbuffer to pixel shader.

 

i solve the problem ,for any arbitrary point inside the quad we can use the following relation to calculate interpolation :

float3 INT;

INT.xz = lerp[ lerp(P2.xz,P1.xz, texcoord.u) , lerp(P3.xz,P0.xz, texcoord.u) , texcoord.v];

INT.y  =  lerp[ lerp(P2.y,P3.y, texcoord.v) , lerp(P1.y,P0.y, texcoord.v) , texcoord.v];

 

where texcoord is texture coordinate passed by vertex shader and P0~P3 are extraData . the quad is :

 

2-----------1

|            /   |

|       /        |

|   /            |

3-----------0


خلیج تا ابد فارس

Persian Gulf





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS