-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b046b63
commit 0da3889
Showing
6 changed files
with
586 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
Android/app/src/main/cpp/examples/08_ShadowMappingOnmi/OnmiCamera.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// Created by wjl on 2021/8/16. | ||
// | ||
|
||
#include "OnmiCamera.h" | ||
|
||
#include <glm/gtc/matrix_transform.hpp> | ||
|
||
BEGIN_NAMESPACE(VulkanEngine) | ||
|
||
void OnmiCamera::prepareUniformBuffers() { | ||
VK_CHECK_RESULT(m_context->vulkanDevice->createBuffer( | ||
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, | ||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, | ||
&m_uniformBuffer, sizeof(m_mvp), &m_mvp)); | ||
VK_CHECK_RESULT(m_uniformBuffer.map()); | ||
updateUniformBuffers(); | ||
} | ||
|
||
void OnmiCamera::updateUniformBuffers() { | ||
m_mvp.projection = glm::perspective((float)(M_PI / 2.0), 1.0f, 0.1f, 64.0f); | ||
m_mvp.view = glm::mat4(1.0f); | ||
m_mvp.model = glm::translate(glm::mat4(1.0f), glm::vec3(-m_mvp.lightpos.x, -m_mvp.lightpos.y, -m_mvp.lightpos.z)); | ||
memcpy(m_uniformBuffer.mapped, &m_mvp, sizeof(m_mvp)); | ||
} | ||
|
||
END_NAMESPACE(VulkanEngine) |
29 changes: 29 additions & 0 deletions
29
Android/app/src/main/cpp/examples/08_ShadowMappingOnmi/OnmiCamera.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// Created by wjl on 2021/8/16. | ||
// | ||
|
||
#ifndef LEARNVULKAN_ONMICAMERA_H | ||
#define LEARNVULKAN_ONMICAMERA_H | ||
|
||
#include "VulkanBuffer.h" | ||
|
||
BEGIN_NAMESPACE(VulkanEngine) | ||
|
||
class OnmiCamera : public VulkanBuffer { | ||
public: | ||
struct { | ||
glm::mat4 projection; | ||
glm::mat4 view; | ||
glm::mat4 model; | ||
glm::vec4 lightpos; | ||
}m_mvp; | ||
public: | ||
OnmiCamera() = default; | ||
|
||
virtual void prepareUniformBuffers() override; | ||
virtual void updateUniformBuffers() override ; | ||
}; | ||
|
||
END_NAMESPACE(VulkanEngine) | ||
|
||
#endif //LEARNVULKAN_ONMICAMERA_H |
31 changes: 31 additions & 0 deletions
31
Android/app/src/main/cpp/examples/08_ShadowMappingOnmi/ReflectParaBuffer.cxx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// Created by wjl on 21-4-10. | ||
// | ||
|
||
#include "ReflectParaBuffer.h" | ||
|
||
BEGIN_NAMESPACE(VulkanEngine) | ||
|
||
void ReflectParaBuffer::reflect() { | ||
if(getReflect() <= 0.f){ | ||
setReflect(1.f); | ||
} | ||
else{ | ||
setReflect(0.f); | ||
} | ||
} | ||
|
||
void ReflectParaBuffer::prepareUniformBuffers() { | ||
VK_CHECK_RESULT(m_context->vulkanDevice->createBuffer( | ||
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, | ||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, | ||
&m_uniformBuffer, sizeof(m_para), &m_para)); | ||
VK_CHECK_RESULT(m_uniformBuffer.map()); | ||
updateUniformBuffers(); | ||
} | ||
|
||
void ReflectParaBuffer::updateUniformBuffers() { | ||
memcpy(m_uniformBuffer.mapped, &m_para, sizeof(m_para)); | ||
} | ||
|
||
END_NAMESPACE(VulkanEngine) |
34 changes: 34 additions & 0 deletions
34
Android/app/src/main/cpp/examples/08_ShadowMappingOnmi/ReflectParaBuffer.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// Created by wjl on 21-4-10. | ||
// | ||
|
||
#ifndef LEARNVULKAN_REFLECTPARABUFFER_H | ||
#define LEARNVULKAN_REFLECTPARABUFFER_H | ||
|
||
#include "VulkanBuffer.h" | ||
|
||
BEGIN_NAMESPACE(VulkanEngine) | ||
|
||
class ReflectParaBuffer : public VulkanBuffer { | ||
public: | ||
struct ReflectPara{ | ||
glm::vec4 para; | ||
} m_para; | ||
|
||
public: | ||
ReflectParaBuffer() = default; | ||
~ReflectParaBuffer() = default; | ||
|
||
void setReflect(float value) { m_para.para[0] = value; } | ||
|
||
float getReflect() { return m_para.para[0];} | ||
|
||
void reflect(); | ||
|
||
virtual void prepareUniformBuffers() override; | ||
virtual void updateUniformBuffers() override ; | ||
}; | ||
|
||
END_NAMESPACE(VulkanEngine) | ||
|
||
#endif //LEARNVULKAN_REFLECTPARABUFFER_H |
Oops, something went wrong.