Merge pull request 'normal mapping - sth wrong with the ship' (#12) from noramal into master
Reviewed-on: #12
This commit is contained in:
commit
99c3fab77b
@ -9,6 +9,7 @@ uniform vec3 cameraPos;
|
||||
|
||||
|
||||
uniform sampler2D textureSampler;
|
||||
uniform sampler2D normalSampler;
|
||||
|
||||
uniform vec3 lightPositions[100];
|
||||
uniform vec3 lightColors[100];
|
||||
@ -26,6 +27,7 @@ uniform float exposition;
|
||||
in vec3 vecNormal;
|
||||
in vec3 worldPos;
|
||||
in vec2 TexCoords;
|
||||
in mat3 TBN;
|
||||
|
||||
out vec4 outColor;
|
||||
|
||||
@ -100,8 +102,8 @@ void main()
|
||||
|
||||
vec4 texColor = texture(textureSampler, TexCoords);
|
||||
|
||||
vec3 normal = normalize(vecNormal);
|
||||
|
||||
vec3 normal = normalize(texture(normalSampler, TexCoords).xyz * TBN);
|
||||
//vec3 normal = normalize(vecNormal);
|
||||
vec3 viewDir = normalize(cameraPos-worldPos);
|
||||
|
||||
vec3 lightDirs[4];
|
||||
|
@ -20,6 +20,7 @@ uniform vec3 cameraPos;
|
||||
out vec3 viewDirTS;
|
||||
out vec3 lightDirTS[10];
|
||||
out vec3 spotlightDirTS;
|
||||
out mat3 TBN;
|
||||
|
||||
void main()
|
||||
{
|
||||
@ -31,7 +32,7 @@ void main()
|
||||
|
||||
vec3 w_tangent = normalize(mat3(modelMatrix)*vertexTangent);
|
||||
vec3 w_bitangent = normalize(mat3(modelMatrix)*vertexBitangent);
|
||||
mat3 TBN = transpose(mat3(w_tangent, w_bitangent, vecNormal));
|
||||
TBN = transpose(mat3(w_tangent, w_bitangent, vecNormal));
|
||||
|
||||
vec3 V = normalize(cameraPos-worldPos);
|
||||
viewDirTS = TBN*V;
|
||||
|
@ -190,7 +190,7 @@ void Core::drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, gl
|
||||
Core::DrawContext(context);
|
||||
}
|
||||
|
||||
void Core::drawObjectPBRTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID, float roughness, float metallic, GLuint program) {
|
||||
void Core::drawObjectPBRTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID, GLuint normalID, float roughness, float metallic, GLuint program) {
|
||||
Spaceship* spaceship = Spaceship::getInstance();
|
||||
glm::mat4 viewProjectionMatrix = Core::createPerspectiveMatrix() * spaceship->createCameraMatrix();
|
||||
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
|
||||
@ -201,10 +201,12 @@ void Core::drawObjectPBRTexture(Core::RenderContext& context, glm::mat4 modelMat
|
||||
|
||||
glUniform1f(glGetUniformLocation(program, "roughness"), roughness);
|
||||
glUniform1f(glGetUniformLocation(program, "metallic"), metallic);
|
||||
;
|
||||
//glUniform3f(glGetUniformLocation(program, "color"), color.x, color.y, color.z);
|
||||
|
||||
Core::SetActiveTexture(textureID, "textureSampler", program, 0);
|
||||
glUniform1i(glGetUniformLocation(program, "textureSampler"), 0);
|
||||
|
||||
Core::SetActiveTexture(normalID, "normalSampler", program, 1);
|
||||
glUniform1i(glGetUniformLocation(program, "normalSampler"), 1);
|
||||
|
||||
glUniform3f(glGetUniformLocation(program, "cameraPos"), spaceship->cameraPos.x, spaceship->cameraPos.y, spaceship->cameraPos.z);
|
||||
|
||||
|
@ -74,5 +74,5 @@ namespace Core
|
||||
glm::mat4 createPerspectiveMatrix();
|
||||
void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec3 color, float roughness, float metallic, GLuint program);
|
||||
void loadModelToContext(std::string path, Core::RenderContext& context);
|
||||
void drawObjectPBRTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID, float roughness, float metallic, GLuint program);
|
||||
void drawObjectPBRTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID, GLuint normalID, float roughness, float metallic, GLuint program);
|
||||
}
|
@ -39,6 +39,7 @@ namespace models {
|
||||
namespace texture {
|
||||
GLuint cubemapTexture;
|
||||
GLuint spaceshipTexture;
|
||||
GLuint spaceshipNormal;
|
||||
GLuint spriteTexture;
|
||||
GLuint earthTexture;
|
||||
}
|
||||
@ -196,14 +197,15 @@ void renderScene(GLFWwindow* window)
|
||||
drawObjectPBRTexture(models::spaceshipContext,
|
||||
spaceship->calculateModelMatrix(),
|
||||
texture::spaceshipTexture,
|
||||
texture::spaceshipNormal,
|
||||
spaceship->roughness, spaceship->metallic, programTex
|
||||
);
|
||||
|
||||
//Core::SetActiveTexture(texture::earthTexture, "textureSampler", programTex, 0);
|
||||
drawObjectPBRTexture(models::sphereContext, glm::translate(glm::vec3(10.f, 0, 0)) * glm::scale(glm::vec3(1.0f)), texture::earthTexture, 0.3, 0.0, programTex);
|
||||
//drawObjectPBRTexture(models::sphereContext, glm::translate(glm::vec3(10.f, 0, 0)) * glm::scale(glm::vec3(1.0f)), texture::earthTexture, 0.3, 0.0, programTex);
|
||||
//glm::translate(pointlightPos) * glm::scale(glm::vec3(1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(10.f, 0, 0)) *
|
||||
Core::SetActiveTexture(texture::earthTexture, "textureSampler", programTex, 0);
|
||||
drawObjectPBRTexture(models::sphereContext, glm::translate(pointlightPos) * glm::scale(glm::vec3(1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(10.f, 0, 0)) * glm::scale(glm::vec3(0.3f)), texture::earthTexture, 0.3, 0.0, programTex);
|
||||
//Core::SetActiveTexture(texture::earthTexture, "textureSampler", programTex, 0);
|
||||
//drawObjectPBRTexture(models::sphereContext, glm::translate(pointlightPos) * glm::scale(glm::vec3(1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(10.f, 0, 0)) * glm::scale(glm::vec3(0.3f)), texture::earthTexture, 0.3, 0.0, programTex);
|
||||
|
||||
//glUseProgram(programSprite);
|
||||
//for (const auto& enemy : enemies) {
|
||||
@ -345,6 +347,7 @@ void init(GLFWwindow* window)
|
||||
loadPlanetsTextures();
|
||||
texture::cubemapTexture = Core::LoadCubemap(cubeFaces);
|
||||
texture::spaceshipTexture = Core::LoadTexture("./textures/spaceship/Material.001_Base_color.jpg");
|
||||
texture::spaceshipNormal = Core::LoadTexture("./textures/spaceship/Material.001_Normal_DirectX.jpg");
|
||||
texture::earthTexture = Core::LoadTexture("./textures/planets/8k_earth_daymap.jpg");
|
||||
|
||||
spaceship->createParticles();
|
||||
|
Loading…
Reference in New Issue
Block a user