Sign in to follow this  
hossainiir

[Solved]Calculate interpolation in pixel shader

Recommended Posts

hossainiir    1044

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
nfactorial    735

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
eppo    4877

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
hossainiir    1044

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this