void init_heights(void) { ProgramUniformSampler(display_prog, "Heights").Set(1); ProgramUniformSampler(shadow_prog, "Heights").Set(1); heights.target = Texture::Target::_2D; heights.BindMulti(1, Texture::Target::_2D); heights.Image2D( 0, PixelDataInternalFormat::DepthComponent32, side, side, 0, PixelDataFormat::DepthComponent, PixelDataType::Float, nullptr ); heights.BorderColor(Vec4f(1,1,1,1)); heights.MinFilter(TextureMinFilter::Nearest); heights.MagFilter(TextureMagFilter::Nearest); heights.WrapS(TextureWrap::ClampToBorder); heights.WrapT(TextureWrap::ClampToBorder); heights_fbo.target = Framebuffer::Target::Draw; heights_fbo.AttachTexture(FramebufferAttachment::Depth, heights, 0); heights_fbo.Complete(); }
void init_shadows(void) { ProgramUniformSampler(display_prog, "Shadows").Set(2); shadows.target = Texture::Target::_2D; shadows.BindMulti(2, Texture::Target::_2D); shadows.Image2D( 0, PixelDataInternalFormat::DepthComponent32, shadow_size, shadow_size, 0, PixelDataFormat::DepthComponent, PixelDataType::Float, nullptr ); shadows.BorderColor(Vec4f(1,1,1,1)); shadows.MinFilter(TextureMinFilter::Linear); shadows.MagFilter(TextureMagFilter::Linear); shadows.WrapS(TextureWrap::ClampToBorder); shadows.WrapT(TextureWrap::ClampToBorder); shadows.CompareMode(TextureCompareMode::CompareRefToTexture); shadows_fbo.target = Framebuffer::Target::Draw; shadows_fbo.AttachTexture(FramebufferAttachment::Depth, shadows, 0); shadows_fbo.Complete(); }
void init_offsets(void) { std::vector<GLfloat> offset_data(side*side*2); auto p = offset_data.begin(); for(GLuint j=0; j!=side; ++j) { GLfloat v = j/GLfloat(side-1) - 0.5f; for(GLuint i=0; i!=side; ++i) { GLfloat u = i/GLfloat(side-1) - 0.5f; *p++ = u*side; *p++ = v*side; } } ProgramUniformSampler(display_prog, "Offsets").Set(0); ProgramUniformSampler(shadow_prog, "Offsets").Set(0); offsets.target = Texture::Target::_2D; offsets.BindMulti(0, Texture::Target::_2D); offsets.Image2D( 0, PixelDataInternalFormat::RG32F, side, side, 0, PixelDataFormat::RG, PixelDataType::Float, offset_data.data() ); offsets.MinFilter(TextureMinFilter::Nearest); offsets.MagFilter(TextureMagFilter::Nearest); offsets.WrapS(TextureWrap::ClampToBorder); offsets.WrapT(TextureWrap::ClampToBorder); }
Field(const images::Image& map, const Program& prog) : gl() { const GLuint w = map.Width(); const GLuint h = map.Height(); const GLuint d = map.Depth(); const GLuint c = 3; radius = std::sqrt(GLfloat(w*w+h*h+d*d))*0.5f; vert_count = w*h*d; std::vector<GLfloat> pos_data(w*h*d*c); std::vector<GLuint> tec_data(w*h*d*c); GLfloat xo = w * 0.5f; GLfloat yo = h * 0.5f; GLfloat zo = d * 0.5f; for(GLuint z=0; z!=d; ++z) { for(GLuint y=0; y!=h; ++y) { for(GLuint x=0; x!=w; ++x) { GLuint k = z*w*h*c+y*w*c+x*c; pos_data[k+0] = x-xo; pos_data[k+1] = y-yo; pos_data[k+2] = z-zo; tec_data[k+0] = x; tec_data[k+1] = y; tec_data[k+2] = z; } } } positions.Data(pos_data); texcoords.Data(tec_data); DSAVertexArrayAttribEXT(vao, prog, "Position") .Setup<Vector<GLfloat, 3>>(positions) .Enable(); DSAVertexArrayAttribEXT(vao, prog, "TexCoord") .Setup<Vector<GLuint, 3>>(texcoords) .Enable(); ProgramUniformSampler(prog, "Pattern").Set(1); pattern.BindMulti(1, Texture::Target::_3D); pattern.Image3D(map); pattern.MinFilter(TextureMinFilter::Nearest); pattern.MagFilter(TextureMagFilter::Nearest); pattern.WrapS(TextureWrap::ClampToBorder); pattern.WrapT(TextureWrap::ClampToBorder); pattern.WrapR(TextureWrap::ClampToBorder); pattern.BorderColor(Vec4f(0,0,0,1)); ProgramUniformSampler(prog, "FadeMap").Set(2); fademap.BindMulti(2, Texture::Target::_3D); fademap.Image3D(images::RandomRedUByte( map.Width(), map.Height(), map.Depth() )); fademap.MinFilter(TextureMinFilter::Nearest); fademap.MagFilter(TextureMagFilter::Nearest); fademap.WrapS(TextureWrap::ClampToBorder); fademap.WrapT(TextureWrap::ClampToBorder); fademap.WrapR(TextureWrap::ClampToBorder); fademap.BorderColor(Vec4f(0,0,0,1)); }