Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Vertex shader (shader A and B both use this)
- #version 130
- in vec2 vertexPosition;
- in vec4 vertexColor;
- in vec2 vertexUV;
- // uniform float time;
- uniform mat4 transform;
- out vec4 fragmentColor;
- out vec2 fragmentUV;
- void main()
- {
- gl_Position.xy = vertexPosition;
- gl_Position.z = 0.0;
- gl_Position.w = 1.0;
- // gl_Position.x += sin(time*(gl_Position.x+gl_Position.y)*(gl_Position.x-gl_Position.y)/10)/30;
- // gl_Position.y += cos(time*(gl_Position.y+gl_Position.x)*(gl_Position.y-gl_Position.x)/10)/30;
- gl_Position.xy = (transform*vec4(gl_Position.xy, 0.0f,1.0f)).xy;
- fragmentColor = vertexColor;
- fragmentUV = vec2(vertexUV.x, 1-vertexUV.y);
- }
- Fragment shader (shader A):
- #version 430
- in vec4 fragmentColor;
- in vec2 fragmentUV;
- layout(location = 1) uniform sampler2D texa;
- layout(location = 2) uniform sampler2D texb;
- layout(location = 0) out vec4 color;
- float toFloat(vec4 color)
- {
- int red = int(color.r * 255.0);
- int green =int(color.g * 255.0);
- int blue = int(color.b * 255.0);
- int alpha = int(color.a * 255.0);
- int intVal = (red << 0) | (green << 8) | (blue << 16) | (alpha << 24);
- return intBitsToFloat(intVal);
- }
- vec4 toColor(float value)
- {
- int intVal = floatBitsToInt(value);
- int red = (intVal >> 0) & 0xff;
- int green = (intVal >> 8) & 0xff;
- int blue = (intVal >> 16) & 0xff;
- int alpha = (intVal >> 24) & 0xff;
- return vec4(red / 255.0, green / 255.0, blue / 255.0, alpha / 255.0);
- }
- float DoAdd(float a, float b)
- {
- return a + b;
- }
- void main()
- {
- color = toColor(DoAdd(toFloat(texture2D(texa,fragmentUV)),toFloat(texture2D(texb,fragmentUV))));
- }
- Fragment shader (shader B):
- #version 430
- in vec4 fragmentColor;
- in vec2 fragmentUV;
- uniform float time;
- layout(location = 1) uniform sampler2D texa1;
- layout(location = 2) uniform sampler2D texa2;
- layout(location = 3) uniform sampler2D texa3;
- layout(location = 4) uniform sampler2D texa4;
- layout(location = 5) uniform sampler2D texa5;
- layout(location = 6) uniform sampler2D texa6;
- layout(location = 7) uniform sampler2D texa7;
- layout(location = 8) uniform sampler2D texa8;
- layout(location = 9) uniform sampler2D texa9;
- layout(location = 10) uniform sampler2D texa10;
- layout(location = 11) uniform sampler2D texb1;
- layout(location = 12) uniform sampler2D texb2;
- layout(location = 13) uniform sampler2D texb3;
- layout(location = 14) uniform sampler2D texb4;
- layout(location = 15) uniform sampler2D texb5;
- layout(location = 16) uniform sampler2D texb6;
- layout(location = 17) uniform sampler2D texb7;
- layout(location = 18) uniform sampler2D texb8;
- layout(location = 19) uniform sampler2D texb9;
- layout(location = 20) uniform sampler2D texb10;
- layout(location = 0) out vec4 color;
- float rand(vec2 co){
- return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
- }
- float resolve(float a)
- {
- float r = rand(fragmentUV*time);
- if(r<0.5) return a;
- r = rand(fragmentUV*(time-2.0));
- if(r > mod(a,1.0))
- return -1;
- return 1;
- }
- float toFloat(vec4 color)
- {
- int red = int(color.r * 255.0);
- int green =int(color.g * 255.0);
- int blue = int(color.b * 255.0);
- int alpha = int(color.a * 255.0);
- int intVal = (red << 0) | (green << 8) | (blue << 16) | (alpha << 24);
- return intBitsToFloat(intVal);
- }
- vec4 toColor(float value)
- {
- int intVal = floatBitsToInt(value);
- int red = (intVal >> 0) & 0xff;
- int green = (intVal >> 8) & 0xff;
- int blue = (intVal >> 16) & 0xff;
- int alpha = (intVal >> 24) & 0xff;
- return vec4(red / 255.0, green / 255.0, blue / 255.0, alpha / 255.0);
- }
- float DoMath(float a, float b)
- {
- return resolve(a + b);
- }
- void main()
- {
- float myTime= mod(time*60,10);
- if(myTime <1)
- color = toColor(DoMath(toFloat(texture2D(texa1,fragmentUV)),toFloat(texture2D(texb1,fragmentUV))));
- else if(myTime <2)
- color = toColor(DoMath(toFloat(texture2D(texa2,fragmentUV)),toFloat(texture2D(texb2,fragmentUV))));
- else if(myTime <3)
- color = toColor(DoMath(toFloat(texture2D(texa3,fragmentUV)),toFloat(texture2D(texb3,fragmentUV))));
- else if(myTime <4)
- color = toColor(DoMath(toFloat(texture2D(texa4,fragmentUV)),toFloat(texture2D(texb4,fragmentUV))));
- else if(myTime <5)
- color = toColor(DoMath(toFloat(texture2D(texa5,fragmentUV)),toFloat(texture2D(texb5,fragmentUV))));
- else if(myTime <6)
- color = toColor(DoMath(toFloat(texture2D(texa6,fragmentUV)),toFloat(texture2D(texb6,fragmentUV))));
- else if(myTime <7)
- color = toColor(DoMath(toFloat(texture2D(texa7,fragmentUV)),toFloat(texture2D(texb7,fragmentUV))));
- else if(myTime <8)
- color = toColor(DoMath(toFloat(texture2D(texa8,fragmentUV)),toFloat(texture2D(texb8,fragmentUV))));
- else if(myTime <9)
- color = toColor(DoMath(toFloat(texture2D(texa9,fragmentUV)),toFloat(texture2D(texb9,fragmentUV))));
- else
- color = toColor(DoMath(toFloat(texture2D(texa10,fragmentUV)),toFloat(texture2D(texb10,fragmentUV))));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement