Implemented basic normal-dot product shading, preparing for more complex methods such as Blinn-Phong and PBR
This commit is contained in:
@@ -23,8 +23,8 @@ void initImGuiWindow() {
|
||||
}
|
||||
|
||||
ImGui::DragFloat3("Camera Position", Graphics::getCamPos());
|
||||
ImGui::DragFloat3("Light Position", Graphics::getLightPos());
|
||||
ImGui::DragFloat3("Center Position", Graphics::getCenterPos());
|
||||
ImGui::DragFloat3("Up Direction", Graphics::getUpDir());
|
||||
ImGui::DragFloat("Depth of Field", &Graphics::getDepthField(), 0.1f, 1.0f,
|
||||
180.0f, NULL, ImGuiSliderFlags_AlwaysClamp);
|
||||
ImGui::DragFloat2("Near and Far fields", Graphics::getDistanceField());
|
||||
|
||||
@@ -88,15 +88,15 @@ void createInstance() {
|
||||
}
|
||||
}
|
||||
void initAgnosia() {
|
||||
Material *vikingRoomMaterial =
|
||||
new Material("vikingRoomMaterial", "assets/textures/viking_room.png");
|
||||
Material *sphereMaterial =
|
||||
new Material("sphereMaterial", "assets/textures/checkermap.png");
|
||||
Material *stanfordDragonMaterial =
|
||||
new Material("stanfordDragonMaterial", "assets/textures/checkermap.png");
|
||||
Material *teapotMaterial =
|
||||
new Material("teapotMaterial", "assets/textures/checkermap.png");
|
||||
Model *vikingRoom =
|
||||
new Model("vikingRoom", *vikingRoomMaterial,
|
||||
"assets/models/viking_room.obj", glm::vec3(0.0f, 0.0f, 0.0f));
|
||||
Model *uvSphere =
|
||||
new Model("uvSphere", *sphereMaterial, "assets/models/UVSphere.obj",
|
||||
glm::vec3(0.0f, 0.0f, 0.0f));
|
||||
Model *stanfordDragon = new Model("stanfordDragon", *stanfordDragonMaterial,
|
||||
"assets/models/StanfordDragon800k.obj",
|
||||
glm::vec3(0.0f, 2.0f, 0.0f));
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <iostream>
|
||||
#include <vulkan/vulkan_core.h>
|
||||
|
||||
float lightPos[4] = {5.0f, 5.0f, 5.0f, 0.44f};
|
||||
float camPos[4] = {3.0f, 3.0f, 3.0f, 0.44f};
|
||||
float centerPos[4] = {0.0f, 0.0f, 0.0f, 0.44f};
|
||||
float upDir[4] = {0.0f, 0.0f, 1.0f, 0.44f};
|
||||
@@ -363,6 +364,7 @@ void Graphics::recordCommandBuffer(VkCommandBuffer commandBuffer,
|
||||
Agnosia_T::GPUPushConstants pushConsts;
|
||||
pushConsts.vertexBuffer = model->getBuffers().vertexBufferAddress;
|
||||
pushConsts.objPosition = model->getPos();
|
||||
pushConsts.lightPos = glm::vec3(lightPos[0], lightPos[1], lightPos[2]);
|
||||
pushConsts.textureID = texID;
|
||||
|
||||
pushConsts.model =
|
||||
@@ -433,6 +435,7 @@ void Graphics::recordCommandBuffer(VkCommandBuffer commandBuffer,
|
||||
}
|
||||
|
||||
float *Graphics::getCamPos() { return camPos; }
|
||||
float *Graphics::getLightPos() { return lightPos; }
|
||||
float *Graphics::getCenterPos() { return centerPos; }
|
||||
float *Graphics::getUpDir() { return upDir; }
|
||||
float &Graphics::getDepthField() { return depthField; }
|
||||
|
||||
@@ -15,6 +15,7 @@ public:
|
||||
uint32_t imageIndex);
|
||||
|
||||
static float *getCamPos();
|
||||
static float *getLightPos();
|
||||
static float *getCenterPos();
|
||||
static float *getUpDir();
|
||||
static float &getDepthField();
|
||||
|
||||
@@ -15,6 +15,7 @@ layout(buffer_reference, scalar) readonly buffer VertexBuffer{
|
||||
layout( push_constant, scalar ) uniform constants {
|
||||
VertexBuffer vertBuffer;
|
||||
vec3 objPos;
|
||||
vec3 lightPos;
|
||||
int textureID;
|
||||
mat4 model;
|
||||
mat4 view;
|
||||
|
||||
@@ -5,11 +5,18 @@
|
||||
layout(binding = 1) uniform sampler2D texSampler[];
|
||||
|
||||
|
||||
layout(location = 0) in vec3 fragColor;
|
||||
layout(location = 1) in vec2 fragTexCoord;
|
||||
layout(location = 0) in vec3 v_norm;
|
||||
layout(location = 1) in vec3 v_pos;
|
||||
layout(location = 2) in vec2 texCoord;
|
||||
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
void main() {
|
||||
outColor = texture(texSampler[PushConstants.textureID], fragTexCoord) * vec4(fragColor, 1.0f);
|
||||
vec3 diffuseColor = texture(texSampler[PushConstants.textureID], texCoord).rgb;
|
||||
vec3 ambientColor = vec3(0.05f,0.05f, 0.05f) * diffuseColor;
|
||||
float lightPower = 5;
|
||||
vec3 lightColor = vec3(1.0f, 1.0f, 1.0f);
|
||||
float cosTheta = dot(PushConstants.lightPos, v_norm);
|
||||
float sqrDist = distance(v_pos, PushConstants.lightPos)*distance(v_pos, PushConstants.lightPos);
|
||||
outColor = vec4(ambientColor + clamp(diffuseColor * lightColor * lightPower * cosTheta / sqrDist, vec3(0,0,0), vec3(1,1,1)), 1.0f);
|
||||
}
|
||||
|
||||
@@ -2,14 +2,16 @@
|
||||
#extension GL_GOOGLE_include_directive : enable
|
||||
#include "common.glsl"
|
||||
|
||||
layout(location = 0) out vec3 fragColor;
|
||||
layout(location = 1) out vec2 fragTexCoord;
|
||||
layout(location = 0) out vec3 v_norm;
|
||||
layout(location = 1) out vec3 v_pos;
|
||||
layout(location = 2) out vec2 texCoord;
|
||||
|
||||
void main() {
|
||||
Vertex vertex = PushConstants.vertBuffer.vertices[gl_VertexIndex];
|
||||
|
||||
gl_Position = PushConstants.proj * PushConstants.view * PushConstants.model *
|
||||
vec4(vertex.pos + PushConstants.objPos, 1.0f);
|
||||
fragColor = vertex.color.rgb;
|
||||
fragTexCoord = vertex.texCoord;
|
||||
v_norm = vertex.normal;
|
||||
v_pos = vertex.pos;
|
||||
texCoord = vertex.texCoord;
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ public:
|
||||
struct GPUPushConstants {
|
||||
VkDeviceAddress vertexBuffer;
|
||||
glm::vec3 objPosition;
|
||||
glm::vec3 lightPos;
|
||||
int textureID;
|
||||
glm::mat4 model;
|
||||
glm::mat4 view;
|
||||
|
||||
Reference in New Issue
Block a user