Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Vertex shader (shader A and B both use this)
  2.     #version 130
  3.     in vec2 vertexPosition;
  4.     in vec4 vertexColor;
  5.     in vec2 vertexUV;
  6.  
  7.     // uniform float time;
  8.     uniform mat4 transform;
  9.  
  10.     out vec4 fragmentColor;
  11.     out vec2 fragmentUV;
  12.     void main()
  13.     {
  14.         gl_Position.xy = vertexPosition;
  15.         gl_Position.z = 0.0;
  16.         gl_Position.w = 1.0;
  17.  
  18.         // gl_Position.x += sin(time*(gl_Position.x+gl_Position.y)*(gl_Position.x-gl_Position.y)/10)/30;
  19.         // gl_Position.y += cos(time*(gl_Position.y+gl_Position.x)*(gl_Position.y-gl_Position.x)/10)/30;
  20.  
  21.         gl_Position.xy = (transform*vec4(gl_Position.xy, 0.0f,1.0f)).xy;
  22.         fragmentColor = vertexColor;
  23.         fragmentUV = vec2(vertexUV.x, 1-vertexUV.y);
  24.     }  
  25.  
  26. Fragment shader (shader A):
  27.     #version 430
  28.  
  29.     in vec4 fragmentColor;
  30.     in vec2 fragmentUV;
  31.     layout(location = 1) uniform sampler2D texa;
  32.     layout(location = 2) uniform sampler2D texb;
  33.  
  34.     layout(location = 0) out vec4 color;
  35.  
  36.     float toFloat(vec4 color)
  37.     {
  38.         int red = int(color.r * 255.0);
  39.         int green =int(color.g * 255.0);
  40.         int blue = int(color.b * 255.0);
  41.         int alpha = int(color.a * 255.0);
  42.         int intVal = (red << 0) | (green << 8) | (blue << 16) | (alpha << 24);
  43.         return intBitsToFloat(intVal);
  44.     }
  45.     vec4 toColor(float value)
  46.     {
  47.         int intVal = floatBitsToInt(value);
  48.         int red = (intVal >> 0) & 0xff;
  49.         int green = (intVal >> 8) & 0xff;
  50.         int blue = (intVal >> 16) & 0xff;
  51.         int alpha = (intVal >> 24) & 0xff;
  52.         return vec4(red / 255.0, green / 255.0, blue / 255.0, alpha / 255.0);
  53.     }
  54.  
  55.     float DoAdd(float a, float b)
  56.     {
  57.         return a + b;
  58.     }
  59.     void main()
  60.     {
  61.         color = toColor(DoAdd(toFloat(texture2D(texa,fragmentUV)),toFloat(texture2D(texb,fragmentUV))));
  62.     }
  63.  
  64. Fragment shader (shader B):
  65.     #version 430
  66.    
  67.     in vec4 fragmentColor;
  68.     in vec2 fragmentUV;
  69.    
  70.     uniform float time;
  71.     layout(location = 1) uniform sampler2D texa1;
  72.     layout(location = 2) uniform sampler2D texa2;
  73.     layout(location = 3) uniform sampler2D texa3;
  74.     layout(location = 4) uniform sampler2D texa4;
  75.     layout(location = 5) uniform sampler2D texa5;
  76.     layout(location = 6) uniform sampler2D texa6;
  77.     layout(location = 7) uniform sampler2D texa7;
  78.     layout(location = 8) uniform sampler2D texa8;
  79.     layout(location = 9) uniform sampler2D texa9;
  80.     layout(location = 10) uniform sampler2D texa10;
  81.  
  82.     layout(location = 11) uniform sampler2D texb1;
  83.     layout(location = 12) uniform sampler2D texb2;
  84.     layout(location = 13) uniform sampler2D texb3;
  85.     layout(location = 14) uniform sampler2D texb4;
  86.     layout(location = 15) uniform sampler2D texb5;
  87.     layout(location = 16) uniform sampler2D texb6;
  88.     layout(location = 17) uniform sampler2D texb7;
  89.     layout(location = 18) uniform sampler2D texb8;
  90.     layout(location = 19) uniform sampler2D texb9;
  91.     layout(location = 20) uniform sampler2D texb10;
  92.  
  93.     layout(location = 0) out vec4 color;
  94.  
  95.     float rand(vec2 co){
  96.         return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
  97.     }
  98.     float resolve(float a)
  99.     {
  100.         float r = rand(fragmentUV*time);
  101.         if(r<0.5) return a;
  102.  
  103.         r = rand(fragmentUV*(time-2.0));
  104.         if(r > mod(a,1.0))
  105.         return -1;
  106.         return 1;
  107.     }
  108.  
  109.     float toFloat(vec4 color)
  110.     {
  111.         int red = int(color.r * 255.0);
  112.         int green =int(color.g * 255.0);
  113.         int blue = int(color.b * 255.0);
  114.         int alpha = int(color.a * 255.0);
  115.         int intVal = (red << 0) | (green << 8) | (blue << 16) | (alpha << 24);
  116.         return intBitsToFloat(intVal);
  117.     }
  118.     vec4 toColor(float value)
  119.     {
  120.         int intVal = floatBitsToInt(value);
  121.         int red = (intVal >> 0) & 0xff;
  122.         int green = (intVal >> 8) & 0xff;
  123.         int blue = (intVal >> 16) & 0xff;
  124.         int alpha = (intVal >> 24) & 0xff;
  125.         return vec4(red / 255.0, green / 255.0, blue / 255.0, alpha / 255.0);
  126.     }
  127.     float DoMath(float a, float b)
  128.     {
  129.         return resolve(a + b);
  130.     }
  131.     void main()
  132.     {
  133.         float myTime= mod(time*60,10);
  134.         if(myTime <1)
  135.             color = toColor(DoMath(toFloat(texture2D(texa1,fragmentUV)),toFloat(texture2D(texb1,fragmentUV))));
  136.         else if(myTime <2)
  137.             color = toColor(DoMath(toFloat(texture2D(texa2,fragmentUV)),toFloat(texture2D(texb2,fragmentUV))));
  138.         else if(myTime <3)
  139.             color = toColor(DoMath(toFloat(texture2D(texa3,fragmentUV)),toFloat(texture2D(texb3,fragmentUV))));
  140.         else if(myTime <4)
  141.             color = toColor(DoMath(toFloat(texture2D(texa4,fragmentUV)),toFloat(texture2D(texb4,fragmentUV))));
  142.         else if(myTime <5)
  143.             color = toColor(DoMath(toFloat(texture2D(texa5,fragmentUV)),toFloat(texture2D(texb5,fragmentUV))));
  144.         else if(myTime <6)
  145.             color = toColor(DoMath(toFloat(texture2D(texa6,fragmentUV)),toFloat(texture2D(texb6,fragmentUV))));
  146.         else if(myTime <7)
  147.             color = toColor(DoMath(toFloat(texture2D(texa7,fragmentUV)),toFloat(texture2D(texb7,fragmentUV))));
  148.         else if(myTime <8)
  149.             color = toColor(DoMath(toFloat(texture2D(texa8,fragmentUV)),toFloat(texture2D(texb8,fragmentUV))));
  150.         else if(myTime <9)
  151.             color = toColor(DoMath(toFloat(texture2D(texa9,fragmentUV)),toFloat(texture2D(texb9,fragmentUV))));
  152.         else
  153.             color = toColor(DoMath(toFloat(texture2D(texa10,fragmentUV)),toFloat(texture2D(texb10,fragmentUV))));
  154.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement