void SceneDrawCall::Draw(const Camera& camera, const Vector4f& rotation, const Vector3f& translate, const Vector3f& eyePos, const Vector3f& lightPosition, const Material& m, std::function<void()> draw) { _SetMaterial(m); _transform.SetCamera(camera); _transform.SetArbitraryRotation(rotation[1], rotation[2], rotation[3], rotation[4]); _transform.SetTranslate(translate.x, translate.y, translate.z); Matrix4f modelMatrix; _transform.GetModelMatrix(modelMatrix); //TODO can I use rvalue-reference here? Matrix4f invModelMatrix = modelMatrix.Invert(); Vector3f objSpaceEyePosition = _MatVecMulReduced(invModelMatrix, eyePos); _vertParam->SetEyePosition(objSpaceEyePosition); Vector3f objSpaceLightPosition = _MatVecMulReduced(invModelMatrix, lightPosition); _vertParam->SetLightPos(objSpaceLightPosition); Matrix4f modelViewProjMatix; _transform.GetMVPMatrix(modelViewProjMatix); _vertParam->SetMVPMatrix(modelViewProjMatix); // deferred params are updated, aka, perform a draw call _vertShader->UpdateParams(); _fragShader->UpdateParams(); draw(); }
void CEditRenderPipeline::SetRenderStyle( const STATIC_RS& RenderStyle ) { //m_pipeline->SetRenderStyle(RenderStyle); //return ; m_GraphicRenderStyle.m_Material = RenderStyle.m_Material; CRenderPipeline::GetInst()->SetShader(RenderStyle.m_ShaderType); _SetMaterial( m_GraphicRenderStyle.m_Material ); _SetRenderStyle ( RS_ALPHAREF, RenderStyle.m_Alpharef ); if (m_GraphicRenderStyle.m_Texturefactor!=RenderStyle.m_Texturefactor || bReFreshTexFactor) { m_GraphicRenderStyle.m_Texturefactor = RenderStyle.m_Texturefactor; _SetRenderStyle ( RS_TEXTUREFACTOR, m_GraphicRenderStyle.m_Texturefactor ); CColor4 factor = m_GraphicRenderStyle.m_Texturefactor; SetFragmentShaderF(ACT_TEXTURE_FACTOR, factor.r, factor.g, factor.b, factor.a); bReFreshTexFactor = false; } float Params[4]; Params[0] = (float)RenderStyle.m_Alpharef; Params[1] = (float)RenderStyle.m_Material.Diffuse.a; Params[2] = (float)RenderStyle.m_Material.Specular.a; SetVertexShaderF(ACT_TEXTURE_FACTOR,Params,1); CColor4 tSpecular(0.0f,0.0f,0.0f,0.0f); if (RenderStyle.m_SpecularEnable) { tSpecular = m_GraphicRenderStyle.m_Material.Specular; tSpecular.a = m_GraphicRenderStyle.m_Material.Power; } SetVertexShaderF(ACT_MAT_DIFFUSE_COLOR , (float*)&m_GraphicRenderStyle.m_Material.Diffuse, 1); SetVertexShaderF(ACT_MAT_AMBIENT_COLOR , (float*)&m_GraphicRenderStyle.m_Material.Ambient, 1); SetVertexShaderF(ACT_MAT_SPECULAR_COLOR , (float*)&tSpecular, 1); SetVertexShaderF(ACT_MAT_EMISSIVE_COLOR , (float*)&m_GraphicRenderStyle.m_Material.Emissive, 1); SetVertexShaderF(ACT_REFRACT_SCALAR , RenderStyle.m_fRefractIndex); SetVertexShaderF(ACT_UV_INDEX , float(RenderStyle.m_Uv_S0) , float(RenderStyle.m_Uv_S1) , float(RenderStyle.m_Uv_S2) ); //_SetRenderStyle ( RS_SLOPESCALEDEPTHBIAS, *(DWORD*)&(RenderStyle.m_fSlopeScaleZBias)); _SetRenderStyle ( RS_DEPTHBIAS, *(DWORD*)&(RenderStyle.m_fZBias)); _SetRenderStyle ( RS_ALPHABLENDENABLE, RenderStyle.m_AlphaBlendEnable ); _SetRenderStyle ( RS_SRCBLEND, RenderStyle.m_SrcBlend ); _SetRenderStyle ( RS_DESTBLEND, RenderStyle.m_DestBlend ); _SetRenderStyle ( RS_ALPHATESTENABLE, RenderStyle.m_AlphaTestEnable ); _SetRenderStyle ( RS_ALPHAFUNC, RenderStyle.m_AlphaTestFun ); _SetRenderStyle ( RS_LIGHTING, RenderStyle.m_LightEnable ); _SetRenderStyle ( RS_SPECULARENABLE, RenderStyle.m_SpecularEnable ); _SetRenderStyle ( RS_ZENABLE, RenderStyle.m_ZTestEnable ); _SetRenderStyle ( RS_ZFUNC, RenderStyle.m_ZTestFun ); _SetRenderStyle ( RS_ZWRITEENABLE, RenderStyle.m_ZWrite ); _SetRenderStyle ( RS_CULLMODE, RenderStyle.m_Cull ); _SetRenderStyle ( RS_FILLMODE, RenderStyle.m_FillMode ); bool isClipPlaneValid = RenderStyle.m_ClipPlane.IsValid(); if (isClipPlaneValid) { CPlane plane = RenderStyle.m_ClipPlane; if (RenderStyle.m_ShaderType.GetVSShaderID()) { // transform to clipping space CMatrix transform = m_CurViewProj; MatrixInverse(transform); transform.Transpose(); plane.Transform(transform); } _SetClipPlane(0, plane); } _SetRenderStyle( RS_CLIPPLANEENABLE, DWORD(isClipPlaneValid ? CLIPPLANE0 : 0) ); SetTextureEx(RenderStyle); }