0 Favourites

Help understanding some shader code.

  • Hello,

    For anyone who understands shaders, hopefully you can help easily.

    Consider the following two lines:

    lowp vec4 front = texture2D(samplerFront, vTex);

    lowp vec4 back = texture2D(samplerBack, mix(destStart, destEnd, vTex));

    I understand the first line and what it does. I understand what the second line does but not why (why am I mixing here). Consequently I don't understand the out put given the following (comments show what I know/think):

    lowp vec4 color = texture2D(samplerFront, vTex); // gets the pixel from the front, and should be the same as front

    colorlookup.b = 0.0; //sets blue to 0

    colorlookup.r = vTex.x; //sets the r component to be the same as the texture coordinate in use

    colorlookup.g = vTex.y; //dito for green

    gl_FragColor = colorlookup;

    Now, this should simply color an object like a slice of an rgb cube with red increasing on the right and green increasing down y. The top left corner is black and the bottom right is yellow and no blue is present.

    If I delete the line: lowp vec4 back = texture2D(samplerBack, mix(destStart, destEnd, vTex));

    everything works, but if I include it vTex seems like it gets changed and thusly it seems to be off when calculating red and green. Like if the object fills the entire screen it will be rendered correctly, but if it larger or smaller than the screen it is color acording to the top left pixel of the screen (not the object) being black and the bottom right being yellow. Does this make sense? does the mix() change or alter it?

    I checked other effects that blend with the background and I don't see anything. You may ask why I read the samplerfront twice, and thats a good question, but I want to know why its working the way it does.

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread sticky
276 261,913
gamecorpstudio's avatar
gamecorpstudio
Unread hot topic
96 16,172
thegodo's avatar
thegodo
Unread hot topic
0 Favourites
Understanding subscription
96 4,810
ruskul's avatar
ruskul