11.15
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
#################
|
||||
# sub dictionary
|
||||
#################
|
||||
add_subdirectory(standard)
|
||||
@@ -0,0 +1,34 @@
|
||||
add_library(dv_standard_shaders SHARED
|
||||
dll_main.cpp
|
||||
vs_standard.h
|
||||
vs_standard.inc
|
||||
fs_debug_solid_color.h
|
||||
fs_debug_solid_color.cpp
|
||||
fs_debug_base_color.h
|
||||
fs_debug_base_color.cpp
|
||||
fs_debug_normal_texture.h
|
||||
fs_debug_normal_texture.cpp
|
||||
fs_debug_texture_coordinates.h
|
||||
fs_debug_texture_coordinates.cpp
|
||||
fs_debug_geometry_normal.h
|
||||
fs_debug_geometry_normal.cpp
|
||||
)
|
||||
|
||||
add_definitions(-DDV_SHADER_EXPORTS)
|
||||
|
||||
target_include_directories(dv_standard_shaders
|
||||
PRIVATE
|
||||
${DV_AUTO_INCLUDE_PATH}
|
||||
${DV_CORE_INCLUDE_PATH}
|
||||
)
|
||||
|
||||
target_link_libraries(dv_standard_shaders
|
||||
dv_core
|
||||
)
|
||||
|
||||
#################
|
||||
# copy runtime dll(for debug)
|
||||
#################
|
||||
add_custom_command(
|
||||
TARGET dv_standard_shaders POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:dv_standard_shaders> ${CMAKE_BINARY_DIR}/source/console/$<$<CONFIG:Debug>:Debug>$<$<CONFIG:Release>:Release>/)
|
||||
@@ -0,0 +1,82 @@
|
||||
#include "dv_config.h"
|
||||
#include "shader/dvc_shader_interface.h"
|
||||
|
||||
#include "vs_standard.h"
|
||||
#include "fs_debug_solid_color.h"
|
||||
#include "fs_debug_base_color.h"
|
||||
#include "fs_debug_normal_texture.h"
|
||||
#include "fs_debug_texture_coordinates.h"
|
||||
#include "fs_debug_geometry_normal.h"
|
||||
|
||||
class StandardShaderInterface : public davinci::ShaderFileInterface
|
||||
{
|
||||
public:
|
||||
virtual davinci::VertexShaderInterface* getVertexShader(const char* szName)
|
||||
{
|
||||
auto it = m_vertexShaderMap.find(szName);
|
||||
if (it != m_vertexShaderMap.end()) return it->second;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
virtual davinci::PixelShaderInterface* getPixelShader(const char* szName)
|
||||
{
|
||||
auto it = m_fragementShaderMap.find(szName);
|
||||
if (it != m_fragementShaderMap.end()) return it->second;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
public:
|
||||
StandardShaderInterface()
|
||||
{
|
||||
registerVertexShader(new StandardVertexShader<false , false>());
|
||||
registerVertexShader(new StandardVertexShader<true , false>());
|
||||
registerVertexShader(new StandardVertexShader<false , true>());
|
||||
registerVertexShader(new StandardVertexShader<true , true>());
|
||||
|
||||
registerFragementShader(new DebugFragementShader_SolidColor());
|
||||
registerFragementShader(new DebugFragementShader_BaseColor());
|
||||
registerFragementShader(new DebugFragementShader_NormalTexture());
|
||||
registerFragementShader(new DebugFragementShader_TextureCoordinates());
|
||||
registerFragementShader(new DebugFragementShader_GeometryNormal());
|
||||
}
|
||||
|
||||
~StandardShaderInterface()
|
||||
{
|
||||
for (auto it = m_vertexShaderMap.begin(); it != m_vertexShaderMap.end(); ++it)
|
||||
{
|
||||
delete it->second;
|
||||
}
|
||||
m_vertexShaderMap.clear();
|
||||
|
||||
for (auto it = m_fragementShaderMap.begin(); it != m_fragementShaderMap.end(); ++it)
|
||||
{
|
||||
delete it->second;
|
||||
}
|
||||
m_fragementShaderMap.clear();
|
||||
}
|
||||
|
||||
private:
|
||||
void registerVertexShader(davinci::VertexShaderInterface* vertexShader)
|
||||
{
|
||||
m_vertexShaderMap.insert(std::make_pair(vertexShader->getName(), vertexShader));
|
||||
}
|
||||
void registerFragementShader(davinci::PixelShaderInterface* fragementShader)
|
||||
{
|
||||
m_fragementShaderMap.insert(std::make_pair(fragementShader->getName(), fragementShader));
|
||||
}
|
||||
|
||||
private:
|
||||
std::map<std::string, davinci::VertexShaderInterface*> m_vertexShaderMap;
|
||||
std::map<std::string, davinci::PixelShaderInterface*> m_fragementShaderMap;
|
||||
};
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
__declspec(dllexport) davinci::ShaderFileInterface* ShaderFileInterface()
|
||||
{
|
||||
static StandardShaderInterface theInterface;
|
||||
return &theInterface;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#include "fs_debug_base_color.h"
|
||||
#include "device/dvc_device.h"
|
||||
#include "device/dvc_uniform_buffer.h"
|
||||
#include "asset/dvc_texture.h"
|
||||
#include "shader/dvc_shader_functions.h"
|
||||
#include "pipe/dvc_render_pipe.h"
|
||||
|
||||
const char* DebugFragementShader_BaseColor::getName(void) const
|
||||
{
|
||||
return "debug:base_color";
|
||||
}
|
||||
|
||||
void DebugFragementShader_BaseColor::prepare(const davinci::RenderPipe* pipe, davinci::MaterialConstPtr material)
|
||||
{
|
||||
m_pipe = pipe;
|
||||
m_material = material;
|
||||
}
|
||||
|
||||
void DebugFragementShader_BaseColor::process(const davinci::VertexDesc& veretexDesc, const float32_t* pixelData, davinci::fVector4& color)
|
||||
{
|
||||
const davinci::UniformBuffer& uniformBuffer = m_pipe->getUniformBuffer();
|
||||
|
||||
const davinci::VertexDesc::Element* v_uv_Element = veretexDesc.getElement("v_uv");
|
||||
const davinci::fVector2* v_uv = (const davinci::fVector2*)(pixelData + (v_uv_Element->offset / sizeof(float32_t)));
|
||||
|
||||
davinci::fVector4 u_baseColor = davinci::shader::texture2D(*m_pipe, m_material->getBaseColorTexture(), (*v_uv), davinci::fVector4::WHITE);
|
||||
|
||||
color = davinci::fVector4(u_baseColor.xyz(), 1);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "dvc_config.h"
|
||||
#include "shader/dvc_shader_interface.h"
|
||||
|
||||
class DebugFragementShader_BaseColor : public davinci::PixelShaderInterface
|
||||
{
|
||||
public:
|
||||
virtual const char* getName(void) const;
|
||||
|
||||
virtual void prepare(const davinci::RenderPipe* pipe, davinci::MaterialConstPtr material);
|
||||
|
||||
virtual void process(const davinci::VertexDesc& veretexDesc, const float32_t* pixelData,
|
||||
davinci::fVector4& color);
|
||||
|
||||
private:
|
||||
const davinci::RenderPipe* m_pipe = nullptr;
|
||||
davinci::MaterialConstPtr m_material;
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
#include "fs_debug_geometry_normal.h"
|
||||
#include "device/dvc_device.h"
|
||||
#include "device/dvc_uniform_buffer.h"
|
||||
#include "asset/dvc_texture.h"
|
||||
#include "shader/dvc_shader_functions.h"
|
||||
#include "pipe/dvc_render_pipe.h"
|
||||
|
||||
const char* DebugFragementShader_GeometryNormal::getName(void) const
|
||||
{
|
||||
return "debug:geometry_normal";
|
||||
}
|
||||
|
||||
void DebugFragementShader_GeometryNormal::prepare(const davinci::RenderPipe* pipe, davinci::MaterialConstPtr material)
|
||||
{
|
||||
m_pipe = pipe;
|
||||
m_material = material;
|
||||
}
|
||||
|
||||
void DebugFragementShader_GeometryNormal::process(const davinci::VertexDesc& veretexDesc, const float32_t* pixelData, davinci::fVector4& color)
|
||||
{
|
||||
const davinci::UniformBuffer& uniformBuffer = m_pipe->getUniformBuffer();
|
||||
|
||||
const davinci::VertexDesc::Element* v_normal_Element = veretexDesc.getElement("v_normal");
|
||||
const davinci::fVector3* v_normal = (const davinci::fVector3*)(pixelData + (v_normal_Element->offset / sizeof(float32_t)));
|
||||
|
||||
davinci::fVector3 normalColor = *v_normal;
|
||||
normalColor.normalise();
|
||||
|
||||
color = davinci::fVector4(normalColor, 1);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "dvc_config.h"
|
||||
#include "shader/dvc_shader_interface.h"
|
||||
|
||||
class DebugFragementShader_GeometryNormal : public davinci::PixelShaderInterface
|
||||
{
|
||||
public:
|
||||
virtual const char* getName(void) const;
|
||||
|
||||
virtual void prepare(const davinci::RenderPipe* pipe, davinci::MaterialConstPtr material);
|
||||
|
||||
virtual void process(const davinci::VertexDesc& veretexDesc, const float32_t* pixelData,
|
||||
davinci::fVector4& color);
|
||||
|
||||
private:
|
||||
const davinci::RenderPipe* m_pipe = nullptr;
|
||||
davinci::MaterialConstPtr m_material;
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
#include "fs_debug_normal_texture.h"
|
||||
#include "device/dvc_device.h"
|
||||
#include "device/dvc_uniform_buffer.h"
|
||||
#include "asset/dvc_texture.h"
|
||||
#include "shader/dvc_shader_functions.h"
|
||||
#include "pipe/dvc_render_pipe.h"
|
||||
|
||||
const char* DebugFragementShader_NormalTexture::getName(void) const
|
||||
{
|
||||
return "debug:normal_texture";
|
||||
}
|
||||
|
||||
void DebugFragementShader_NormalTexture::prepare(const davinci::RenderPipe* pipe, davinci::MaterialConstPtr material)
|
||||
{
|
||||
m_pipe = pipe;
|
||||
m_material = material;
|
||||
}
|
||||
|
||||
void DebugFragementShader_NormalTexture::process(const davinci::VertexDesc& veretexDesc, const float32_t* pixelData, davinci::fVector4& color)
|
||||
{
|
||||
const davinci::UniformBuffer& uniformBuffer = m_pipe->getUniformBuffer();
|
||||
|
||||
const davinci::VertexDesc::Element* v_uv_Element = veretexDesc.getElement("v_uv");
|
||||
const davinci::fVector2* v_uv = (const davinci::fVector2*)(pixelData + (v_uv_Element->offset / sizeof(float32_t)));
|
||||
|
||||
davinci::fVector4 u_baseColor = davinci::shader::texture2D(*m_pipe, m_material->getNormalTexture(), (*v_uv), davinci::fVector4::WHITE);
|
||||
|
||||
color = davinci::fVector4(u_baseColor.xyz(), 1);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "dvc_config.h"
|
||||
#include "shader/dvc_shader_interface.h"
|
||||
|
||||
class DebugFragementShader_NormalTexture : public davinci::PixelShaderInterface
|
||||
{
|
||||
public:
|
||||
virtual const char* getName(void) const;
|
||||
|
||||
virtual void prepare(const davinci::RenderPipe* pipe, davinci::MaterialConstPtr material);
|
||||
|
||||
virtual void process(const davinci::VertexDesc& veretexDesc, const float32_t* pixelData,
|
||||
davinci::fVector4& color);
|
||||
|
||||
private:
|
||||
const davinci::RenderPipe* m_pipe = nullptr;
|
||||
davinci::MaterialConstPtr m_material;
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
#include "fs_debug_solid_color.h"
|
||||
|
||||
const char* DebugFragementShader_SolidColor::getName(void) const
|
||||
{
|
||||
return "debug:solid_color";
|
||||
}
|
||||
|
||||
void DebugFragementShader_SolidColor::prepare(const davinci::RenderPipe* pipe, davinci::MaterialConstPtr material)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DebugFragementShader_SolidColor::process(const davinci::VertexDesc& veretexDesc, const float32_t* pixelData, davinci::fVector4& color)
|
||||
{
|
||||
color = davinci::fVector4::RED;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "dvc_config.h"
|
||||
#include "shader/dvc_shader_interface.h"
|
||||
|
||||
class DebugFragementShader_SolidColor : public davinci::PixelShaderInterface
|
||||
{
|
||||
public:
|
||||
virtual const char* getName(void) const;
|
||||
|
||||
virtual void prepare(const davinci::RenderPipe* pipe, davinci::MaterialConstPtr material);
|
||||
|
||||
virtual void process(const davinci::VertexDesc& veretexDesc, const float32_t* pixelData,
|
||||
davinci::fVector4& color);
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
#include "fs_debug_texture_coordinates.h"
|
||||
#include "device/dvc_device.h"
|
||||
#include "device/dvc_uniform_buffer.h"
|
||||
#include "asset/dvc_texture.h"
|
||||
#include "shader/dvc_shader_functions.h"
|
||||
#include "pipe/dvc_render_pipe.h"
|
||||
|
||||
const char* DebugFragementShader_TextureCoordinates::getName(void) const
|
||||
{
|
||||
return "debug:texture_coordinates";
|
||||
}
|
||||
|
||||
void DebugFragementShader_TextureCoordinates::prepare(const davinci::RenderPipe* pipe, davinci::MaterialConstPtr material)
|
||||
{
|
||||
m_pipe = pipe;
|
||||
m_material = material;
|
||||
}
|
||||
|
||||
void DebugFragementShader_TextureCoordinates::process(const davinci::VertexDesc& veretexDesc, const float32_t* pixelData, davinci::fVector4& color)
|
||||
{
|
||||
const davinci::UniformBuffer& uniformBuffer = m_pipe->getUniformBuffer();
|
||||
|
||||
const davinci::VertexDesc::Element* v_uv_Element = veretexDesc.getElement("v_uv");
|
||||
const davinci::fVector2* v_uv = (const davinci::fVector2*)(pixelData + (v_uv_Element->offset / sizeof(float32_t)));
|
||||
|
||||
davinci::fVector2 uv = *v_uv;
|
||||
float uv_x = uv.x - std::floor(uv.x);
|
||||
float uv_y = uv.y - std::floor(uv.y);
|
||||
|
||||
color = davinci::fVector4(uv_x, uv_y, 0, 1);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "dvc_config.h"
|
||||
#include "shader/dvc_shader_interface.h"
|
||||
|
||||
class DebugFragementShader_TextureCoordinates : public davinci::PixelShaderInterface
|
||||
{
|
||||
public:
|
||||
virtual const char* getName(void) const;
|
||||
|
||||
virtual void prepare(const davinci::RenderPipe* pipe, davinci::MaterialConstPtr material);
|
||||
|
||||
virtual void process(const davinci::VertexDesc& veretexDesc, const float32_t* pixelData,
|
||||
davinci::fVector4& color);
|
||||
|
||||
private:
|
||||
const davinci::RenderPipe* m_pipe = nullptr;
|
||||
davinci::MaterialConstPtr m_material;
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include "dvc_config.h"
|
||||
#include "shader/dvc_shader_interface.h"
|
||||
|
||||
|
||||
template<bool WithNormal, bool WithUV>
|
||||
class StandardVertexShader : public davinci::VertexShaderInterface
|
||||
{
|
||||
public:
|
||||
virtual const char* getName(void) const;
|
||||
virtual const davinci::VertexDesc& getOutputVertexDesc() const;
|
||||
virtual size_t getOutputVertexByteSize(void) const;
|
||||
virtual void prepare(const davinci::RenderPipe* pipe, SetInputAttributeFunc setInputAttributeFunc);
|
||||
virtual void process(size_t index, void* outputVertex, davinci::fVector3& vertexWorldPos);
|
||||
|
||||
private:
|
||||
const davinci::RenderPipe* m_pipe = nullptr;
|
||||
davinci::VertexDesc m_outputVertexDesc;
|
||||
|
||||
using InputBufferMembers = decltype(std::tuple_cat(
|
||||
std::tuple<davinci::DeviceBufferAccessorConstPtr>(),
|
||||
std::conditional_t<WithNormal, std::tuple<davinci::DeviceBufferAccessorConstPtr>, std::tuple<>>{},
|
||||
std::conditional_t<WithUV, std::tuple<davinci::DeviceBufferAccessorConstPtr>, std::tuple<>>{}
|
||||
));
|
||||
InputBufferMembers m_inputAccessors;
|
||||
|
||||
static constexpr int32_t iPOSITION() { return 0; };
|
||||
static constexpr int32_t iNORMAL() { return 1; };
|
||||
static constexpr int32_t iUV() { return WithNormal+1; };
|
||||
|
||||
//davinci::DeviceBufferAccessorConstPtr& getPositionAccessor();
|
||||
//davinci::DeviceBufferAccessorConstPtr& getNormalAccessor();
|
||||
//davinci::DeviceBufferAccessorConstPtr& getUVAccessor();
|
||||
|
||||
public:
|
||||
StandardVertexShader();
|
||||
virtual ~StandardVertexShader();
|
||||
};
|
||||
|
||||
#include "vs_standard.inc"
|
||||
@@ -0,0 +1,181 @@
|
||||
#include "device/dvc_buffer_accessor.h"
|
||||
#include "math/dvc_vector2.h"
|
||||
#include "math/dvc_vector3.h"
|
||||
#include "math/dvc_matrix4.h"
|
||||
#include "pipe/dvc_render_pipe.h"
|
||||
#include "device/dvc_uniform_buffer.h"
|
||||
|
||||
template<bool WithNormal, bool WithUV>
|
||||
StandardVertexShader<WithNormal, WithUV>::StandardVertexShader()
|
||||
{
|
||||
m_outputVertexDesc.addElement("v_position", davinci::VET_POSITION, davinci::CT_Float32, davinci::DT_Vec3);
|
||||
|
||||
if constexpr(WithNormal)
|
||||
m_outputVertexDesc.addElement("v_normal", davinci::VET_NORMAL, davinci::CT_Float32, davinci::DT_Vec3);
|
||||
|
||||
if constexpr(WithUV)
|
||||
m_outputVertexDesc.addElement("v_uv", davinci::VET_TEXCOORD_0, davinci::CT_Float32, davinci::DT_Vec2);
|
||||
}
|
||||
|
||||
template<bool WithNormal, bool WithUV>
|
||||
StandardVertexShader<WithNormal, WithUV>::~StandardVertexShader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
template<std::size_t N>
|
||||
struct CompileTimeString {
|
||||
std::array<char, N> data{};
|
||||
std::size_t size = 0;
|
||||
|
||||
constexpr void append(const char* str, std::size_t len) {
|
||||
for (std::size_t i = 0; i < len; ++i) {
|
||||
data[size++] = str[i];
|
||||
}
|
||||
}
|
||||
|
||||
constexpr void append(const char* str) {
|
||||
while (*str) {
|
||||
data[size++] = *str++;
|
||||
}
|
||||
}
|
||||
|
||||
constexpr const char* c_str() const { return data.data(); }
|
||||
constexpr std::string_view view() const { return {data.data(), size}; }
|
||||
};
|
||||
|
||||
template<bool WithNormal, bool WithUV>
|
||||
constexpr auto buildNameString()
|
||||
{
|
||||
constexpr const char* prefix = "standard";
|
||||
constexpr const char* normalString = WithNormal ? "+normal" : "-normal";
|
||||
constexpr const char* uvString = WithUV ? "+uv" : "-uv";
|
||||
|
||||
constexpr std::size_t total_len = std::char_traits<char>::length(prefix)
|
||||
+ std::char_traits<char>::length(normalString)
|
||||
+ std::char_traits<char>::length(uvString);
|
||||
|
||||
CompileTimeString<total_len> result;
|
||||
result.append(prefix);
|
||||
result.append(normalString);
|
||||
result.append(uvString);
|
||||
result.append(""); // null terminator
|
||||
return result;
|
||||
}
|
||||
|
||||
template<bool WithNormal, bool WithUV>
|
||||
const char* StandardVertexShader<WithNormal, WithUV>::getName(void) const
|
||||
{
|
||||
static constexpr auto strName = buildNameString<WithNormal, WithUV>();
|
||||
const char* p = strName.c_str();
|
||||
return p;
|
||||
}
|
||||
|
||||
template<bool WithNormal, bool WithUV>
|
||||
const davinci::VertexDesc& StandardVertexShader<WithNormal, WithUV>::getOutputVertexDesc() const
|
||||
{
|
||||
return m_outputVertexDesc;
|
||||
}
|
||||
|
||||
template<bool WithNormal, bool WithUV>
|
||||
size_t StandardVertexShader<WithNormal, WithUV>::getOutputVertexByteSize(void) const
|
||||
{
|
||||
return m_outputVertexDesc.vertexByteSize();
|
||||
}
|
||||
|
||||
template<bool WithNormal, bool WithUV>
|
||||
void StandardVertexShader<WithNormal, WithUV>::prepare(const davinci::RenderPipe* pipe, SetInputAttributeFunc setInputAttributeFunc)
|
||||
{
|
||||
m_pipe = pipe;
|
||||
|
||||
std::get<iPOSITION()>(m_inputAccessors) = setInputAttributeFunc(davinci::VET_POSITION);
|
||||
|
||||
if constexpr(WithNormal)
|
||||
std::get<iNORMAL()>(m_inputAccessors) = setInputAttributeFunc(davinci::VET_NORMAL);
|
||||
|
||||
if constexpr(WithUV)
|
||||
std::get<iUV()>(m_inputAccessors) = setInputAttributeFunc(davinci::VET_TEXCOORD_0);
|
||||
|
||||
}
|
||||
/*
|
||||
template<bool WithNormal, bool WithUV>
|
||||
davinci::DeviceBufferAccessorConstPtr& StandardVertexShader<WithNormal, WithUV>::getPositionAccessor()
|
||||
{
|
||||
return std::get<0>(m_inputAccessors);
|
||||
}
|
||||
|
||||
template<bool WithNormal, bool WithUV>
|
||||
davinci::DeviceBufferAccessorConstPtr& StandardVertexShader<WithNormal, WithUV>::getNormalAccessor()
|
||||
{
|
||||
if constexpr(WithNormal)
|
||||
return std::get<1>(m_inputAccessors);
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template<bool WithNormal, bool WithUV>
|
||||
davinci::DeviceBufferAccessorConstPtr& StandardVertexShader<WithNormal, WithUV>::getUVAccessor()
|
||||
{
|
||||
if constexpr(WithUV)
|
||||
return std::get<WithNormal+1>(m_inputAccessors);
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
*/
|
||||
template<bool WithNormal, bool WithUV>
|
||||
void StandardVertexShader<WithNormal, WithUV>::process(size_t index, void* outputVertex, davinci::fVector3& vertexWorldPos)
|
||||
{
|
||||
static const float DEFAULT_POSITION[] = {0.f, 0.f, 0.f};
|
||||
static const float32_t DEFAULT_NORMAL[] = { 0.f, 0.f, 0.f };
|
||||
static const float32_t DEFAULT_TEXCOORD0[] = { 0.f, 0.f};
|
||||
|
||||
const davinci::UniformBuffer& uniformBuffer = m_pipe->getUniformBuffer();
|
||||
|
||||
davinci::DeviceBufferAccessorConstPtr inputPosition = std::get<0>(m_inputAccessors);
|
||||
|
||||
davinci::DeviceBufferAccessorConstPtr inputNormal = nullptr;
|
||||
if constexpr(WithNormal)
|
||||
inputNormal = std::get<iNORMAL()>(m_inputAccessors);
|
||||
|
||||
davinci::DeviceBufferAccessorConstPtr inputUV = nullptr;
|
||||
if constexpr(WithUV)
|
||||
inputUV = std::get<iUV()>(m_inputAccessors);
|
||||
|
||||
davinci::fVector3 a_position(inputPosition ? (const float32_t*)(inputPosition->getElement(index)) : DEFAULT_POSITION);
|
||||
davinci::fVector3 a_normal(inputNormal ? (const float32_t*)(inputNormal->getElement(index)) : DEFAULT_NORMAL);
|
||||
davinci::fVector2 a_uv(inputUV ? (const float32_t*)(inputUV->getElement(index)) : DEFAULT_TEXCOORD0);
|
||||
|
||||
davinci::fMatrix4 mat_world = davinci::fMatrix4::IDENTITY;
|
||||
if (davinci::fMatrix4* p_mat_world = (davinci::fMatrix4*)(uniformBuffer.getAttribute("self:world_transform")))
|
||||
{
|
||||
mat_world = *p_mat_world;
|
||||
}
|
||||
|
||||
davinci::fMatrix4 mat_camera_view_proj = davinci::fMatrix4::IDENTITY;
|
||||
if (davinci::fMatrix4* p_mat_camera_view_proj = (davinci::fMatrix4*)(uniformBuffer.getAttribute("camera:view_proj_mat")))
|
||||
{
|
||||
mat_camera_view_proj = *p_mat_camera_view_proj;
|
||||
}
|
||||
|
||||
vertexWorldPos = mat_world * a_position;
|
||||
davinci::fVector3 v_position = mat_camera_view_proj * vertexWorldPos;
|
||||
|
||||
int32_t outputOffset=0;
|
||||
memcpy((char*)outputVertex + m_outputVertexDesc.getElement(outputOffset++)->offset, &v_position, sizeof(davinci::fVector3));
|
||||
|
||||
if constexpr(WithNormal)
|
||||
{
|
||||
davinci::fMatrix4 matNormal = davinci::fMatrix4::IDENTITY;
|
||||
if (davinci::fMatrix4* p_mat_normal = (davinci::fMatrix4*)(uniformBuffer.getAttribute("self:world_transform_inverse_trans")))
|
||||
{
|
||||
matNormal = *p_mat_normal;
|
||||
}
|
||||
davinci::fVector3 v_normal = (matNormal * davinci::fVector4(a_normal, 0)).xyz().normalise();
|
||||
memcpy((char*)outputVertex + m_outputVertexDesc.getElement(outputOffset++)->offset, &v_normal, sizeof(davinci::fVector3));
|
||||
}
|
||||
|
||||
if constexpr(WithUV)
|
||||
{
|
||||
memcpy((char*)outputVertex + m_outputVertexDesc.getElement(outputOffset++)->offset, &a_uv, sizeof(float32_t) * 2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user