Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef SHADOWMAP_H_
- #define SHADOWMAP_H_
- #include <iostream>
- #include <GL/GLee.h>
- #include "../math/Vector.h"
- /*
- * Basic shader
- *
- * Vertex (1):
- #version 150
- uniform mat4 pmv;
- in vec3 vertex0;
- void main(){
- gl_Position = pmv*vec4(vertex0, 1.0);
- }
- *
- * Vertex (2):
- #version 150
- uniform mat4 pmv;
- uniform mat4 shadowBP; // bias*projection
- uniform mat4 shadowMV;
- in vec3 vertex0;
- in vec2 texCoord0;
- out vec2 texCoord;
- out vec4 shadowCoord;
- void main(){
- texCoord = texCoord0;
- shadowCoord = shadowBP*shadowMV*vec4(vertex0, 1.0);
- gl_Position = pmv*vec4(vertex0, 1.0);
- }
- *
- * Fragment (1):
- #version 150
- precision highp float;
- void main(){
- gl_FragDepth = gl_FragCoord.z;
- }
- *
- * Fragment (2):
- #version 150
- precision highp float;
- uniform sampler2D texture0;
- uniform sampler2DShadow shadowMap;
- in vec2 texCoord;
- in vec4 shadowCoord;
- void main(){
- vec4 SC = shadowCoord/shadowCoord.w+0.0005;
- float D = textureProj(shadowMap, SC);
- float shadow = 1.0;
- if(shadowCoord.w > 0.0){
- if(D < SC.z){
- shadow = 0.5;
- }
- }
- gl_FragColor = shadow*texture(texture0, texCoord);
- }
- *
- */
- class ShadowMap{
- protected:
- GLuint m_texture;
- GLuint m_fbo; // Frame Buffer Object
- vec2 m_size;
- vec2 m_pixelOffset; // Persistent Closing Filter
- public:
- ShadowMap(vec2 size, vec2 pixelOffset);
- virtual ~ShadowMap();
- void updateTexture(vec2 v);
- void updateTexture(float x, float y);
- void setPixelOffset(vec2 v);
- void setPixelOffset(float x, float y);
- GLuint getTextureID();
- GLuint getFBO();
- vec2 getTextureSize();
- float getTextureWidth();
- float getTextureHeight();
- vec2 getPixelOffset();
- };
- #endif
Advertisement
Add Comment
Please, Sign In to add comment