Add TIFF import
Completed LoadTexture() to allow for TIFF files and loaded the color texture to the shaders. Some minor changes to the fragment shaders, but nothing major.
This commit is contained in:
parent
6a35ad9e5c
commit
0b3c7b0f74
14
imgui.ini
14
imgui.ini
|
@ -4,8 +4,8 @@ Size=400,400
|
|||
Collapsed=0
|
||||
|
||||
[Window][Terrain Controls]
|
||||
Pos=863,19
|
||||
Size=417,701
|
||||
Pos=925,19
|
||||
Size=403,701
|
||||
Collapsed=0
|
||||
DockId=0x00000002,0
|
||||
|
||||
|
@ -19,17 +19,17 @@ Collapsed=0
|
|||
|
||||
[Window][TerraVisor]
|
||||
Pos=0,0
|
||||
Size=1280,720
|
||||
Size=1328,720
|
||||
Collapsed=0
|
||||
|
||||
[Window][Scene Window]
|
||||
Pos=0,19
|
||||
Size=861,701
|
||||
Size=923,701
|
||||
Collapsed=0
|
||||
DockId=0x00000001,0
|
||||
|
||||
[Docking][Data]
|
||||
DockSpace ID=0x6F42A598 Window=0xE80F322C Pos=0,19 Size=1280,701 Split=X Selected=0x9F2D9299
|
||||
DockNode ID=0x00000001 Parent=0x6F42A598 SizeRef=861,701 CentralNode=1 Selected=0x9F2D9299
|
||||
DockNode ID=0x00000002 Parent=0x6F42A598 SizeRef=417,701 Selected=0xF69494A7
|
||||
DockSpace ID=0x6F42A598 Window=0xE80F322C Pos=0,19 Size=1328,701 Split=X Selected=0x9F2D9299
|
||||
DockNode ID=0x00000001 Parent=0x6F42A598 SizeRef=875,701 CentralNode=1 Selected=0x9F2D9299
|
||||
DockNode ID=0x00000002 Parent=0x6F42A598 SizeRef=403,701 Selected=0xF69494A7
|
||||
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
#ifndef LOAD_TEXTURE_H_
|
||||
#define LOAD_TEXTURE_H_
|
||||
|
||||
#include <GL/glew.h>
|
||||
|
||||
namespace Texture {
|
||||
void LoadTexture(const char* filePath);
|
||||
GLuint LoadTexture(const char* filePath);
|
||||
}
|
||||
|
||||
#endif // LOAD_TEXTURE_H_
|
|
@ -1,6 +1,7 @@
|
|||
#version 450 core
|
||||
|
||||
layout(binding = 0) uniform sampler2D heightTexture;
|
||||
layout(binding = 1) uniform sampler2D colorTexture;
|
||||
|
||||
in TE_OUT {
|
||||
vec3 position;
|
||||
|
@ -53,7 +54,7 @@ vec3 calculateNormalsFromHeightTexture() {
|
|||
}
|
||||
|
||||
void main() {
|
||||
albedoGbuffer = vec4(vec3(texture(heightTexture, fs_in.texCoord).r), 1.0);
|
||||
positionGbuffer = vec4(fs_in.position, 1.0);
|
||||
normalGbuffer = vec4(fs_in.normal, 1.0);
|
||||
albedoGbuffer = texture(colorTexture, vec2(fs_in.texCoord.x, -fs_in.texCoord.y));
|
||||
positionGbuffer = vec4(fs_in.position, 1.0f);
|
||||
normalGbuffer = vec4(fs_in.normal, 1.0f);
|
||||
}
|
|
@ -23,7 +23,7 @@ vec3 calculateDisneySpecular(vec3 N, vec3 V, vec3 L, vec3 albedo) {
|
|||
vec3 F = F0 + (1.0f - F0) * pow(1.0f - dot(H, V), 5.0f);
|
||||
|
||||
// Normal Distribution Function (GGX)
|
||||
float roughness = 0.5f;
|
||||
float roughness = 0.7f;
|
||||
float alpha = roughness * roughness;
|
||||
float alpha2 = alpha * alpha;
|
||||
|
||||
|
@ -47,7 +47,7 @@ vec3 calculateDisneySpecular(vec3 N, vec3 V, vec3 L, vec3 albedo) {
|
|||
void main()
|
||||
{
|
||||
vec4 albedo = texture(albedoGbuffer, tex_coords);
|
||||
albedo = vec4(vec3(0.18f), texture(albedoGbuffer, tex_coords).a);
|
||||
// albedo = vec4(vec3(0.18f), texture(albedoGbuffer, tex_coords).a);
|
||||
vec4 position = texture(positionGbuffer, tex_coords);
|
||||
vec4 normal = texture(normalGbuffer, tex_coords);
|
||||
|
||||
|
@ -76,7 +76,7 @@ void main()
|
|||
vec4 specular = vec4(calculateDisneySpecular(N, V, L, albedo.rgb), albedo.a);
|
||||
|
||||
// Light Intensity
|
||||
vec4 lightColor = vec4(vec3(50.0f), 1.0f);
|
||||
vec4 lightColor = vec4(vec3(25.0f), 1.0f);
|
||||
vec4 finalDiffuse = (diffuse + specular) * lightColor + (ambientLight * 0.1f);
|
||||
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <FreeImage.h>
|
||||
|
||||
namespace Texture {
|
||||
void LoadTexture(const char* filePath) {
|
||||
GLuint LoadTexture(const char* filePath) {
|
||||
FIBITMAP* bitmap = FreeImage_Load(FIF_TIFF, filePath, TIFF_DEFAULT);
|
||||
|
||||
if(!bitmap) {
|
||||
|
@ -13,5 +13,26 @@ namespace Texture {
|
|||
|
||||
FIBITMAP* bitmap32 = FreeImage_ConvertTo32Bits(bitmap);
|
||||
FreeImage_Unload(bitmap);
|
||||
|
||||
int width = FreeImage_GetWidth(bitmap32);
|
||||
int height = FreeImage_GetHeight(bitmap32);
|
||||
BYTE* pixels = FreeImage_GetBits(bitmap32);
|
||||
|
||||
GLuint textureID;
|
||||
glGenTextures(1, &textureID);
|
||||
glBindTexture(GL_TEXTURE_2D, textureID);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, pixels);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
FreeImage_Unload(bitmap32);
|
||||
|
||||
return textureID;
|
||||
}
|
||||
}
|
|
@ -28,6 +28,7 @@
|
|||
#include "Uniforms.h"
|
||||
#include "InitShader.h"
|
||||
#include "DebugCallback.h"
|
||||
#include "load_texture.h"
|
||||
|
||||
namespace {
|
||||
|
||||
|
@ -40,7 +41,9 @@ const std::string kQuadVertexPath = "shaders/quad_vertex.glsl";
|
|||
const std::string kQuadFragmentPath = "shaders/quad_fragment.glsl";
|
||||
|
||||
const std::string kHGTPath = "hgt/N02E016.hgt";
|
||||
GLuint tex_id = -1;
|
||||
const std::string kColPath = "hgt/color/N02E16_col.tiff";
|
||||
GLuint tex_id = 0;
|
||||
GLuint col_id = 0;
|
||||
|
||||
float tessellationFactor = 32.0f;
|
||||
|
||||
|
@ -83,6 +86,7 @@ void Scene::Init() {
|
|||
|
||||
std::vector<int16_t> heightData = LoadHGT(kHGTPath, 3601, 3601);
|
||||
tex_id = CreateHeightmapTexture(heightData, 3601, 3601);
|
||||
col_id = Texture::LoadTexture(kColPath.c_str());
|
||||
|
||||
InitBuffers();
|
||||
ReloadShader();
|
||||
|
@ -229,9 +233,13 @@ void Scene::Display(GLFWwindow* window) {
|
|||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, tex_id);
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, col_id);
|
||||
|
||||
GLint heightTextureLoc = glGetUniformLocation(shader_program_, "heightTexture");
|
||||
glUniform1i(heightTextureLoc, 0);
|
||||
GLint colorTextureLoc = glGetUniformLocation(shader_program_, "colorTexture");
|
||||
glUniform1i(colorTextureLoc, 1);
|
||||
|
||||
GLint tessFactorLoc = glGetUniformLocation(shader_program_, "tessellationFactor");
|
||||
glUniform1f(tessFactorLoc, tessellationFactor);
|
||||
|
@ -254,8 +262,8 @@ void Scene::Display(GLFWwindow* window) {
|
|||
glActiveTexture(GL_TEXTURE2);
|
||||
glBindTexture(GL_TEXTURE_2D, geo_fbo_.normalTexture);
|
||||
|
||||
GLint colorTextureLoc = glGetUniformLocation(quad_shader_program_, "albedoGbuffer");
|
||||
glUniform1i(colorTextureLoc, 0);
|
||||
GLint albedoTextureLoc = glGetUniformLocation(quad_shader_program_, "albedoGbuffer");
|
||||
glUniform1i(albedoTextureLoc, 0);
|
||||
GLint positionTextureLoc = glGetUniformLocation(quad_shader_program_, "positionGbuffer");
|
||||
glUniform1i(positionTextureLoc, 1);
|
||||
GLint normalTextureLoc = glGetUniformLocation(quad_shader_program_, "normalGbuffer");
|
||||
|
|
Loading…
Reference in New Issue