Guest User

Untitled

a guest
Oct 10th, 2012
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 KB | None | 0 0
  1. #ifndef SHADOWMAP_H_
  2. #define SHADOWMAP_H_
  3.  
  4. #include <iostream>
  5. #include <GL/GLee.h>
  6.  
  7. #include "../math/Vector.h"
  8.  
  9. /*
  10.  * Basic shader
  11.  *
  12.  * Vertex (1):
  13.         #version 150
  14.  
  15.         uniform mat4 pmv;
  16.  
  17.         in vec3 vertex0;
  18.  
  19.         void main(){
  20.             gl_Position = pmv*vec4(vertex0, 1.0);
  21.         }
  22.  *
  23.  * Vertex (2):
  24.         #version 150
  25.  
  26.         uniform mat4 pmv;
  27.         uniform mat4 shadowBP; // bias*projection
  28.         uniform mat4 shadowMV;
  29.  
  30.         in vec3 vertex0;
  31.         in vec2 texCoord0;
  32.  
  33.         out vec2 texCoord;
  34.         out vec4 shadowCoord;
  35.  
  36.         void main(){
  37.             texCoord = texCoord0;
  38.             shadowCoord = shadowBP*shadowMV*vec4(vertex0, 1.0);
  39.             gl_Position = pmv*vec4(vertex0, 1.0);
  40.         }
  41.  *
  42.  * Fragment (1):
  43.         #version 150
  44.  
  45.         precision highp float;
  46.  
  47.         void main(){
  48.             gl_FragDepth = gl_FragCoord.z;
  49.         }
  50.  *
  51.  * Fragment (2):
  52.         #version 150
  53.  
  54.         precision highp float;
  55.  
  56.         uniform sampler2D texture0;
  57.         uniform sampler2DShadow shadowMap;
  58.  
  59.         in vec2 texCoord;
  60.         in vec4 shadowCoord;
  61.  
  62.         void main(){
  63.             vec4 SC = shadowCoord/shadowCoord.w+0.0005;
  64.    
  65.             float D = textureProj(shadowMap, SC);
  66.    
  67.             float shadow = 1.0;
  68.    
  69.             if(shadowCoord.w > 0.0){
  70.                 if(D < SC.z){
  71.                     shadow = 0.5;
  72.                 }
  73.             }
  74.    
  75.             gl_FragColor = shadow*texture(texture0, texCoord);
  76.         }
  77.  *
  78.  */
  79.  
  80. class ShadowMap{
  81.     protected:
  82.         GLuint m_texture;
  83.         GLuint m_fbo; // Frame Buffer Object
  84.         vec2 m_size;
  85.         vec2 m_pixelOffset; // Persistent Closing Filter
  86.  
  87.     public:
  88.         ShadowMap(vec2 size, vec2 pixelOffset);
  89.         virtual ~ShadowMap();
  90.  
  91.         void updateTexture(vec2 v);
  92.         void updateTexture(float x, float y);
  93.         void setPixelOffset(vec2 v);
  94.         void setPixelOffset(float x, float y);
  95.  
  96.         GLuint getTextureID();
  97.         GLuint getFBO();
  98.  
  99.         vec2 getTextureSize();
  100.         float getTextureWidth();
  101.         float getTextureHeight();
  102.  
  103.         vec2 getPixelOffset();
  104. };
  105.  
  106. #endif
Advertisement
Add Comment
Please, Sign In to add comment