The Reverend
Member
I learned more about shaders the last few weeks but one thing I still don't really get and that's corner ids.
I can observe that
this line: mod(in_Colour.r * 255.0, 2.0);
returns 0 for the even vertices 0 & 2 or top-left and bottom-right and
returns 1 for the uneven vertices 1 & 3 or top-right and bottom-left
this line: abs(mod(in_Colour.b * 255.0, 2.0));
returns 0 for vertices 0 & 1 and
returns 1 for vertices 2 & 3
So logically this line: abs(mod(in_Colour.b * 255.0, 2.0) - mod(in_Colour.r * 255.0, 2.0));
returns 0 for vertices 0 & 3 and
returns 1 for vertices 1 & 2
So I realize I can use this to get interpolated normalized x/y-coords to pass to the fragment shader instead or additional to v_vTexcoord. flyingsaucerinvasion was so kind to point me to this method.
I just absolutely don't understand why this works.
What exactly is corner id?
What are those 2 bits stolen from the colour as the documentation "explains"?
Why can I retrieve a number 0, -1 or 1 when multiplying the colour by 255 and then checking for eveness by modding by 2?
Could anyone explain that to me? I hate not understanding things.
(edit: To my surprise this question was moved to the advanced programming discussion subforum. Now I hope the answers won't be too complicated for me to understand.)
I can observe that
this line: mod(in_Colour.r * 255.0, 2.0);
returns 0 for the even vertices 0 & 2 or top-left and bottom-right and
returns 1 for the uneven vertices 1 & 3 or top-right and bottom-left
this line: abs(mod(in_Colour.b * 255.0, 2.0));
returns 0 for vertices 0 & 1 and
returns 1 for vertices 2 & 3
So logically this line: abs(mod(in_Colour.b * 255.0, 2.0) - mod(in_Colour.r * 255.0, 2.0));
returns 0 for vertices 0 & 3 and
returns 1 for vertices 1 & 2
So I realize I can use this to get interpolated normalized x/y-coords to pass to the fragment shader instead or additional to v_vTexcoord. flyingsaucerinvasion was so kind to point me to this method.
I just absolutely don't understand why this works.
What exactly is corner id?
What are those 2 bits stolen from the colour as the documentation "explains"?
Why can I retrieve a number 0, -1 or 1 when multiplying the colour by 255 and then checking for eveness by modding by 2?
Could anyone explain that to me? I hate not understanding things.
(edit: To my surprise this question was moved to the advanced programming discussion subforum. Now I hope the answers won't be too complicated for me to understand.)
Last edited: