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.

  • Try Construct 3

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

    Try 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)