您的位置:首页 > 其它

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

2017-12-09 21:58 447 查看


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 100
attribute 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 430
precision 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);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: