您的位置:首页 > 其它

编辑器中材质参数设置以及记录保存功能

2017-03-05 17:15 706 查看
PBR 参数调整记录功能

功能介绍:使用PBR渲染,对于其中的roughness 以及 matelness 设置,并记录该次的参数值。方便下次打开的时候自动读取xml文件,并设置相应的值。

记录结构体

struct matPBRInfo
{
int nShininess;
int nRougthness;
bool nHasTexture;
string nTextureFile;
}
Typedef std:: map<string, matPBRInfo> TMAT_PBRINFO;


材质的buffer 的管理, 数据保存为GLUbyte (unsigned char 类型)

typedef unsigned char GLUbyte;
std:: vector<GLUbyte> m_buffer;

void Material:: reflushUniformValue(int location, const GLubyte* data, int off){
Glint offset = offsets[location] + off * sizeof(GLfloat);
GLint dataSize;
if(off){
dataSize = sizeof(GLfloat);
}
else{
GLint nextoffset = offsets[location + 1];
if(nextoffset < 0 ) nextoffset = blockSize;
dataSize = nextoffset - offset;
}
for(int i =0 ; i < dataSize ; i ++){
m_buffer[offset + i ] = data[i];
}
}


数据写入 uniformbuffer

void Material::rebufferData(){
m_uniformsBuffer - >bind();
m_uniformsBuffer -> write(0, blockSize, m_buffer.data());
m_uniformBuffer->release();
}


下图所示为设置的参数,从xml文件中读取



获取材质渲染shader 中uniform 参数 , 使用 glGetactiveUniform() API 即可

void ShaderManager:: getUniform(QOpenGLShaderProgramPtr shader)
{
QOpenGLContext* context = QOpenGLContext::currentContext();
QASSERT(context);
QOpenGLFumtions_4_3_Core* m_funcs = nullptr;
m_funcs = context -> versionFunctions<QOpenGLFunctions_4_3_Core>();
m_funcs->initializeOpenGLFunctions(0;

GLuint program = shader-> programID();

int total = -1;
m_funcs-> glGetProgramiv(program, GL_ACTIVE_UNIFORMS, &total);
shaderUniformType.clear();
for(int i =0; i<total; ++i)
{
int name_len = -1, num = -1;
GLenum typr = GL_ZERO;
chat  name[50];
m_funcs->glGetActiveUniform(program, GLunit(i), sizeof(name) -1, &name_len, &num., &type, name);
name[name_len] = 0;
shaderUniformType.insert(std:: make_pair(name, type));
}
}


实际效果

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐