mirror of
https://github.com/redstrate/Novus.git
synced 2025-04-28 06:37:44 +00:00
Use mdl normals to display some lighting
This commit is contained in:
parent
a2688ca2dc
commit
0b01715824
5 changed files with 29 additions and 10 deletions
|
@ -1,7 +1,17 @@
|
||||||
#version 450
|
#version 450
|
||||||
|
|
||||||
|
layout(location = 0) in vec3 inNormal;
|
||||||
|
layout(location = 1) in vec3 inFragPos;
|
||||||
|
|
||||||
layout(location = 0) out vec4 outColor;
|
layout(location = 0) out vec4 outColor;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
outColor = vec4(0.0, 1.0, 0.0, 1.0);
|
const vec3 lightPos = vec3(3);
|
||||||
|
|
||||||
|
vec3 norm = normalize(inNormal);
|
||||||
|
vec3 lightDir = normalize(lightPos - inFragPos);
|
||||||
|
|
||||||
|
float diff = max(dot(norm, lightDir), 0.0);
|
||||||
|
|
||||||
|
outColor = vec4(0.0, 1.0, 0.0, 1.0) * diff;
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
|
@ -1,6 +1,10 @@
|
||||||
#version 450
|
#version 450
|
||||||
|
|
||||||
layout(location = 0) in vec3 inPosition;
|
layout(location = 0) in vec3 inPosition;
|
||||||
|
layout(location = 1) in vec3 inNormal;
|
||||||
|
|
||||||
|
layout(location = 0) out vec3 outNormal;
|
||||||
|
layout(location = 1) out vec3 outFragPos;
|
||||||
|
|
||||||
layout(push_constant) uniform PushConstant {
|
layout(push_constant) uniform PushConstant {
|
||||||
mat4 mvp;
|
mat4 mvp;
|
||||||
|
@ -8,4 +12,6 @@ layout( push_constant ) uniform PushConstant {
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
gl_Position = mvp * vec4(inPosition, 1.0);
|
gl_Position = mvp * vec4(inPosition, 1.0);
|
||||||
|
outNormal = inNormal;
|
||||||
|
outFragPos = inNormal;
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
|
@ -493,7 +493,7 @@ RenderModel Renderer::addModel(const Model& model) {
|
||||||
for(auto part : model.lods[0].parts) {
|
for(auto part : model.lods[0].parts) {
|
||||||
RenderPart renderPart;
|
RenderPart renderPart;
|
||||||
|
|
||||||
size_t vertexSize = part.vertices.size() * sizeof(float) * 3;
|
size_t vertexSize = part.vertices.size() * sizeof(Vertex);
|
||||||
auto[vertexBuffer, vertexMemory] = createBuffer(vertexSize, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT);
|
auto[vertexBuffer, vertexMemory] = createBuffer(vertexSize, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT);
|
||||||
|
|
||||||
size_t indexSize = part.indices.size() * sizeof(uint16_t);
|
size_t indexSize = part.indices.size() * sizeof(uint16_t);
|
||||||
|
@ -504,10 +504,7 @@ RenderModel Renderer::addModel(const Model& model) {
|
||||||
void* mapped_data = nullptr;
|
void* mapped_data = nullptr;
|
||||||
vkMapMemory(device, vertexMemory, 0, vertexSize, 0, &mapped_data);
|
vkMapMemory(device, vertexMemory, 0, vertexSize, 0, &mapped_data);
|
||||||
|
|
||||||
for (int i = 0; i < part.vertices.size(); i++) {
|
memcpy(mapped_data, part.vertices.data(), vertexSize);
|
||||||
memcpy((char *) mapped_data + ((sizeof(float) * 3) * i),
|
|
||||||
part.vertices[i].position.data(), sizeof(float) * 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
VkMappedMemoryRange range = {};
|
VkMappedMemoryRange range = {};
|
||||||
range.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
|
range.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
|
||||||
|
@ -564,10 +561,16 @@ void Renderer::initPipeline() {
|
||||||
std::array<VkPipelineShaderStageCreateInfo, 2> shaderStages = {vertexShaderStageInfo, fragmentShaderStageInfo};
|
std::array<VkPipelineShaderStageCreateInfo, 2> shaderStages = {vertexShaderStageInfo, fragmentShaderStageInfo};
|
||||||
|
|
||||||
VkVertexInputBindingDescription binding = {};
|
VkVertexInputBindingDescription binding = {};
|
||||||
binding.stride = sizeof(float) * 3;
|
binding.stride = sizeof(Vertex);
|
||||||
|
|
||||||
VkVertexInputAttributeDescription positionAttribute = {};
|
VkVertexInputAttributeDescription positionAttribute = {};
|
||||||
positionAttribute.format = VK_FORMAT_R32G32B32_SFLOAT;
|
positionAttribute.format = VK_FORMAT_R32G32B32_SFLOAT;
|
||||||
|
positionAttribute.offset = offsetof(Vertex, position);
|
||||||
|
|
||||||
|
VkVertexInputAttributeDescription normalAttribute = {};
|
||||||
|
normalAttribute.format = VK_FORMAT_R32G32B32_SFLOAT;
|
||||||
|
normalAttribute.location = 1;
|
||||||
|
normalAttribute.offset = offsetof(Vertex, normal);
|
||||||
|
|
||||||
VkPipelineVertexInputStateCreateInfo vertexInputState = {};
|
VkPipelineVertexInputStateCreateInfo vertexInputState = {};
|
||||||
vertexInputState.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
|
vertexInputState.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
|
||||||
|
|
Loading…
Add table
Reference in a new issue