Guest User

Shader

a guest
Jul 10th, 2012
216
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #version 120
  2.  
  3. #define MAX_NUM_CAMS 8
  4. varying vec3 location;
  5. varying vec3 location_obj;
  6. uniform mat4 viewMat;
  7. uniform int numCameras;
  8. uniform sampler2D texSampler[MAX_NUM_CAMS];
  9. uniform sampler2D weightSampler[MAX_NUM_CAMS];
  10.  
  11. void main()
  12. {
  13. int i;
  14. float sumw = 0.0;
  15. float camw[MAX_NUM_CAMS];
  16. vec3 colour = vec3(0,0,0);
  17. vec4 p = vec4(location, 1.0);
  18. vec4 p_obj = vec4(location_obj, 1.0);
  19. vec4 tc = viewMat * p_obj;
  20. i = 0;
  21. camw[i]=0.0;
  22. if (i<numCameras)
  23. {
  24. camw[i] = texture2DProj(weightSampler[0],tc).r;
  25. sumw += camw[i];
  26. }
  27. i = 1;
  28. camw[i]=0.0;
  29. if (i<numCameras)
  30. {
  31. camw[i] = texture2DProj(weightSampler[1],tc).r;
  32. sumw += camw[i];
  33. }
  34. i = 2;
  35. camw[i]=0.0;
  36. if (i<numCameras)
  37. {
  38. camw[i] = texture2DProj(weightSampler[2],tc).r;
  39. sumw += camw[i];
  40. }
  41. i = 3;
  42. camw[i]=0.0;
  43. if (i<numCameras)
  44. {
  45. camw[i] = texture2DProj(weightSampler[3],tc).r;
  46. sumw += camw[i];
  47. }
  48. i = 4;
  49. camw[i]=0.0;
  50. if (i<numCameras)
  51. {
  52. camw[i] = texture2DProj(weightSampler[4],tc).r;
  53. sumw += camw[i];
  54. }
  55. i = 5;
  56. camw[i]=0.0;
  57. if (i<numCameras)
  58. {
  59. camw[i] = texture2DProj(weightSampler[5],tc).r;
  60. sumw += camw[i];
  61. }
  62. i = 6;
  63. camw[i]=0.0;
  64. if (i<numCameras)
  65. {
  66. camw[i] = texture2DProj(weightSampler[6],tc).r;
  67. sumw += camw[i];
  68. }
  69. i = 7;
  70. camw[i]=0.0;
  71. if (i<numCameras)
  72. {
  73. camw[i] = texture2DProj(weightSampler[7],tc).r;
  74. sumw += camw[i];
  75. }
  76. i = 0;
  77. if (i<numCameras && sumw>0.0)
  78. {
  79. vec4 texCoord = gl_TextureMatrix[i] * p;
  80. vec4 texColour = texture2DProj(texSampler[0],texCoord);
  81. float w = camw[i] / sumw;
  82. if (w>1.0) w = 1.0;
  83. colour += texColour.rgb*w;
  84. }
  85. i = 1;
  86. if (i<numCameras && sumw>0.0)
  87. {
  88. vec4 texCoord = gl_TextureMatrix[i] * p;
  89. vec4 texColour = texture2DProj(texSampler[1],texCoord);
  90. float w = camw[i] / sumw;
  91. if (w>1.0) w = 1.0;
  92. colour += texColour.rgb*w;
  93. }
  94. i = 2;
  95. if (i<numCameras && sumw>0.0)
  96. {
  97. vec4 texCoord = gl_TextureMatrix[i] * p;
  98. vec4 texColour = texture2DProj(texSampler[2],texCoord);
  99. float w = camw[i] / sumw;
  100. if (w>1.0) w = 1.0;
  101. colour += texColour.rgb*w;
  102. }
  103. i = 3;
  104. if (i<numCameras && sumw>0.0)
  105. {
  106. vec4 texCoord = gl_TextureMatrix[i] * p;
  107. vec4 texColour = texture2DProj(texSampler[3],texCoord);
  108. float w = camw[i] / sumw;
  109. if (w>1.0) w = 1.0;
  110. colour += texColour.rgb*w;
  111. }
  112. i = 4;
  113. if (i<numCameras && sumw>0.0)
  114. {
  115. vec4 texCoord = gl_TextureMatrix[i] * p;
  116. vec4 texColour = texture2DProj(texSampler[4],texCoord);
  117. float w = camw[i] / sumw;
  118. if (w>1.0) w = 1.0;
  119. colour += texColour.rgb*w;
  120. }
  121. i = 5;
  122. if (i<numCameras && sumw>0.0)
  123. {
  124. vec4 texCoord = gl_TextureMatrix[i] * p;
  125. vec4 texColour = texture2DProj(texSampler[5],texCoord);
  126. float w = camw[i] / sumw;
  127. if (w>1.0) w = 1.0;
  128. colour += texColour.rgb*w;
  129. }
  130. i = 6;
  131. if (i<numCameras && sumw>0.0)
  132. {
  133. vec4 texCoord = gl_TextureMatrix[i] * p;
  134. vec4 texColour = texture2DProj(texSampler[6],texCoord);
  135. float w = camw[i] / sumw;
  136. if (w>1.0) w = 1.0;
  137. colour += texColour.rgb*w;
  138. }
  139. i = 7;
  140. if (i<numCameras && sumw>0.0)
  141. {
  142. vec4 texCoord = gl_TextureMatrix[i] * p;
  143. vec4 texColour = texture2DProj(texSampler[7],texCoord);
  144. float w = camw[i] / sumw;
  145. if (w>1.0) w = 1.0;
  146. colour += texColour.rgb*w;
  147. }
  148. if (sumw==0.0) discard;
  149. //colour = colour*0.5;
  150. gl_FragColor = vec4(colour, 0.5);
  151. //gl_FragData[0] = vec4(colour, 0.5);
  152. //gl_FragData[1] = vec4(colour, 0.5);
  153. }
RAW Paste Data