fix: critical vertex shader bug

This commit is contained in:
Szymon Szczubkowski 2024-01-24 23:34:16 +01:00
parent 47c8242bfd
commit a9de5e6a71
13 changed files with 39 additions and 15 deletions

View File

@ -39,6 +39,8 @@
<ItemGroup>
<None Include="shaders\pbr.frag" />
<None Include="shaders\pbr.vert" />
<None Include="shaders\sun.frag" />
<None Include="shaders\sun.vert" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{6D813233-7D21-4888-944E-8E3CCAC3EFD3}</ProjectGuid>

View File

@ -97,5 +97,11 @@
<None Include="shaders\pbr.vert">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\sun.frag">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\sun.vert">
<Filter>Shader Files</Filter>
</None>
</ItemGroup>
</Project>

View File

@ -15,10 +15,10 @@ out vec2 TexCoords;
void main()
{
TexCoords = -vertexTexCoord;
TexCoords = vertexTexCoord;
worldPos = vec3(modelMatrix * vec4(vertexPosition,1));
Normal = normalize((modelMatrix * vec4(vertexNormal,0)).xyz);
gl_Position = transformation * vec4(worldPos, 1.0);
gl_Position = transformation * vec4(vertexPosition, 1.0);
}

View File

@ -16,15 +16,17 @@ GLuint programSun;
Core::Shader_Loader shaderLoader;
Core::RenderContext shipContext;
Core::RenderContext earthContext;
Core::RenderContext sunContext;
Core::RenderContext planetContext;
namespace texture {
GLuint earth_albedo;
GLuint earth_normal;
GLuint sun;
GLuint planet_albedo;
GLuint planet_ao;
GLuint planet_normal;
GLuint planet_roughness;
}
float aspectRatio = 1.f;
@ -42,8 +44,8 @@ void shutdown(GLFWwindow* window);
glm::mat4 createPerspectiveMatrix();
glm::mat4 createCameraMatrix();
void drawObjectEarth(Core::RenderContext& context, glm::mat4 modelMatrix);
void drawObjectSun(Core::RenderContext& context, glm::mat4 modelMatrix);
void drawObjectPlanet(Core::RenderContext& context, glm::mat4 modelMatrix);
void init(GLFWwindow* window)
{
@ -55,15 +57,22 @@ void init(GLFWwindow* window)
programSun = shaderLoader.CreateProgram("shaders/sun.vert", "shaders/sun.frag");
//load models here
loadModelToContext("./models/earth.obj", earthContext);
loadModelToContext("./models/spaceship.obj", shipContext);
loadModelToContext("./models/sun.glb", sunContext);
loadModelToContext("./models/sphere.obj", planetContext);
//load textures here
texture::earth_albedo = Core::LoadTexture("textures/earth/albedo.jpeg");
texture::earth_normal = Core::LoadTexture("textures/earth/bump.jpeg");
texture::sun = Core::LoadTexture("textures/sun/sun.png");
texture::planet_albedo = Core::LoadTexture("textures/planet/albedo.jpg");
texture::planet_ao = Core::LoadTexture("textures/planet/ao.jpg");
texture::planet_normal = Core::LoadTexture("textures/planet/normal.jpg");
texture::planet_roughness = Core::LoadTexture("textures/planet/roughness.jpg");
}
void renderScene(GLFWwindow* window){
@ -72,9 +81,11 @@ void renderScene(GLFWwindow* window){
glUseProgram(program);
float time = glfwGetTime();
//desired objects go here
drawObjectSun(sunContext, glm::mat4());
//drawObjectEarth(earthContext, glm::mat4());
drawObjectSun(sunContext, glm::scale(glm::vec3(0.1f)) * glm::eulerAngleY(time/10));
drawObjectPlanet(planetContext, glm::eulerAngleY(time) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::eulerAngleY(-2*time));
//desired objects end here
glUseProgram(0);
glfwSwapBuffers(window);
@ -96,7 +107,7 @@ void processInput(GLFWwindow* window)
cameraPos += glm::normalize(glm::cross(cameraFront, cameraUp)) * cameraSpeed;
}
void drawObjectEarth(Core::RenderContext& context, glm::mat4 modelMatrix) {
void drawObjectPlanet(Core::RenderContext& context, glm::mat4 modelMatrix) {
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
@ -104,8 +115,13 @@ void drawObjectEarth(Core::RenderContext& context, glm::mat4 modelMatrix) {
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);
glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
Core::SetActiveTexture(texture::earth_albedo, "albedoMap", program, 0);
Core::SetActiveTexture(texture::earth_normal, "normalMap", program, 1);
glUniform3f(glGetUniformLocation(program, "lightPos"), 0, 0, 0);
glUniform3f(glGetUniformLocation(program, "lightColor"), 300, 300, 300);
Core::SetActiveTexture(texture::planet_albedo, "albedoMap", program, 0);
Core::SetActiveTexture(texture::planet_normal, "normalMap", program, 1);
Core::SetActiveTexture(texture::planet_ao, "aoMap", program, 2);
Core::SetActiveTexture(texture::planet_roughness, "roughnessMap", program, 3);
Core::DrawContext(context);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 MiB

BIN
cw_8/textures/planet/ao.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 304 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 311 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB