增加材质和纹理

This commit is contained in:
2025-10-26 20:07:32 +08:00
parent f847154ba2
commit 8db6f7b115
45 changed files with 1124 additions and 281 deletions
+39
View File
@@ -0,0 +1,39 @@
#pragma once
#include "dvc_config.h"
#include "dvc_pre_declare.h"
#include "math/dvc_vector2.h"
#include "math/dvc_vector4.h"
DV_CORE_BEGIN_NAMESPACE
class DV_CORE_API Image
{
public:
int32_t getID(void) const { return m_id; }
int32_t getWidth(void) const { return m_width; }
int32_t getHeight(void) const { return m_height; }
PixelFormat getPixelFormat(void) const { return m_pixelFormat; }
DeviceBufferConstPtr getPixelBuffer(void) const { return m_pixelBuffer; }
fVector4 getPixel(int32_t u, int32_t v) const;
void clear();
bool initWithPixelData(Device& device, int32_t width, int32_t height,
PixelFormat pixelFormat, const uint8_t* data, size_t dataSize);
protected:
int32_t m_id;
int32_t m_width;
int32_t m_height;
PixelFormat m_pixelFormat;
size_t m_pixelByteSize;
DeviceBufferPtr m_pixelBuffer;
public:
Image(int32_t id);
~Image();
};
DV_CORE_END_NAMESPACE
+113
View File
@@ -0,0 +1,113 @@
#pragma once
#include "dvc_config.h"
#include "dvc_pre_declare.h"
#include "math/dvc_vector4.h"
DV_CORE_BEGIN_NAMESPACE
class DV_CORE_API Material
{
public:
struct TextureInfo
{
TextureConstPtr texture;
int32_t texCoord = 0;
};
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;
}
const TextureInfo& getBaseColorTexture() const {
return m_baseColorTexture;
}
const fVector4& getBaseColorFactor() const {
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;
}
const TextureInfo& getMetallicRoughnessTexture() const {
return m_metallicRoughnessTexture;
}
float32_t getMetallicFactor() const {
return m_metallicFactor;
}
float32_t getRoughnessFactor() const {
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;
}
const TextureInfo& getNormalTexture() const {
return m_normalTexture;
}
float32_t getNormalScale() const {
return m_normalScale;
}
VertexShaderInterface* getVertexShader() const {
return m_vertexShader;
}
PixelShaderInterface* getPixelShader() const {
return m_pixelShader;
}
public:
bool loadShader();
protected:
int32_t m_id;
/*The base color texture.
* The first three components (RGB) MUST be encoded with the sRGB transfer function.
*/
TextureInfo m_baseColorTexture;
fVector4 m_baseColorFactor = fVector4::ONE;
/*The metallic - roughness texture.
* The metalness values are sampled from the B channel.
* The roughness values are sampled from the G channel.
*/
TextureInfo m_metallicRoughnessTexture;
float32_t m_metallicFactor = 1.0f;
float32_t m_roughnessFactor = 1.0f;
/*The normal texture.
*/
TextureInfo m_normalTexture;
/*The scalar parameter applied to each normal vector of the texture.
* This value scales the normal vector in X and Y directions using the formula:
* scaledNormal = (normalize<sampled normal texture value> * 2.0 - 1.0) * vec3(<normal scale>, <normal scale>, 1.0).
*/
float32_t m_normalScale = 1.0f;
protected:
VertexShaderInterface* m_vertexShader = nullptr;
PixelShaderInterface* m_pixelShader = nullptr;
public:
Material(int32_t id);
~Material();
};
DV_CORE_END_NAMESPACE
+5 -1
View File
@@ -14,12 +14,15 @@ public:
PrimitiveType type;
PrimitiveAttributes attributes;
DeviceBufferAccessorConstPtr indices;
MaterialPtr material;
};
typedef std::shared_ptr<Primitive> PrimitivePtr;
typedef std::shared_ptr<const Primitive> PrimitiveConstPtr;
typedef std::vector<PrimitivePtr> PrimitiveArray;
public:
int32_t getID(void) const { return m_id; }
const std::string& getName(void) const {
return m_name;
}
@@ -31,11 +34,12 @@ public:
PrimitiveConstPtr getPrimitive(int32_t index) const;
private:
int32_t m_id;
std::string m_name;
PrimitiveArray m_primitiveArray;
public:
Mesh(const std::string& name);
Mesh(int32_t id, const std::string& name);
~Mesh();
};
+28
View File
@@ -0,0 +1,28 @@
#pragma once
#include "dvc_config.h"
#include "dvc_pre_declare.h"
#include "math/dvc_vector2.h"
#include "math/dvc_vector4.h"
DV_CORE_BEGIN_NAMESPACE
class DV_CORE_API Texture
{
public:
int32_t getID(void) const { return m_id; }
ImagePtr getImage(void) const { return m_image; }
void setImage(const ImagePtr& image) { m_image = image; }
fVector4 sample(const fVector2& uv) const;
private:
int32_t m_id;
ImagePtr m_image;
public:
Texture(int32_t id);
~Texture();
};
DV_CORE_END_NAMESPACE