11.15
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include "dvc_config.h"
|
||||
#include "dvc_pre_declare.h"
|
||||
#include "math/dvc_vector4.h"
|
||||
#include "math/dvc_matrix3.h"
|
||||
|
||||
DV_CORE_BEGIN_NAMESPACE
|
||||
|
||||
@@ -13,16 +14,14 @@ public:
|
||||
{
|
||||
TextureConstPtr texture;
|
||||
int32_t texCoord = 0;
|
||||
fMatrix3 uvTransform;
|
||||
};
|
||||
|
||||
public:
|
||||
int32_t getID(void) const { return m_id; }
|
||||
|
||||
void setBaseColorTexture(const TextureConstPtr& texture, int32_t texCoord, const fVector4& baseColorfactor) {
|
||||
m_baseColorTexture.texture = texture;
|
||||
m_baseColorTexture.texCoord = texCoord;
|
||||
m_baseColorFactor = baseColorfactor;
|
||||
}
|
||||
void setBaseColorTexture(const TextureConstPtr& texture, int32_t texCoord, const fMatrix3& uvTransform,
|
||||
const fVector4& baseColorfactor);
|
||||
const TextureInfo& getBaseColorTexture() const {
|
||||
return m_baseColorTexture;
|
||||
}
|
||||
@@ -31,12 +30,8 @@ public:
|
||||
return m_baseColorFactor;
|
||||
}
|
||||
|
||||
void setMetallicRoughnessTexture(const TextureConstPtr& texture, int32_t texCoord, float32_t metallicFactor=1.f, float32_t roughnessFactor=1.f ) {
|
||||
m_metallicRoughnessTexture.texture = texture;
|
||||
m_metallicRoughnessTexture.texCoord = texCoord;
|
||||
m_metallicFactor = metallicFactor;
|
||||
m_roughnessFactor = roughnessFactor;
|
||||
}
|
||||
void setMetallicRoughnessTexture(const TextureConstPtr& texture, int32_t texCoord, const fMatrix3& uvTransform,
|
||||
float32_t metallicFactor = 1, float32_t roughnessFactor = 1);
|
||||
|
||||
const TextureInfo& getMetallicRoughnessTexture() const {
|
||||
return m_metallicRoughnessTexture;
|
||||
@@ -50,11 +45,8 @@ public:
|
||||
return m_roughnessFactor;
|
||||
}
|
||||
|
||||
void setNormalTexture(const TextureConstPtr& texture, int32_t texCoord, float32_t scale=1.f) {
|
||||
m_normalTexture.texture = texture;
|
||||
m_normalTexture.texCoord = texCoord;
|
||||
m_normalScale = scale;
|
||||
}
|
||||
void setNormalTexture(const TextureConstPtr& texture, int32_t texCoord, const fMatrix3& uvTransform,
|
||||
float32_t scale = 1);
|
||||
|
||||
const TextureInfo& getNormalTexture() const {
|
||||
return m_normalTexture;
|
||||
@@ -64,6 +56,9 @@ public:
|
||||
return m_normalScale;
|
||||
}
|
||||
|
||||
void setVertexShader(const char* szShaderFile, const char* vertexShaderName);
|
||||
void setFragementShader(const char* szShaderFile, const char* fragementShaderName);
|
||||
|
||||
VertexShaderInterface* getVertexShader() const {
|
||||
return m_vertexShader;
|
||||
}
|
||||
@@ -72,6 +67,7 @@ public:
|
||||
return m_pixelShader;
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
bool loadShader();
|
||||
|
||||
@@ -105,6 +101,12 @@ protected:
|
||||
VertexShaderInterface* m_vertexShader = nullptr;
|
||||
PixelShaderInterface* m_pixelShader = nullptr;
|
||||
|
||||
std::string m_vertexshaderFile;
|
||||
std::string m_vertexShaderName;
|
||||
|
||||
std::string m_fragementShaderFile;
|
||||
std::string m_fragementShaderName;
|
||||
|
||||
public:
|
||||
Material(int32_t id);
|
||||
~Material();
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "dvc_pre_declare.h"
|
||||
#include "math/dvc_vector2.h"
|
||||
#include "math/dvc_vector4.h"
|
||||
#include "math/dvc_matrix3.h"
|
||||
|
||||
DV_CORE_BEGIN_NAMESPACE
|
||||
|
||||
|
||||
@@ -94,6 +94,45 @@ public:
|
||||
template<typename U>
|
||||
friend TMatrix3<U> operator * (U fScalar, const TMatrix3<U>& rkMatrix);
|
||||
|
||||
public:
|
||||
static inline TMatrix3 makeTrans(T x, T y) {
|
||||
return TMatrix3(
|
||||
1, 0, x,
|
||||
0, 1, y,
|
||||
0, 0, 1);
|
||||
}
|
||||
|
||||
static inline TMatrix3 makeTrans(const TVector2<T>& pos) {
|
||||
return TMatrix3(
|
||||
1, 0, pos.x,
|
||||
0, 1, pos.y,
|
||||
0, 0, 1);
|
||||
}
|
||||
|
||||
static inline TMatrix3 makeScale(T x, T y) {
|
||||
return TMatrix3(
|
||||
x, 0, 0,
|
||||
0, y, 0,
|
||||
0, 0, 1);
|
||||
}
|
||||
|
||||
static inline TMatrix3 makeScale(const TVector2<T>& scale) {
|
||||
return TMatrix3(
|
||||
scale.x, 0, 0,
|
||||
0, scale.y, 0,
|
||||
0, 0, 1);
|
||||
}
|
||||
|
||||
//2D rotate, left multiplication
|
||||
static inline TMatrix3 makeRotate(T angle) {
|
||||
T s = sin(angle);
|
||||
T c = cos(angle);
|
||||
return TMatrix3(
|
||||
c, -s, 0,
|
||||
s, c, 0,
|
||||
0, 0, 1);
|
||||
}
|
||||
|
||||
public:
|
||||
// Utilities
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "dvc_pre_declare.h"
|
||||
#include "math/dvc_vector2.h"
|
||||
#include "math/dvc_vector4.h"
|
||||
#include "asset/dvc_material.h"
|
||||
|
||||
DV_CORE_BEGIN_NAMESPACE
|
||||
|
||||
@@ -30,7 +31,7 @@ public:
|
||||
return (a < b) ? a : b;
|
||||
}
|
||||
|
||||
static DV_CORE_API fVector4 texture2D(const RenderPipe& pipe, const char* textName, const fVector2& uv, const fVector4& defaultValue);
|
||||
static DV_CORE_API fVector4 texture2D(const RenderPipe& pipe, const Material::TextureInfo& texturePtr, const fVector2& uv, const fVector4& defaultValue);
|
||||
};
|
||||
|
||||
DV_CORE_END_NAMESPACE
|
||||
|
||||
@@ -26,8 +26,7 @@ class PixelShaderInterface
|
||||
public:
|
||||
virtual const char* getName(void) const = 0;
|
||||
|
||||
typedef std::function<size_t(const std::string&)> SetInputAttributeFunc;
|
||||
virtual void prepare(const RenderPipe* pipe, SetInputAttributeFunc setInputAttributeFunc) = 0;
|
||||
virtual void prepare(const RenderPipe* pipe, MaterialConstPtr material) = 0;
|
||||
|
||||
virtual void process(const VertexDesc& veretexDesc, const float32_t* pixelData, fVector4& color) = 0;
|
||||
};
|
||||
|
||||
@@ -12,12 +12,73 @@ Material::~Material()
|
||||
{
|
||||
}
|
||||
|
||||
void Material::setBaseColorTexture(const TextureConstPtr& texture, int32_t texCoord, const fMatrix3& uvTransform,
|
||||
const fVector4& baseColorfactor)
|
||||
{
|
||||
m_baseColorTexture.texture = texture;
|
||||
m_baseColorTexture.texCoord = texCoord;
|
||||
m_baseColorTexture.uvTransform = uvTransform;
|
||||
|
||||
m_baseColorFactor = baseColorfactor;
|
||||
}
|
||||
|
||||
void Material::setMetallicRoughnessTexture(const TextureConstPtr& texture, int32_t texCoord, const fMatrix3& uvTransform,
|
||||
float32_t metallicFactor, float32_t roughnessFactor)
|
||||
{
|
||||
m_metallicRoughnessTexture.texture = texture;
|
||||
m_metallicRoughnessTexture.texCoord = texCoord;
|
||||
m_metallicRoughnessTexture.uvTransform = uvTransform;
|
||||
|
||||
m_metallicFactor = metallicFactor;
|
||||
m_roughnessFactor = roughnessFactor;
|
||||
}
|
||||
|
||||
void Material::setNormalTexture(const TextureConstPtr& texture, int32_t texCoord, const fMatrix3& uvTransform,
|
||||
float32_t scale)
|
||||
{
|
||||
m_normalTexture.texture = texture;
|
||||
m_normalTexture.texCoord = texCoord;
|
||||
m_normalTexture.uvTransform = uvTransform;
|
||||
|
||||
m_normalScale = scale;
|
||||
}
|
||||
|
||||
void Material::setVertexShader(const char* szShaderFile, const char* vertexShaderName)
|
||||
{
|
||||
m_vertexshaderFile = szShaderFile;
|
||||
m_vertexShaderName = vertexShaderName;
|
||||
}
|
||||
|
||||
void Material::setFragementShader(const char* szShaderFile, const char* fragementShaderName)
|
||||
{
|
||||
m_fragementShaderFile = szShaderFile;
|
||||
m_fragementShaderName = fragementShaderName;
|
||||
}
|
||||
|
||||
bool Material::loadShader()
|
||||
{
|
||||
ShaderFileInterface* shaderInterface = davinci::LoadShaderFile("TestShader.dll");
|
||||
m_vertexShader = shaderInterface->getVertexShader("test");
|
||||
m_pixelShader = shaderInterface->getPixelShader("test");
|
||||
ShaderFileInterface* shaderInterface = davinci::LoadShaderFile(m_vertexshaderFile.c_str());
|
||||
if (shaderInterface == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
m_vertexShader = shaderInterface->getVertexShader(m_vertexShaderName.c_str());
|
||||
if (!m_vertexShader)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
shaderInterface = davinci::LoadShaderFile(m_fragementShaderFile.c_str());
|
||||
if (shaderInterface == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_pixelShader = shaderInterface->getPixelShader(m_fragementShaderName.c_str());
|
||||
if (!m_pixelShader)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,12 @@ fVector4 Texture::sample(const fVector2& uv) const
|
||||
fVector4 color = fVector4::ZERO;
|
||||
if (!m_image) return color;
|
||||
|
||||
int32_t u = uv.x * m_image->getWidth();
|
||||
int32_t v = uv.y * m_image->getHeight();
|
||||
float uv_x = uv.x - std::floor(uv.x);
|
||||
float uv_y = uv.y - std::floor(uv.y);
|
||||
|
||||
|
||||
int32_t u = uv_x * m_image->getWidth();
|
||||
int32_t v = uv_y * m_image->getHeight();
|
||||
|
||||
return m_image->getPixel(u, v);
|
||||
}
|
||||
|
||||
@@ -26,18 +26,8 @@ void RasterizerStep::process(RenderPipe& pipe, const VertexShaderStep::NodeArray
|
||||
{
|
||||
const VertexShaderStep::Node& node = *it;
|
||||
|
||||
if (node.material->getBaseColorTexture().texture)
|
||||
{
|
||||
uniformBuffer.setAttribute("material:pbr:base_color_texture", node.material->getBaseColorTexture().texture->getID());
|
||||
}
|
||||
|
||||
if (node.material->getNormalTexture().texture)
|
||||
{
|
||||
uniformBuffer.setAttribute("material:pbr:normal_texture", node.material->getNormalTexture().texture->getID());
|
||||
}
|
||||
|
||||
PixelShaderInterface* pixelShader = node.material->getPixelShader();
|
||||
pixelShader->prepare(&pipe, nullptr);
|
||||
pixelShader->prepare(&pipe, node.material);
|
||||
|
||||
size_t vertexSize = node.vertexDesc.vertexByteSize();
|
||||
size_t POS_offset = node.vertexDesc.getElement(VET_POSITION)->offset;
|
||||
@@ -75,9 +65,14 @@ void RasterizerStep::process(RenderPipe& pipe, const VertexShaderStep::NodeArray
|
||||
pixelData[j] = MathUtil::lerp3(vertex0[j], vertex1[j], vertex2[j], percentCorrected);
|
||||
}
|
||||
|
||||
if(dot.first==570 && dot.second==405 )
|
||||
{
|
||||
int a = 0;
|
||||
}
|
||||
fVector4 color;
|
||||
pixelShader->process(node.vertexDesc, &(pixelData[0]), color);
|
||||
|
||||
|
||||
float32_t depth = MathUtil::lerp3(vertexDepth[0], vertexDepth[1], vertexDepth[2], percentCorrected);
|
||||
|
||||
int32_t x = dot.first;
|
||||
|
||||
@@ -4,15 +4,12 @@
|
||||
|
||||
DV_CORE_BEGIN_NAMESPACE
|
||||
|
||||
fVector4 shader::texture2D(const RenderPipe& pipe, const char* textName, const fVector2& uv, const fVector4& defaultValue)
|
||||
fVector4 shader::texture2D(const RenderPipe& pipe, const Material::TextureInfo& textureInfo, const fVector2& uv, const fVector4& defaultValue)
|
||||
{
|
||||
davinci::fVector4 textureColor = defaultValue;
|
||||
const int32_t* textureID = (const int32_t* )(pipe.getUniformBuffer().getAttribute(textName));
|
||||
if (textureID != nullptr)
|
||||
{
|
||||
textureColor = pipe.getDevice().getTexture(*textureID)->sample(uv);
|
||||
}
|
||||
return textureColor;
|
||||
if (!(textureInfo.texture)) return defaultValue;
|
||||
fVector3 uvTransform = textureInfo.uvTransform * fVector3(uv, 1);
|
||||
return textureInfo.texture->sample(uvTransform.xy());
|
||||
}
|
||||
|
||||
|
||||
DV_CORE_END_NAMESPACE
|
||||
|
||||
Reference in New Issue
Block a user