投影纹理与最小细节层级的混合应用

来源:互联网 发布:如何恢复u盘数据 编辑:程序博客网 时间:2024/06/04 19:04

这里写图片描述

void Basic::genfloorTex(){    m_sourceImage = NvImage::CreateFromDDSFile("textures/flower1024.dds");    GLint w = m_sourceImage->getWidth();    GLint h = m_sourceImage->getHeight();    GLint intFormat = m_sourceImage->getInternalFormat();    GLint format = m_sourceImage->getFormat();    GLint type = m_sourceImage->getType();    // Image must be immutable in order to be used with glBindImageTexture    // So we copy the mutable texture to an immutable texture    glGenTextures(1, &m_sourceTexture);    glBindTexture(GL_TEXTURE_2D, m_sourceTexture);    glTexStorage2D(GL_TEXTURE_2D, 1, intFormat, w, h);    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, format, type, m_sourceImage->getLevel(0));    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);    glBindTexture(GL_TEXTURE_2D, 0);}//vertex shader#version 100attribute highp vec2 aPosition;attribute highp vec2 aTexcoord;uniform mediump mat4 uViewProjMatrix;varying lowp vec4 vColor;varying lowp vec2 vs_fs_texCoord;varying lowp vec4 vs_fs_projtexCoord;void main(void){    gl_Position = uViewProjMatrix * vec4(aPosition.x, aPosition.y, 0.0, 1.0);    vs_fs_texCoord = aTexcoord;    vs_fs_projtexCoord = mat4(0.5,0.0,0.0,0.0,    0.0,0.5,0.0,0.0,    0.0,0.0,0.5,0.0,    0.5,0.5,0.5,1.0)*uViewProjMatrix * vec4(aPosition.x+0.4, aPosition.y, 0.0, 1.0);}//frag shader#version 430precision highp float;in lowp vec2 vs_fs_texCoord;in lowp vec4 vs_fs_projtexCoord;layout (binding = 0) uniform sampler2D mipmapTex;layout (binding = 1) uniform sampler2D projTex;layout (location = 0) out vec4 outcolor0;void main(void){    //outcolor0 = texture(mipmapTex, vs_fs_texCoord);    //outcolor0 = textureLod(mipmapTex,vs_fs_texCoord,6.0f);    outcolor0 = texture(mipmapTex, vs_fs_texCoord);    outcolor0+= textureProj(projTex,vs_fs_projtexCoord);}