bump mapping tests

This commit is contained in:
Anselme 2015-07-03 21:22:03 +02:00
parent d2244fa274
commit 935b56da2e
3 changed files with 14 additions and 14 deletions

View File

@ -64,7 +64,6 @@ Scene* MyGLWidget::buildScene()
scene->addEntity(myEntity);
scene->addDirectionnalLight(glm::vec3(6, 4, -4), glm::vec3(0.7f, 0.6f, 0.4f)); // sun
scene->addPointLight(glm::vec3(0, 0, 4), glm::vec3(0.7f, 0.6f, 0.4f));
return scene;
}

View File

@ -39,12 +39,13 @@ vec3 computeLight(in vec3 kd, in vec3 ks, in float ns, in vec3 color, in vec3 no
void main(void) {
int i;
vec3 kd = vec3(texture2D(baseTexture, varTexCoord));
vec3 light = 0.1f*kd;
for(i=0; i<nbDirLights && i<4; ++i)
light += computeLight(kd, materialKs, materialNs, dirLights[i*2+1], varNormal, lightDirInView[i], halfVecInView[i]);
for(i=0; i<nbPointLights && i+nbDirLights<4; ++i)
light += computeLight(kd, materialKs, materialNs, pointLights[i*2+1], varNormal, lightDirInView[nbDirLights+i], halfVecInView[nbDirLights+i]);
vec3 kd = vec3(0.5);
vec3 light = 0.1*kd;
vec3 myNormal = normalize(varNormal + 0.3 - 0.6*vec3(texture2D(baseTexture, varTexCoord)));
for(i=0; i<nbDirLights && i<4; ++i)
light += computeLight(kd, materialKs, materialNs, dirLights[i*2+1], myNormal, lightDirInView[i], halfVecInView[i]);
for(i=0; i<nbPointLights && i+nbDirLights<4; ++i)
light += computeLight(kd, materialKs, materialNs, pointLights[i*2+1], myNormal, lightDirInView[nbDirLights+i], halfVecInView[nbDirLights+i]);
outColor = vec4(light, 1);
}

View File

@ -8,7 +8,7 @@ Texture::Texture() : type(GL_TEXTURE_2D)
{
glAssert(glGenTextures(1, &texId));
glAssert(glBindTexture(type, texId));
createNoiseTexture(GL_TEXTURE_2D, 512, 512, 10, 1);
createNoiseTexture(GL_TEXTURE_2D, 512, 512, 10, 1.5f);
setWrap(GL_REPEAT);
setFiltering(GL_LINEAR);
}
@ -42,9 +42,9 @@ Texture::~Texture()
glAssert(glDeleteTextures(1, &texId));
}
void Texture::createNoiseTexture(GLenum textureSlot, int width, int height, float frequency, float myScale)
void Texture::createNoiseTexture(GLenum textureSlot, int width, int height, float frequency, float amplitude)
{
GLubyte *data = new GLubyte[ width * height * 4 ];
GLubyte *data = new GLubyte[ width * height * 4];
float xFactor = 1.0f / (width - 1);
float yFactor = 1.0f / (height - 1);
@ -55,10 +55,10 @@ void Texture::createNoiseTexture(GLenum textureSlot, int width, int height, floa
float y = yFactor * row;
float sum = 0.0f;
float freq = frequency;
float scale = myScale;
float scale = amplitude;
// Compute the sum for each octave
for( int oct = 0; oct < 4; oct++ ) {
for( int oct = 0; oct < 4 ; oct++ ) {
glm::vec2 p(x * freq, y * freq);
float val = glm::perlin(p, glm::vec2(freq)) / scale;
sum += val;
@ -66,9 +66,9 @@ void Texture::createNoiseTexture(GLenum textureSlot, int width, int height, floa
// Store in texture buffer
data[((row * width + col) * 4) + oct] =
(GLubyte) ( result * 255.0f );
(GLubyte) ( result * 255.0f );
freq *= 2.0f; // Double the frequency
scale *= myScale; // Next power of b
scale *= amplitude; // Next power of b
}
}
}