Jump to content
  • Advertisement
Sign in to follow this  
hossainiir

[Solved]Calculate interpolation in pixel shader

This topic is 2095 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement

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!

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!