This commit is contained in:
2025-11-15 16:27:19 +08:00
parent 8db6f7b115
commit a0beb9eac7
35 changed files with 886 additions and 128 deletions
+2 -12
View File
@@ -9,12 +9,7 @@ class TestShaderInterface : public davinci::ShaderFileInterface
public:
virtual davinci::VertexShaderInterface* getVertexShader(const char* szName)
{
if (strcmp(szName, "standard") == 0)
{
static StandardVertexShader standardVertexShader;
return &standardVertexShader;
}
else if (strcmp(szName, "test") == 0)
if (strcmp(szName, "test") == 0)
{
static TestVertexShader testVertexShader;
return &testVertexShader;
@@ -23,13 +18,8 @@ public:
}
virtual davinci::PixelShaderInterface* getPixelShader(const char* szName)
{
static SolidColorPixelShader solidColorPixelShader;
static TestPixelShader testPixelShader;
if(strcmp(szName, solidColorPixelShader.getName()) == 0)
{
return &solidColorPixelShader;
}
else if (strcmp(szName, testPixelShader.getName()) == 0)
if (strcmp(szName, testPixelShader.getName()) == 0)
{
return &testPixelShader;
}
+9 -44
View File
@@ -12,7 +12,7 @@ const char* TestPixelShader::getName(void) const
return "test";
}
void TestPixelShader::prepare(const RenderPipe* pipe, SetInputAttributeFunc setInputAttributeFunc)
void TestPixelShader::prepare(const RenderPipe* pipe, davinci::MaterialConstPtr material)
{
m_pipe = pipe;
}
@@ -68,76 +68,41 @@ void TestPixelShader::process(const VertexDesc& veretexDesc, const float32_t* pi
fVector3 u_lightColor = fVector3(1.0, 1.0, 1.0);
fVector4 u_textureColor = shader::texture2D(*m_pipe, "material:pbr:base_color_texture", *v_uv, fVector4::WHITE);
fVector4 u_textureColor;// = shader::texture2D(*m_pipe, "material:pbr:base_color_texture", *v_uv, fVector4::WHITE);
const fVector4 defaultNormal = fVector4(0.5f, 0.5f, 1.0f, 1.0f);
fVector4 u_normalColor = shader::texture2D(*m_pipe, "material:pbr:normal_texture", *v_uv, defaultNormal);
fVector4 u_normalColor;// = shader::texture2D(*m_pipe, "material:pbr:normal_texture", *v_uv, defaultNormal);
//----------------
fVector3 vN = fVector3::UNIT_Z;// u_normalColor.xyz() * 2.0f - fVector3::ONE;
fVector3 vN = u_normalColor.xyz() * 2.0f - fVector3::ONE;
vN.normalise();
//vector vL = normalize(v_toLight);
fVector3 vL =vLight;
vL.normalise();
//vector vV = normalize(v_toCamera);
fVector3 vV = *v_toCamera;
vV.normalise();
float ndotl = vL.dotProduct(vN);
//vector vR = 2 * dot(vL, vN)*vN - vL;
fVector3 vR = 2 * ndotl * vN - vL;
float rdotv = vR.dotProduct(vV);
//vector vH = normalize(vL + vV);
//fVector3 vH = vL + vV;
//vH.normalise();
//color colAmbient = u_ambientColor*u_matColor;
fVector3 colAmbient = u_ambientColor * u_matColor;
//float ndotl = max(dot(vN, vL), 0);
//float32_t ndotl = std::max(vN.dotProduct(vL), 0.0f);
//color colDiff = ndotl * u_matColor * u_lightColor;
fVector3 colDiff = shader::max(0.0f, ndotl) * u_matColor* u_lightColor;
//float32_t spec = std::max(vR.dotProduct(vV), 0.0f)*1.0;
//color colSpec = step(0, ndotl) * pow(spec, 64) * u_matColor * u_lightColor;
const float _m = 1.0f;
float spec = shader::step(0.0f, ndotl) * shader::pow(shader::max(0.0f, rdotv), 32.f);
fVector3 colSpec = spec * u_matColor* u_lightColor;
//color final = colAmbient + colDiff + colSpec;
fVector3 final = fVector3::BLACK;// (colAmbient + colDiff + colSpec)* u_textureColor.xyz();
final += colAmbient;
fVector3 final = fVector3::BLACK;
//final += colAmbient;
final += colDiff;
final += colSpec;
final *= u_textureColor.xyz();
//fVector3 final = (colAmbient +colDiff +colSpec)*u_textureColor.xyz();
//final += colSpec;
//final *= u_textureColor.xyz();
//final = u_normalColor.xyz();
//color = fVector4::RED;
color = fVector4(final.saturate(), 1.0f);// fVector4::RED;
}
const char* SolidColorPixelShader::getName(void) const
{
return "solid";
}
void SolidColorPixelShader::prepare(const RenderPipe* pipe, SetInputAttributeFunc setInputAttributeFunc)
{
}
void SolidColorPixelShader::process(const VertexDesc& veretexDesc, const float32_t* pixelData, fVector4& color)
{
color = fVector4::RED;
}
+1 -11
View File
@@ -8,7 +8,7 @@ class TestPixelShader : public davinci::PixelShaderInterface
public:
virtual const char* getName(void) const;
virtual void prepare(const davinci::RenderPipe* pipe, SetInputAttributeFunc setInputAttributeFunc);
virtual void prepare(const davinci::RenderPipe* pipe, davinci::MaterialConstPtr material);
virtual void process(const davinci::VertexDesc& veretexDesc, const float32_t* pixelData,
davinci::fVector4& color);
@@ -16,13 +16,3 @@ private:
const davinci::RenderPipe* m_pipe = nullptr;
};
class SolidColorPixelShader : public davinci::PixelShaderInterface
{
public:
virtual const char* getName(void) const;
virtual void prepare(const davinci::RenderPipe* pipe, SetInputAttributeFunc setInputAttributeFunc);
virtual void process(const davinci::VertexDesc& veretexDesc, const float32_t* pixelData,
davinci::fVector4& color);
};
+4 -4
View File
@@ -63,7 +63,7 @@ void TestVertexShader::process(size_t index, void* outputVertex, davinci::fVecto
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_TANGENT[] = { 1.f, 0.f, 0.f };
static const float32_t DEFAULT_TANGENT[] = { 1.f, 0.f, 0.f, 1.f };
const davinci::UniformBuffer& uniformBuffer = m_pipe->getUniformBuffer();
@@ -73,7 +73,7 @@ void TestVertexShader::process(size_t index, void* outputVertex, davinci::fVecto
davinci::fVector2 a_uv(m_TEXCOORD_0 ? (const float32_t*)(m_TEXCOORD_0->getElement(index)) : DEFAULT_TEXCOORD0);
davinci::fVector3 a_tangent(m_TANGENT ? (const float32_t*)(m_TANGENT->getElement(index)) : DEFAULT_TANGENT);
davinci::fVector4 a_tangent(m_TANGENT ? (const float32_t*)(m_TANGENT->getElement(index)) : DEFAULT_TANGENT);
davinci::fMatrix4 mat_world = davinci::fMatrix4::IDENTITY;
if (davinci::fMatrix4* p_mat_world = (davinci::fMatrix4*)(uniformBuffer.getAttribute("self:world_transform")))
@@ -108,8 +108,8 @@ void TestVertexShader::process(size_t index, void* outputVertex, davinci::fVecto
matNormal = *p_mat_normal;
}
davinci::fVector3 v_normal = (matNormal * davinci::fVector4(a_normal, 0)).xyz().normalise();
davinci::fVector3 v_tangent = (matNormal * davinci::fVector4(a_tangent, 0)).xyz().normalise();
davinci::fVector3 v_binormal = v_normal.crossProduct(v_tangent).normalise();
davinci::fVector3 v_tangent = (matNormal * davinci::fVector4(a_tangent.xyz(), 0)).xyz().normalise();
davinci::fVector3 v_binormal = v_normal.crossProduct(v_tangent).normalise();// *a_tangent.w;
davinci::fMatrix3 tbnMatrix = davinci::fMatrix3(
v_tangent.x, v_binormal.x, v_normal.x,