Use texture buffer instead of uniform for samples
Should fix nvidia glsl error
This commit is contained in:
parent
f0d430c833
commit
2b0680d92d
@ -1,5 +1,5 @@
|
||||
uniform samplerCube tex;
|
||||
uniform float samples[2048];
|
||||
uniform samplerBuffer samples;
|
||||
uniform float ViewportSize;
|
||||
|
||||
uniform mat4 PermutationMatrix;
|
||||
@ -20,8 +20,8 @@ void main(void)
|
||||
|
||||
for (int i = 0; i < 1024; i++)
|
||||
{
|
||||
float Theta = samples[2 * i];
|
||||
float Phi = samples[2 * i + 1];
|
||||
float Theta = texelFetch(samples, 2 * i).r;
|
||||
float Phi = texelFetch(samples, 2 * i).g;
|
||||
|
||||
vec3 L = cos(Theta) * RayDir + sin(Theta) * cos(Phi) * Tangent + sin(Theta) * sin(Phi) * Bitangent;
|
||||
float NdotL = clamp(dot(RayDir, L), 0., 1.);
|
||||
|
@ -289,24 +289,39 @@ GLuint generateSpecularCubemap(GLuint probe)
|
||||
float roughness = (8 - level) * 4 * pow(2.f, 10.f) / 8.f;
|
||||
float viewportSize = float(1 << (8 - level));
|
||||
|
||||
std::vector<float> Samples;
|
||||
float *tmp = new float[2048];
|
||||
for (unsigned i = 0; i < 1024; i++)
|
||||
{
|
||||
std::pair<float, float> sample = ImportanceSamplingPhong(HammersleySequence(i, 1024), roughness);
|
||||
Samples.push_back(sample.first);
|
||||
Samples.push_back(sample.second);
|
||||
tmp[2 * i] = sample.first;
|
||||
tmp[2 * i + 1] = sample.second;
|
||||
}
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + UtilShader::SpecularIBLGenerator::getInstance()->TU_Samples);
|
||||
GLuint sampleTex, sampleBuffer;
|
||||
glGenBuffers(1, &sampleBuffer);
|
||||
glBindBuffer(GL_TEXTURE_BUFFER, sampleBuffer);
|
||||
glBufferData(GL_TEXTURE_BUFFER, 2048 * sizeof(float), tmp, GL_STATIC_DRAW);
|
||||
glGenTextures(1, &sampleTex);
|
||||
glBindTexture(GL_TEXTURE_BUFFER, sampleTex);
|
||||
glTexBuffer(GL_TEXTURE_BUFFER, GL_RG32F, sampleBuffer);
|
||||
|
||||
for (unsigned face = 0; face < 6; face++)
|
||||
{
|
||||
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, cubemap_texture, level);
|
||||
GLuint status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
assert(status == GL_FRAMEBUFFER_COMPLETE);
|
||||
|
||||
UtilShader::SpecularIBLGenerator::getInstance()->SetTextureUnits(probe);
|
||||
UtilShader::SpecularIBLGenerator::getInstance()->setUniforms(M[face], Samples, viewportSize);
|
||||
UtilShader::SpecularIBLGenerator::getInstance()->setUniforms(M[face], viewportSize);
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
}
|
||||
|
||||
delete[] tmp;
|
||||
glDeleteTextures(1, &sampleTex);
|
||||
glDeleteBuffers(1, &sampleBuffer);
|
||||
}
|
||||
|
||||
glDeleteFramebuffers(1, &fbo);
|
||||
|
@ -894,8 +894,10 @@ namespace UtilShader
|
||||
Program = LoadProgram(OBJECT,
|
||||
GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/importance_sampling_specular.frag").c_str());
|
||||
AssignUniforms("PermutationMatrix", "samples[0]", "ViewportSize");
|
||||
AssignUniforms("PermutationMatrix", "ViewportSize");
|
||||
TU_Samples = 1;
|
||||
AssignSamplerNames(Program, 0, "tex");
|
||||
AssignTextureUnit(Program, TexUnit(TU_Samples, "samples"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,9 +49,10 @@ public:
|
||||
static void setUniforms(const irr::video::SColor &);
|
||||
};
|
||||
|
||||
class SpecularIBLGenerator : public ShaderHelperSingleton<SpecularIBLGenerator, core::matrix4, std::vector<float>, float >, public TextureRead<Trilinear_cubemap>
|
||||
class SpecularIBLGenerator : public ShaderHelperSingleton<SpecularIBLGenerator, core::matrix4, float >, public TextureRead<Trilinear_cubemap>
|
||||
{
|
||||
public:
|
||||
GLuint TU_Samples;
|
||||
SpecularIBLGenerator();
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user