规范模型输入以及测试shader
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "ui_main.h"
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_opengl.h>
|
||||
|
||||
#include <imgui/imgui.h>
|
||||
@@ -74,7 +75,10 @@ void OpenFileDialogFileCallback(void* userdata, const char* const* filelist, int
|
||||
g_scene.clear();
|
||||
|
||||
const char* szFileName = *filelist;
|
||||
davinci_utils::load_scene_from_gltf(szFileName, g_scene);
|
||||
if (!davinci_utils::load_scene_from_gltf(szFileName, g_scene))
|
||||
{
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Open glf scene file error", main_window);
|
||||
}
|
||||
}
|
||||
|
||||
void drawMainUI()
|
||||
|
||||
@@ -8,8 +8,8 @@ DV_CORE_BEGIN_NAMESPACE
|
||||
class MathUtil
|
||||
{
|
||||
public:
|
||||
static size_t ComponentSize(ComponentType ct);
|
||||
static size_t DataTypeSize(DataType dt);
|
||||
static DV_CORE_API size_t ComponentSize(ComponentType ct);
|
||||
static DV_CORE_API size_t DataTypeSize(DataType dt);
|
||||
|
||||
//count the number of bits set in v
|
||||
static DV_CORE_API uint32_t popcount(uint8_t v);
|
||||
|
||||
@@ -8,7 +8,7 @@ DV_CORE_BEGIN_NAMESPACE
|
||||
void VertexShaderStep::process(UniformBuffer& uniformBuffer, const InputAssemberStep::NodeArray& assembedNodeArray)
|
||||
{
|
||||
ShaderFileInterface* shaderInterface = davinci::LoadShaderFile("TestShader.dll");
|
||||
VertexShaderInterface* standardVS = shaderInterface->getVertexShader("xxxx");
|
||||
VertexShaderInterface* standardVS = shaderInterface->getVertexShader("test");
|
||||
|
||||
const fVector3* eyePos = (const fVector3*)(uniformBuffer.getAttribute("camera:eye_pos"));
|
||||
const fMatrix4* cameraView = (const fMatrix4*)(uniformBuffer.getAttribute("camera:view_mat"));
|
||||
@@ -24,6 +24,9 @@ void VertexShaderStep::process(UniformBuffer& uniformBuffer, const InputAssember
|
||||
//update self uniform value
|
||||
uniformBuffer.setAttribute("self:world_transform", inputNode.transform);
|
||||
|
||||
fMatrix4 worldInverseTrans = inputNode.transform.inverse().transpose();
|
||||
uniformBuffer.setAttribute("self:world_transform_inverse_trans", worldInverseTrans);
|
||||
|
||||
standardVS->prepare(&uniformBuffer,
|
||||
[inputNode](VertexElementType type) -> DeviceBufferAccessorConstPtr
|
||||
{
|
||||
@@ -47,19 +50,7 @@ void VertexShaderStep::process(UniformBuffer& uniformBuffer, const InputAssember
|
||||
|
||||
for (size_t i = 0; i < vertexCounts; i++)
|
||||
{
|
||||
size_t index = 0;
|
||||
if (inputNode.indices->getComponentType() == CT_Uint16)
|
||||
{
|
||||
index = (size_t)(*(uint16_t*)(inputNode.indices->getElement(i)));
|
||||
}
|
||||
else if(inputNode.indices->getComponentType() == CT_Uint32)
|
||||
{
|
||||
index = (size_t)(*(uint32_t*)(inputNode.indices->getElement(i)));
|
||||
}
|
||||
else
|
||||
{
|
||||
//error
|
||||
}
|
||||
uint16_t index = *((const uint16_t*)(inputNode.indices->getElement(i)));
|
||||
|
||||
fVector3 vertexWorldPos;
|
||||
void* outputVertexMemory = outputNode.vertexBuf->ptr(i* outputNode.vertexDesc.vertexByteSize());
|
||||
|
||||
@@ -9,7 +9,7 @@ DV_CORE_BEGIN_NAMESPACE
|
||||
void RasterizerStep::process(const VertexShaderStep::NodeArray& vsNodeArray, AntiAliasingTech aaTech, int32_t canvasWidth, int32_t canvasHeight)
|
||||
{
|
||||
ShaderFileInterface* shaderInterface = davinci::LoadShaderFile("TestShader.dll");
|
||||
PixelShaderInterface* pixelShader = shaderInterface->getPixelShader("xxx");
|
||||
PixelShaderInterface* pixelShader = shaderInterface->getPixelShader("test");
|
||||
|
||||
fMatrix4 view_trans =
|
||||
fMatrix4::makeTrans(canvasWidth / 2.f, canvasHeight / 2.f, 0.f) *
|
||||
@@ -75,7 +75,7 @@ void RasterizerStep::process(const VertexShaderStep::NodeArray& vsNodeArray, Ant
|
||||
newFragment.mask = mask;
|
||||
newFragment.next = currentOffset;
|
||||
this->m_fragementArray.push_back(newFragment);
|
||||
}
|
||||
},true
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,6 +132,253 @@ davinci::VertexElementType _getElementTypeFromGltf(const std::string& gltfElemen
|
||||
return davinci::VET_UNKNOWN;
|
||||
}
|
||||
|
||||
davinci::DeviceBufferAccessorPtr _createFloat32BufferAccessorFromNormalizedIntegerType(davinci::Scene& scene,
|
||||
davinci::DeviceBufferAccessorPtr inpuptBufferAccesser)
|
||||
{
|
||||
size_t elementCounts = inpuptBufferAccesser->getCount();
|
||||
davinci::ComponentType inputComponentType = inpuptBufferAccesser->getComponentType();
|
||||
if (inputComponentType != davinci::ComponentType::CT_Uint8 &&
|
||||
inputComponentType != davinci::ComponentType::CT_Uint16 &&
|
||||
inputComponentType != davinci::ComponentType::CT_Uint32)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
davinci::DataType dataType = inpuptBufferAccesser->getDataType();
|
||||
davinci::DeviceBufferPtr newBuffer = scene.newDeviceBuffer();
|
||||
size_t bufferSize = elementCounts * davinci::MathUtil::ComponentSize(davinci::ComponentType::CT_Float32) * davinci::MathUtil::DataTypeSize(dataType);
|
||||
newBuffer->init(bufferSize);
|
||||
|
||||
if (dataType == davinci::DataType::DT_Scalar)
|
||||
{
|
||||
inpuptBufferAccesser->walk([newBuffer, inputComponentType](const uint8_t* ptr, size_t index)
|
||||
{
|
||||
float32_t* target = (float32_t*)(newBuffer->ptr(index * sizeof(float32_t)));
|
||||
if (inputComponentType == davinci::ComponentType::CT_Uint8)
|
||||
{
|
||||
target[0] = ((const uint8_t*)ptr)[0] / (float32_t)0xFF;
|
||||
}
|
||||
else if (inputComponentType == davinci::ComponentType::CT_Uint16)
|
||||
{
|
||||
target[0] = ((const uint16_t*)ptr)[0] / (float32_t)0xFFFF;
|
||||
}
|
||||
else
|
||||
{
|
||||
target[0] = ((const uint32_t*)ptr)[0] / (float32_t)0xFFFFFFFF;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
);
|
||||
}
|
||||
else if (dataType == davinci::DataType::DT_Vec2)
|
||||
{
|
||||
inpuptBufferAccesser->walk(
|
||||
[newBuffer, inputComponentType](const uint8_t* ptr, size_t index)
|
||||
{
|
||||
float32_t* target = (float32_t*)(newBuffer->ptr(index * sizeof(float32_t) * 2));
|
||||
if (inputComponentType == davinci::ComponentType::CT_Uint8)
|
||||
{
|
||||
target[0] = ((const uint8_t*)ptr)[0] / (float32_t)0xFF;
|
||||
target[1] = ((const uint8_t*)ptr)[1] / (float32_t)0xFF;
|
||||
}
|
||||
else if (inputComponentType == davinci::ComponentType::CT_Uint16)
|
||||
{
|
||||
target[0] = ((const uint16_t*)ptr)[0] / (float32_t)0xFFFF;
|
||||
target[1] = ((const uint16_t*)ptr)[1] / (float32_t)0xFFFF;
|
||||
}
|
||||
else
|
||||
{
|
||||
target[0] = ((const uint32_t*)ptr)[0] / (float32_t)0xFFFFFFFF;
|
||||
target[1] = ((const uint32_t*)ptr)[1] / (float32_t)0xFFFFFFFF;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
);
|
||||
}
|
||||
else if (dataType == davinci::DataType::DT_Vec3)
|
||||
{
|
||||
inpuptBufferAccesser->walk(
|
||||
[newBuffer, inputComponentType](const uint8_t* ptr, size_t index)
|
||||
{
|
||||
float32_t* target = (float32_t*)(newBuffer->ptr(index * sizeof(float32_t) * 3));
|
||||
if (inputComponentType == davinci::ComponentType::CT_Uint8)
|
||||
{
|
||||
target[0] = ((const uint8_t*)ptr)[0] / (float32_t)0xFF;
|
||||
target[1] = ((const uint8_t*)ptr)[1] / (float32_t)0xFF;
|
||||
target[2] = ((const uint8_t*)ptr)[2] / (float32_t)0xFF;
|
||||
}
|
||||
else if (inputComponentType == davinci::ComponentType::CT_Uint16)
|
||||
{
|
||||
target[0] = ((const uint16_t*)ptr)[0] / (float32_t)0xFFFF;
|
||||
target[1] = ((const uint16_t*)ptr)[1] / (float32_t)0xFFFF;
|
||||
target[2] = ((const uint16_t*)ptr)[2] / (float32_t)0xFFFF;
|
||||
}
|
||||
else
|
||||
{
|
||||
target[0] = ((const uint32_t*)ptr)[0] / (float32_t)0xFFFFFFFF;
|
||||
target[1] = ((const uint32_t*)ptr)[1] / (float32_t)0xFFFFFFFF;
|
||||
target[2] = ((const uint32_t*)ptr)[2] / (float32_t)0xFFFFFFFF;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
);
|
||||
}
|
||||
else if (dataType == davinci::DataType::DT_Vec4)
|
||||
{
|
||||
inpuptBufferAccesser->walk(
|
||||
[newBuffer, inputComponentType](const uint8_t* ptr, size_t index)
|
||||
{
|
||||
float32_t* target = (float32_t*)(newBuffer->ptr(index * sizeof(float32_t) * 4));
|
||||
if (inputComponentType == davinci::ComponentType::CT_Uint8)
|
||||
{
|
||||
target[0] = ((const uint8_t*)ptr)[0] / (float32_t)0xFF;
|
||||
target[1] = ((const uint8_t*)ptr)[1] / (float32_t)0xFF;
|
||||
target[2] = ((const uint8_t*)ptr)[2] / (float32_t)0xFF;
|
||||
target[3] = ((const uint8_t*)ptr)[3] / (float32_t)0xFF;
|
||||
}
|
||||
else if (inputComponentType == davinci::ComponentType::CT_Uint16)
|
||||
{
|
||||
target[0] = ((const uint16_t*)ptr)[0] / (float32_t)0xFFFF;
|
||||
target[1] = ((const uint16_t*)ptr)[1] / (float32_t)0xFFFF;
|
||||
target[2] = ((const uint16_t*)ptr)[2] / (float32_t)0xFFFF;
|
||||
target[3] = ((const uint16_t*)ptr)[3] / (float32_t)0xFFFF;
|
||||
}
|
||||
else
|
||||
{
|
||||
target[0] = ((const uint32_t*)ptr)[0] / (float32_t)0xFFFFFFFF;
|
||||
target[1] = ((const uint32_t*)ptr)[1] / (float32_t)0xFFFFFFFF;
|
||||
target[2] = ((const uint32_t*)ptr)[2] / (float32_t)0xFFFFFFFF;
|
||||
target[3] = ((const uint32_t*)ptr)[3] / (float32_t)0xFFFFFFFF;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
);
|
||||
}
|
||||
davinci::DeviceBufferViewPtr newBufferViewer = scene.newDeviceBufferView(newBuffer, 0, bufferSize, 0);
|
||||
return scene.newDeviceBufferAccessor(newBufferViewer, 0, elementCounts, davinci::ComponentType::CT_Float32, dataType);
|
||||
}
|
||||
|
||||
davinci::DeviceBufferAccessorPtr _createSupportedPrimitiveAttributeBufferAccessor(
|
||||
davinci::Scene& scene, davinci::VertexElementType vetType, davinci::DeviceBufferAccessorPtr inpuptBufferAccesser)
|
||||
{
|
||||
if (!inpuptBufferAccesser) return nullptr;
|
||||
davinci::ComponentType componentType = inpuptBufferAccesser->getComponentType();
|
||||
davinci::DataType dataType = inpuptBufferAccesser->getDataType();
|
||||
|
||||
switch (vetType)
|
||||
{
|
||||
case davinci::VET_POSITION:
|
||||
case davinci::VET_NORMAL:
|
||||
case davinci::VET_BINORMAL:
|
||||
if (componentType == davinci::ComponentType::CT_Float32 && dataType == davinci::DataType::DT_Vec3)
|
||||
{
|
||||
return inpuptBufferAccesser;
|
||||
}
|
||||
break;
|
||||
|
||||
case davinci::VET_TANGENT:
|
||||
if (componentType == davinci::ComponentType::CT_Float32 && dataType == davinci::DataType::DT_Vec4)
|
||||
{
|
||||
return inpuptBufferAccesser;
|
||||
}
|
||||
break;
|
||||
|
||||
case davinci::VET_TEXCOORD_0:
|
||||
case davinci::VET_TEXCOORD_1:
|
||||
case davinci::VET_TEXCOORD_2:
|
||||
case davinci::VET_TEXCOORD_3:
|
||||
case davinci::VET_TEXCOORD_4:
|
||||
case davinci::VET_TEXCOORD_5:
|
||||
case davinci::VET_TEXCOORD_6:
|
||||
case davinci::VET_TEXCOORD_7:
|
||||
if (dataType == davinci::DataType::DT_Vec2)
|
||||
{
|
||||
if (componentType == davinci::ComponentType::CT_Float32)
|
||||
{
|
||||
return inpuptBufferAccesser;
|
||||
}
|
||||
else if (componentType == davinci::ComponentType::CT_Uint8 || componentType == davinci::ComponentType::CT_Uint16)
|
||||
{
|
||||
return _createFloat32BufferAccessorFromNormalizedIntegerType(scene, inpuptBufferAccesser);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case davinci::VET_COLOR_0:
|
||||
case davinci::VET_COLOR_1:
|
||||
case davinci::VET_COLOR_2:
|
||||
case davinci::VET_COLOR_3:
|
||||
case davinci::VET_COLOR_4:
|
||||
case davinci::VET_COLOR_5:
|
||||
case davinci::VET_COLOR_6:
|
||||
case davinci::VET_COLOR_7:
|
||||
if (dataType == davinci::DataType::DT_Vec3 || dataType == davinci::DataType::DT_Vec4)
|
||||
{
|
||||
if (componentType == davinci::ComponentType::CT_Float32)
|
||||
{
|
||||
return inpuptBufferAccesser;
|
||||
}
|
||||
else if (componentType == davinci::ComponentType::CT_Uint8 || componentType == davinci::ComponentType::CT_Uint16)
|
||||
{
|
||||
return _createFloat32BufferAccessorFromNormalizedIntegerType(scene, inpuptBufferAccesser);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case davinci::VET_JOINTS_0:
|
||||
case davinci::VET_JOINTS_1:
|
||||
case davinci::VET_JOINTS_2:
|
||||
case davinci::VET_JOINTS_3:
|
||||
case davinci::VET_JOINTS_4:
|
||||
case davinci::VET_JOINTS_5:
|
||||
case davinci::VET_JOINTS_6:
|
||||
case davinci::VET_JOINTS_7:
|
||||
if (dataType == davinci::DataType::DT_Vec4)
|
||||
{
|
||||
if (componentType == davinci::ComponentType::CT_Uint8 || componentType == davinci::ComponentType::CT_Uint16)
|
||||
{
|
||||
return inpuptBufferAccesser;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case davinci::VET_WEIGHTS_0:
|
||||
case davinci::VET_WEIGHTS_1:
|
||||
case davinci::VET_WEIGHTS_2:
|
||||
case davinci::VET_WEIGHTS_3:
|
||||
case davinci::VET_WEIGHTS_4:
|
||||
case davinci::VET_WEIGHTS_5:
|
||||
case davinci::VET_WEIGHTS_6:
|
||||
case davinci::VET_WEIGHTS_7:
|
||||
if (dataType == davinci::DataType::DT_Vec4)
|
||||
{
|
||||
if (componentType == davinci::ComponentType::CT_Float32)
|
||||
{
|
||||
return inpuptBufferAccesser;
|
||||
}
|
||||
else if (componentType == davinci::ComponentType::CT_Uint8 || componentType == davinci::ComponentType::CT_Uint16)
|
||||
{
|
||||
return _createFloat32BufferAccessorFromNormalizedIntegerType(scene, inpuptBufferAccesser);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool _isSupportedIndicesType(const davinci::DeviceBufferAccessorConstPtr accesserBuffer)
|
||||
{
|
||||
if (!accesserBuffer) return false;
|
||||
davinci::ComponentType componentType = accesserBuffer->getComponentType();
|
||||
davinci::DataType dataType = accesserBuffer->getDataType();
|
||||
|
||||
return componentType == davinci::ComponentType::CT_Uint16 && dataType == davinci::DataType::DT_Scalar;
|
||||
}
|
||||
|
||||
bool _loadDeviceBuffer(const tinygltf::Model& gltfModel, davinci::Scene& scene)
|
||||
{
|
||||
for (size_t i = 0; i < gltfModel.buffers.size(); i++)
|
||||
@@ -225,6 +472,13 @@ bool _loadMesh(const tinygltf::Model& gltfModel, davinci::Scene& scene)
|
||||
return false;
|
||||
}
|
||||
|
||||
//convert to supported primitive buffer(float32)
|
||||
deviceBufferAccessor = _createSupportedPrimitiveAttributeBufferAccessor(scene, vetype, deviceBufferAccessor);
|
||||
if (deviceBufferAccessor == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
primitive->attributes.insert(std::make_pair(vetype, deviceBufferAccessor));
|
||||
}
|
||||
|
||||
@@ -233,6 +487,12 @@ bool _loadMesh(const tinygltf::Model& gltfModel, davinci::Scene& scene)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
bool isSupportedType = _isSupportedIndicesType(indicesBufferAccessor);
|
||||
if (!isSupportedType)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
primitive->indices = indicesBufferAccessor;
|
||||
}
|
||||
|
||||
@@ -609,30 +869,9 @@ bool export_mesh_to_obj(const davinci::Scene& scene)
|
||||
davinci::DeviceBufferAccessorConstPtr indexBufferAccessor = primitive->indices;
|
||||
indexBufferAccessor->walk3([=](const uint8_t* ptr0, const uint8_t* ptr1, const uint8_t* ptr2, size_t index) {
|
||||
|
||||
uint32_t indice0, indice1, indice2;
|
||||
if (indexBufferAccessor->getComponentType() == davinci::CT_Uint16)
|
||||
{
|
||||
indice0 = *((uint16_t*)ptr0) + 1;
|
||||
indice1 = *((uint16_t*)ptr1) + 1;
|
||||
indice2 = *((uint16_t*)ptr2) + 1;
|
||||
}
|
||||
else if (indexBufferAccessor->getComponentType() == davinci::CT_Uint32)
|
||||
{
|
||||
indice0 = *((uint32_t*)ptr0) + 1;
|
||||
indice1 = *((uint32_t*)ptr1) + 1;
|
||||
indice2 = *((uint32_t*)ptr2) + 1;
|
||||
}
|
||||
else if (indexBufferAccessor->getComponentType() == davinci::CT_Uint8)
|
||||
{
|
||||
indice0 = *((uint8_t*)ptr0) + 1;
|
||||
indice1 = *((uint8_t*)ptr1) + 1;
|
||||
indice2 = *((uint8_t*)ptr2) + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
//error
|
||||
return true;
|
||||
}
|
||||
uint32_t indice0 = *((uint16_t*)ptr0) + 1;
|
||||
uint32_t indice1 = *((uint16_t*)ptr1) + 1;
|
||||
uint32_t indice2 = *((uint16_t*)ptr2) + 1;
|
||||
|
||||
if (bHasTex0)
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@ void Canvas::reset(int32_t width, int32_t height)
|
||||
{
|
||||
m_pixels[i].fragementID = -1;
|
||||
m_pixels[i].mask = 0;
|
||||
m_pixels[i].color = 0;
|
||||
m_pixels[i].color = davinci::fVector3::BLACK;
|
||||
}
|
||||
|
||||
m_fragementArray.clear();
|
||||
|
||||
@@ -9,13 +9,31 @@ class TestShaderInterface : public davinci::ShaderFileInterface
|
||||
public:
|
||||
virtual davinci::VertexShaderInterface* getVertexShader(const char* szName)
|
||||
{
|
||||
static TestVertexShader testVertexShader;
|
||||
return &testVertexShader;
|
||||
if (strcmp(szName, "standard") == 0)
|
||||
{
|
||||
static StandardVertexShader standardVertexShader;
|
||||
return &standardVertexShader;
|
||||
}
|
||||
else if (strcmp(szName, "test") == 0)
|
||||
{
|
||||
static TestVertexShader testVertexShader;
|
||||
return &testVertexShader;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
virtual davinci::PixelShaderInterface* getPixelShader(const char* szName)
|
||||
{
|
||||
static SolidColorPixelShader solidColorPixelShader;
|
||||
static TestPixelShader testPixelShader;
|
||||
return &testPixelShader;
|
||||
if(strcmp(szName, solidColorPixelShader.getName()) == 0)
|
||||
{
|
||||
return &solidColorPixelShader;
|
||||
}
|
||||
else if (strcmp(szName, testPixelShader.getName()) == 0)
|
||||
{
|
||||
return &testPixelShader;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
const char* TestPixelShader::getName(void) const
|
||||
{
|
||||
return "test_pixel_shader";
|
||||
return "test";
|
||||
}
|
||||
|
||||
void TestPixelShader::prepare(const davinci::UniformBuffer* uniformBuffer, SetInputAttributeFunc setInputAttributeFunc)
|
||||
@@ -12,14 +12,14 @@ void TestPixelShader::prepare(const davinci::UniformBuffer* uniformBuffer, SetIn
|
||||
|
||||
void TestPixelShader::process(const davinci::VertexDesc& veretexDesc, const float32_t* pixelData, davinci::fVector4& color)
|
||||
{
|
||||
const davinci::VertexDesc::Element* v_position_Element = veretexDesc.getElement("v_position");
|
||||
const davinci::fVector3* v_position = (const davinci::fVector3*)(pixelData + (v_position_Element->offset / sizeof(float32_t)));
|
||||
//const davinci::VertexDesc::Element* v_position_Element = veretexDesc.getElement("v_position");
|
||||
//const davinci::fVector3* v_position = (const davinci::fVector3*)(pixelData + (v_position_Element->offset / sizeof(float32_t)));
|
||||
|
||||
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)));
|
||||
|
||||
const davinci::VertexDesc::Element* v_uv_Element = veretexDesc.getElement("v_uv");
|
||||
const float32_t* v_uv = (const float32_t*)(pixelData + (v_uv_Element->offset / sizeof(float32_t)));
|
||||
//const davinci::VertexDesc::Element* v_uv_Element = veretexDesc.getElement("v_uv");
|
||||
//const float32_t* v_uv = (const float32_t*)(pixelData + (v_uv_Element->offset / sizeof(float32_t)));
|
||||
|
||||
const davinci::VertexDesc::Element* v_toCamera_Element = veretexDesc.getElement("v_toCamera");
|
||||
const davinci::fVector3* v_toCamera = (const davinci::fVector3*)(pixelData + (v_toCamera_Element->offset / sizeof(float32_t)));
|
||||
@@ -49,9 +49,9 @@ void TestPixelShader::process(const davinci::VertexDesc& veretexDesc, const floa
|
||||
davinci::fVector3 vH = vL + vV;
|
||||
vH.normalise();
|
||||
|
||||
davinci::fVector3 u_ambientColor = davinci::fVector3(0.1, 0.1, 0.1);
|
||||
davinci::fVector3 u_ambientColor = davinci::fVector3(0.2, 0.2, 0.2);
|
||||
|
||||
davinci::fVector3 u_matColor = davinci::fVector3(1.0, 0.5, 0.7);
|
||||
davinci::fVector3 u_matColor = davinci::fVector3(0.7, 0.7, 0.7);
|
||||
|
||||
davinci::fVector3 u_lightColor = davinci::fVector3(1.0, 1.0, 1.0);
|
||||
|
||||
@@ -69,8 +69,24 @@ void TestPixelShader::process(const davinci::VertexDesc& veretexDesc, const floa
|
||||
davinci::fVector3 colSpec = (ndotl < 0.f ? 0.0 : 1.0) * std::powf(spec, 64.f) * u_matColor * u_lightColor;
|
||||
|
||||
//color final = colAmbient + colDiff + colSpec;
|
||||
davinci::fVector3 final = colAmbient + colDiff + colSpec;
|
||||
davinci::fVector3 final = colAmbient +colDiff +colSpec;
|
||||
//davinci::fVector3 final = *v_color0;
|
||||
|
||||
//color = davinci::fVector4::RED;
|
||||
color = davinci::fVector4(final.saturate(), 1.0f);// davinci::fVector4::RED;
|
||||
}
|
||||
|
||||
const char* SolidColorPixelShader::getName(void) const
|
||||
{
|
||||
return "solid";
|
||||
}
|
||||
|
||||
void SolidColorPixelShader::prepare(const davinci::UniformBuffer* uniformBuffer, SetInputAttributeFunc setInputAttributeFunc)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SolidColorPixelShader::process(const davinci::VertexDesc& veretexDesc, const float32_t* pixelData, davinci::fVector4& color)
|
||||
{
|
||||
color = davinci::fVector4::RED;
|
||||
}
|
||||
|
||||
@@ -13,3 +13,14 @@ public:
|
||||
virtual void process(const davinci::VertexDesc& veretexDesc, const float32_t* pixelData,
|
||||
davinci::fVector4& color);
|
||||
};
|
||||
|
||||
class SolidColorPixelShader : public davinci::PixelShaderInterface
|
||||
{
|
||||
public:
|
||||
virtual const char* getName(void) const;
|
||||
|
||||
virtual void prepare(const davinci::UniformBuffer* uniformBuffer, SetInputAttributeFunc setInputAttributeFunc);
|
||||
|
||||
virtual void process(const davinci::VertexDesc& veretexDesc, const float32_t* pixelData,
|
||||
davinci::fVector4& color);
|
||||
};
|
||||
|
||||
@@ -28,7 +28,7 @@ TestVertexShader::~TestVertexShader()
|
||||
|
||||
const char* TestVertexShader::getName(void) const
|
||||
{
|
||||
return "test_vertex_shader";
|
||||
return "test";
|
||||
}
|
||||
|
||||
size_t TestVertexShader::getOutputVertexByteSize(void) const
|
||||
@@ -57,21 +57,18 @@ void TestVertexShader::prepare(const davinci::UniformBuffer* uniformBuffer, SetI
|
||||
|
||||
void TestVertexShader::process(size_t index, void* outputVertex, davinci::fVector3& vertexWorldPos)
|
||||
{
|
||||
static const float DEFAULT_POSITION[] = {0.f, 0.f, 0.f};
|
||||
static const float DEFAULT_NORMAL[] = { 0.f, 0.f, 0.f };
|
||||
static const float DEFAULT_TEXCOORD0[] = { 0.f, 0.f};
|
||||
static const uint16_t DEFAULT_COLOR0[] = { 0, 0, 0 };
|
||||
static const float32_t 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};
|
||||
static const float32_t DEFAULT_COLOR0[] = { 0.f, 0.f, 0.f };
|
||||
|
||||
davinci::fVector3 a_position(m_POSITION ? (const float*)(m_POSITION->getElement(index)) : DEFAULT_POSITION);
|
||||
davinci::fVector3 a_normal(m_NORMAL ? (const float*)(m_NORMAL->getElement(index)) : DEFAULT_NORMAL);
|
||||
const float32_t* a_texcoord_0(m_TEXCOORD_0 ? (const float*)(m_TEXCOORD_0->getElement(index)) : DEFAULT_TEXCOORD0);
|
||||
const uint16_t* color0 = m_COLOR_0 ? (const uint16_t*)(m_COLOR_0->getElement(index)) : DEFAULT_COLOR0;
|
||||
davinci::fVector3 a_position(m_POSITION ? (const float32_t*)(m_POSITION->getElement(index)) : DEFAULT_POSITION);
|
||||
|
||||
davinci::fVector3 a_color_0(
|
||||
color0[0] / float(std::numeric_limits<uint16_t>::max()),
|
||||
color0[1] / float(std::numeric_limits<uint16_t>::max()),
|
||||
color0[2] / float(std::numeric_limits<uint16_t>::max())
|
||||
);
|
||||
davinci::fVector3 a_normal(m_NORMAL ? (const float32_t*)(m_NORMAL->getElement(index)) : DEFAULT_NORMAL);
|
||||
|
||||
davinci::fVector2 a_uv(m_TEXCOORD_0 ? (const float32_t*)(m_TEXCOORD_0->getElement(index)) : DEFAULT_TEXCOORD0);
|
||||
|
||||
davinci::fVector3 a_color_0(m_COLOR_0 ? (const float32_t*)(m_COLOR_0->getElement(index)) : DEFAULT_COLOR0);
|
||||
|
||||
davinci::fMatrix4 mat_world = davinci::fMatrix4::IDENTITY;
|
||||
if (davinci::fMatrix4* p_mat_world = (davinci::fMatrix4*)(m_uniformBuffer->getAttribute("self:world_transform")))
|
||||
@@ -100,19 +97,21 @@ void TestVertexShader::process(size_t index, void* outputVertex, davinci::fVecto
|
||||
davinci::fVector3 temp1 = mat_world * a_position;
|
||||
davinci::fVector3 v_position = mat_camera_view_proj * temp1;
|
||||
|
||||
davinci::fVector3 v_normal = a_normal;
|
||||
davinci::fMatrix4 matNormal = davinci::fMatrix4::IDENTITY;
|
||||
if (davinci::fMatrix4* p_mat_normal = (davinci::fMatrix4*)(m_uniformBuffer->getAttribute("self:world_transform_inverse_trans")))
|
||||
{
|
||||
matNormal = *p_mat_normal;
|
||||
}
|
||||
davinci::fVector3 v_normal = (matNormal * davinci::fVector4(a_normal, 0)).xyz().normalise();
|
||||
|
||||
davinci::fVector3 v_color_0 = a_color_0;
|
||||
|
||||
float32_t v_uv[2];
|
||||
memcpy(v_uv, a_texcoord_0, sizeof(float32_t) * 2);
|
||||
|
||||
davinci::fVector3 v_to_camera = (camera_position - v_position).normalise();
|
||||
davinci::fVector3 v_to_light = (light0_position - v_position).normalise();
|
||||
davinci::fVector3 v_to_camera = (camera_position - temp1).normalise();
|
||||
davinci::fVector3 v_to_light = (light0_position - temp1).normalise();
|
||||
|
||||
memcpy((char*)outputVertex + m_outputVertexDesc.getElement(0)->offset, &v_position, sizeof(davinci::fVector3));
|
||||
memcpy((char*)outputVertex + m_outputVertexDesc.getElement(1)->offset, &v_normal, sizeof(davinci::fVector3));
|
||||
memcpy((char*)outputVertex + m_outputVertexDesc.getElement(2)->offset, v_uv, sizeof(float32_t) * 2);
|
||||
memcpy((char*)outputVertex + m_outputVertexDesc.getElement(2)->offset, &a_uv, sizeof(float32_t) * 2);
|
||||
memcpy((char*)outputVertex + m_outputVertexDesc.getElement(3)->offset, &v_to_camera, sizeof(davinci::fVector3));
|
||||
memcpy((char*)outputVertex + m_outputVertexDesc.getElement(4)->offset, &v_to_light, sizeof(davinci::fVector3));
|
||||
memcpy((char*)outputVertex + m_outputVertexDesc.getElement(5)->offset, &v_color_0, sizeof(davinci::fVector3));
|
||||
@@ -120,3 +119,64 @@ void TestVertexShader::process(size_t index, void* outputVertex, davinci::fVecto
|
||||
vertexWorldPos = mat_world * a_position;
|
||||
}
|
||||
|
||||
|
||||
StandardVertexShader::StandardVertexShader()
|
||||
{
|
||||
m_uniformBuffer = nullptr;
|
||||
//output point v_position = point(0, 0, 0) [[ string attribute="POSITION"]],
|
||||
m_outputVertexDesc.addElement("v_position", davinci::VET_POSITION, davinci::CT_Float32, davinci::DT_Vec3);
|
||||
}
|
||||
|
||||
StandardVertexShader::~StandardVertexShader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
const char* StandardVertexShader::getName(void) const
|
||||
{
|
||||
return "standard";
|
||||
}
|
||||
|
||||
size_t StandardVertexShader::getOutputVertexByteSize(void) const
|
||||
{
|
||||
return m_outputVertexDesc.vertexByteSize();
|
||||
}
|
||||
|
||||
const davinci::VertexDesc& StandardVertexShader::getOutputVertexDesc() const
|
||||
{
|
||||
return m_outputVertexDesc;
|
||||
}
|
||||
|
||||
void StandardVertexShader::prepare(const davinci::UniformBuffer* uniformBuffer, SetInputAttributeFunc setInputAttributeFunc)
|
||||
{
|
||||
m_uniformBuffer = uniformBuffer;
|
||||
|
||||
//point a_position = vector(0, 0, 0) [[ string attribute="POSITION"]],
|
||||
m_POSITION = setInputAttributeFunc(davinci::VET_POSITION);
|
||||
}
|
||||
|
||||
void StandardVertexShader::process(size_t index, void* outputVertex, davinci::fVector3& vertexWorldPos)
|
||||
{
|
||||
static const float DEFAULT_POSITION[] = {0.f, 0.f, 0.f};
|
||||
|
||||
davinci::fVector3 a_position(m_POSITION ? (const float32_t*)(m_POSITION->getElement(index)) : DEFAULT_POSITION);
|
||||
|
||||
davinci::fMatrix4 mat_world = davinci::fMatrix4::IDENTITY;
|
||||
if (davinci::fMatrix4* p_mat_world = (davinci::fMatrix4*)(m_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*)(m_uniformBuffer->getAttribute("camera:view_proj_mat")))
|
||||
{
|
||||
mat_camera_view_proj = *p_mat_camera_view_proj;
|
||||
}
|
||||
|
||||
davinci::fVector3 temp1 = mat_world * a_position;
|
||||
davinci::fVector3 v_position = mat_camera_view_proj * temp1;
|
||||
|
||||
memcpy((char*)outputVertex + m_outputVertexDesc.getElement(0)->offset, &v_position, sizeof(davinci::fVector3));
|
||||
|
||||
vertexWorldPos = mat_world * a_position;
|
||||
}
|
||||
|
||||
@@ -31,3 +31,22 @@ public:
|
||||
virtual ~TestVertexShader();
|
||||
};
|
||||
|
||||
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::UniformBuffer* uniformBuffer, SetInputAttributeFunc setInputAttributeFunc);
|
||||
virtual void process(size_t index, void* outputVertex, davinci::fVector3& vertexWorldPos);
|
||||
|
||||
private:
|
||||
const davinci::UniformBuffer* m_uniformBuffer = nullptr;
|
||||
davinci::DeviceBufferAccessorConstPtr m_POSITION;
|
||||
|
||||
davinci::VertexDesc m_outputVertexDesc;
|
||||
|
||||
public:
|
||||
StandardVertexShader();
|
||||
virtual ~StandardVertexShader();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user