bump mapping tests
This commit is contained in:
parent
d2244fa274
commit
935b56da2e
@ -64,7 +64,6 @@ Scene* MyGLWidget::buildScene()
|
|||||||
scene->addEntity(myEntity);
|
scene->addEntity(myEntity);
|
||||||
|
|
||||||
scene->addDirectionnalLight(glm::vec3(6, 4, -4), glm::vec3(0.7f, 0.6f, 0.4f)); // sun
|
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;
|
return scene;
|
||||||
}
|
}
|
||||||
|
@ -39,12 +39,13 @@ vec3 computeLight(in vec3 kd, in vec3 ks, in float ns, in vec3 color, in vec3 no
|
|||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
int i;
|
int i;
|
||||||
vec3 kd = vec3(texture2D(baseTexture, varTexCoord));
|
vec3 kd = vec3(0.5);
|
||||||
vec3 light = 0.1f*kd;
|
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)
|
for(i=0; i<nbDirLights && i<4; ++i)
|
||||||
light += computeLight(kd, materialKs, materialNs, dirLights[i*2+1], varNormal, lightDirInView[i], halfVecInView[i]);
|
light += computeLight(kd, materialKs, materialNs, dirLights[i*2+1], myNormal, lightDirInView[i], halfVecInView[i]);
|
||||||
for(i=0; i<nbPointLights && i+nbDirLights<4; ++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]);
|
light += computeLight(kd, materialKs, materialNs, pointLights[i*2+1], myNormal, lightDirInView[nbDirLights+i], halfVecInView[nbDirLights+i]);
|
||||||
|
|
||||||
outColor = vec4(light, 1);
|
outColor = vec4(light, 1);
|
||||||
}
|
}
|
||||||
|
12
texture.cpp
12
texture.cpp
@ -8,7 +8,7 @@ Texture::Texture() : type(GL_TEXTURE_2D)
|
|||||||
{
|
{
|
||||||
glAssert(glGenTextures(1, &texId));
|
glAssert(glGenTextures(1, &texId));
|
||||||
glAssert(glBindTexture(type, 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);
|
setWrap(GL_REPEAT);
|
||||||
setFiltering(GL_LINEAR);
|
setFiltering(GL_LINEAR);
|
||||||
}
|
}
|
||||||
@ -42,9 +42,9 @@ Texture::~Texture()
|
|||||||
glAssert(glDeleteTextures(1, &texId));
|
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 xFactor = 1.0f / (width - 1);
|
||||||
float yFactor = 1.0f / (height - 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 y = yFactor * row;
|
||||||
float sum = 0.0f;
|
float sum = 0.0f;
|
||||||
float freq = frequency;
|
float freq = frequency;
|
||||||
float scale = myScale;
|
float scale = amplitude;
|
||||||
|
|
||||||
// Compute the sum for each octave
|
// 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);
|
glm::vec2 p(x * freq, y * freq);
|
||||||
float val = glm::perlin(p, glm::vec2(freq)) / scale;
|
float val = glm::perlin(p, glm::vec2(freq)) / scale;
|
||||||
sum += val;
|
sum += val;
|
||||||
@ -68,7 +68,7 @@ void Texture::createNoiseTexture(GLenum textureSlot, int width, int height, floa
|
|||||||
data[((row * width + col) * 4) + oct] =
|
data[((row * width + col) * 4) + oct] =
|
||||||
(GLubyte) ( result * 255.0f );
|
(GLubyte) ( result * 255.0f );
|
||||||
freq *= 2.0f; // Double the frequency
|
freq *= 2.0f; // Double the frequency
|
||||||
scale *= myScale; // Next power of b
|
scale *= amplitude; // Next power of b
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user