Hello all!
I have some questions about passing uniforms to a post-process effect.
Suppose I need camera rotation, projection matrix, projection-view matrix (let’s ignore that I should get it from the camera inverse) in a “quad” command. How can I set these uniforms?
Urho variants can’t store a matrix, but I can use 4 vectors. I’ve tried this:
[code]void WorkSample::HandleRenderUpdate(StringHash eventType, VariantMap& eventData)
{
// Camera rotation
Matrix3 r = camera_->GetEffectiveWorldTransform().RotationMatrix();
// Projection matrix
Matrix4 p = camera_->GetProjection();
// Projection-View matrix
Matrix4 pv = p * camera_->GetView();
#ifdef USE_OPENGL
r = r.Transpose();
p = p.Transpose();
pv = pv.Transpose();
#endif
renderPath_->SetShaderParameter("CamRotRow0", *(Vector3*)&r.m00_);
renderPath_->SetShaderParameter("CamRotRow1", *(Vector3*)&r.m10_);
renderPath_->SetShaderParameter("CamRotRow2", *(Vector3*)&r.m20_);
renderPath_->SetShaderParameter("ProjRow0", *(Vector4*)&p.m00_);
renderPath_->SetShaderParameter("ProjRow1", *(Vector4*)&p.m10_);
renderPath_->SetShaderParameter("ProjRow2", *(Vector4*)&p.m20_);
renderPath_->SetShaderParameter("ProjRow3", *(Vector4*)&p.m30_);
// Frustum size
Vector3 nearVector, farVector;
camera->GetFrustumSize(nearVector, farVector);
renderPath_->SetShaderParameter("FrustumSize", farVector);
}[/code]
And then in the shader:
[code]uniform vec4 cProjRow0;
uniform vec4 cProjRow1;
uniform vec4 cProjRow2;
uniform vec4 cProjRow3;
void PS()
{
mat4 proj = mat4(cProjRow0, cProjRow1, cProjRow2, cProjRow3);
}[/code]
Can this work? Am I getting the correct matrices?
Another problem, suppose I wanted to use GetFarRay() which uses the uniform mat3 cCameraRot, but how can I set it? Is there a way to set uniforms directly after the shader program was binded?
Thank you.