Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on May 4th, 2012  |  syntax: OpenGL Shading  |  size: 1.79 KB  |  views: 44  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. GEOMETRY SHADER
  2. ------------------------------------------------------------------
  3. #version 120
  4.  
  5. //in values from vert shader...
  6. varying in vec2 vSpriteTransform[];
  7. varying in vec4 vSpriteColor[];
  8. varying in vec4 vSpriteTexCoords[];
  9.  
  10. //out values to frag shader...
  11. varying out vec2 TexCoord;
  12. varying out vec4 Color;
  13.  
  14. void main() {
  15.         mat4 gVP = gl_ModelViewProjectionMatrix;
  16.        
  17.         vec2 pos = gl_PositionIn[0].xy;
  18.         vec2 size = vSpriteTransform[0].xy;
  19.         vec4 tex = vSpriteTexCoords[0];
  20.                
  21.         //out to frag...
  22.         Color = vSpriteColor[0];
  23.        
  24.         gl_Position = gVP * vec4(pos.x, pos.y, 0, 1); //top left
  25.         TexCoord = vec2(tex.x, tex.y);
  26.         EmitVertex();
  27.        
  28.         gl_Position = gVP * vec4(pos.x+size.x, pos.y, 0, 1); //top right
  29.         TexCoord = vec2(tex.x+tex.z, tex.y);
  30.         EmitVertex();
  31.        
  32.         gl_Position = gVP * vec4(pos.x, pos.y+size.y, 0, 1); //bottom left
  33.         TexCoord = vec2(tex.x, tex.y+tex.w);
  34.         EmitVertex();
  35.        
  36.         gl_Position = gVP * vec4(pos.x+size.x, pos.y+size.y, 0, 1); //bottom right
  37.         TexCoord = vec2(tex.x+tex.z, tex.y+tex.w);
  38.         EmitVertex();
  39.        
  40.         EndPrimitive();
  41. }
  42.  
  43.  
  44.  
  45.  
  46.  
  47. VERTEX SHADER
  48. ------------------------------------------------------------------
  49. #version 120
  50.  
  51. //in values...
  52. attribute vec2 SpriteTransform;
  53. attribute vec4 SpriteTexCoords;
  54. attribute vec4 SpriteColor;
  55.  
  56. //out values...
  57. varying vec2 vSpriteTransform;
  58. varying vec4 vSpriteColor;
  59. varying vec4 vSpriteTexCoords;
  60.  
  61. void main() {
  62.         vSpriteTransform = SpriteTransform;
  63.         vSpriteTexCoords = SpriteTexCoords;
  64.         vSpriteColor = SpriteColor;
  65.         gl_Position = gl_Vertex;
  66. }
  67.  
  68.  
  69.  
  70.  
  71.  
  72. FRAGMENT SHADER
  73. ------------------------------------------------------------------
  74. #version 120
  75.  
  76. uniform sampler2D tex0;
  77.  
  78. varying vec2 TexCoord;
  79. varying vec4 Color;
  80.  
  81. void main(void) {
  82.         vec4 c = texture2D(tex0, TexCoord);
  83.         gl_FragColor = Color * c;
  84. }