Reputation: 31
I'm working on a software renderer.And I use the GLM library for vector and matrix calculations.I found that vector times matrix takes 30 milliseconds on my Shader Class.What puzzles me the most is that when I compute the vector times the matrix in my main function alone, I get a time difference of 0 milliseconds. I use GettickCount64 to calculate the Time difference.
finally,I appreciate you reading through my question.And English is not my first language.If you're wondering about my question or the syntax,Please ask me for more details.
The following is my shader Code.
class TriangleShader :public Shader
{
public:
glm::mat3x3 normal_mat_f;
glm::mat2x3 uv_mat_f;
public:
TriangleShader() :normal_mat_f(0), uv_mat_f(0) {}
void vertexShader(glm::mat4x3& vertex_mat, glm::mat4x4& M, const glm::mat3x3& normal_mat, const glm::mat2x3& uv_mat) override
{
normal_mat_f = normal_mat;
uv_mat_f = uv_mat;
vertex_mat = vertex_mat * M; //乘以视图变换矩阵
}
TGAColor fragmentShader(glm::vec3 bc, double& totaltime, Model& model) override
{
DWORD start_time = 0, end_time = 0;
start_time = GetTickCount64();
glm::vec2 uv = bc * uv_mat_f; //30ms
end_time = GetTickCount64();
totaltime += end_time - start_time;
//法向量计算光照强度
glm::vec3 n = model.normal(uv);
//Vec3f n = normal_mat_f * bc;
n = glm::normalize(n); //法线归一化
float intensity = std::max((float)0, glm::dot(n, light)); //计算光照强度(防止光照强度小于0)
//计算颜色
TGAColor color = model.diffuse(uv);
//加上环境光照
return color * intensity + 5;
}
};
I want to be able to compute vector times matrix in 5 milliseconds.
Upvotes: 1
Views: 262