std::shared_ptr<Mesh> Light::EvaluateVolume() { if (m_Mesh) m_Mesh.reset(); if (m_Type == LightType::DIRECTIONAL) { m_Mesh = MeshUtil::GetUnitQuad(); } else if (m_Type == LightType::POINT) { m_Mesh = MeshUtil::GetUnitIcoSphere(); } else { float height = m_Radius; float bottomR = std::tan(m_OutterAngle * 0.5f) * height; m_Mesh = MeshUtil::CreateCylinder("spotlight_convex", 0.0f, bottomR, height, 5, 20); Matrix4 matrix; matrix.Translate(Vector4(0.0f, -height * 0.5f, 0.0f)); MeshUtil::TransformMesh(m_Mesh, matrix); } return m_Mesh; }
void DrawGridScene( std::shared_ptr<RenderingContext> context, const Matrix4& matWorld ) { Assert( context ); ConstantBuffer& cbuffer = context->GetSharedConstantBuffer(); float scale = model_scale.Float(); size_t columns = grid_size.Int(); float rowFactor = 1.0f / grid_size.Int(); float colFactor = 1.0f / columns; for ( int row = 0; row < grid_size.Int(); ++row ) { for ( size_t col = 0; col < columns; ++col ) { // world transform Matrix4 matTrans; matTrans.Translate( ( ( col + 1 ) * colFactor - colFactor * ( columns * 0.5f ) ) * columns, ( ( row + 1 ) * rowFactor - rowFactor * ( columns * 0.5f ) ) * columns, ( ( row + 1 ) * rowFactor - rowFactor * ( columns * 0.5f ) ) * columns ); Matrix4 matScale; matScale.Scaling( scale, scale, scale ); Matrix4 matNewWorld = matScale * matWorld * matTrans; cbuffer.SetMatrix4( ConstantBuffer::WorldMatrix, matNewWorld ); // various color cbuffer.SetVector4( ConstantBuffer::DiffuseColor, Vector4( max( 0.2f, matTrans.A41 * 0.5f + 0.8f ), max( 0.4f, matTrans.A42 * 0.5f + 0.6f ), matTrans.A43 * 0.5f + 1.0f, 1.0f ) ); context->Draw( GetMeshes()[row * columns + col] ); } } }
Matrix4 Camera3D::GetCameraViewMatrix(){ //get transform matrix Matrix4 cameraTransformMatrix; cameraTransformMatrix.Translate(m_position); cameraTransformMatrix.m_translation.x *= -1.0f; //stopgap fix for -zUP issue cameraTransformMatrix.m_translation.z *= -1.0f; //stopgap fix for -zUP issue Matrix4 viewMatrix = /* GetCameraRotationMatrix() * */ cameraTransformMatrix * GetCameraRotationMatrix(); //R*T = rotate around origin, movement correct //T*R = rotate correct, absolute movement viewMatrix.Transpose(); //the movement is absolute regardless of rotation for whatever reason... return viewMatrix; }
void DrawGridSceneInParallel( StlVector<std::shared_ptr<RenderingContext>>& contexts, const Matrix4& matWorld ) { float scale = model_scale.Float(); size_t rows = grid_size.Int(); size_t columns = grid_size.Int(); float rowFactor = 1.0f / grid_size.Int(); float colFactor = 1.0f / columns; //using FuncPreRender = std::function<void( std::shared_ptr<RenderingContext> context, const std::shared_ptr<IMesh>& mesh, size_t index )>; RenderingContext::FuncPreRender funcPreRender( [=]( std::shared_ptr<RenderingContext> context, size_t index ) { ConstantBuffer& cbuffer = context->GetSharedConstantBuffer(); // world transform size_t row = kih::Clamp<size_t>( index / rows, 0, rows - 1 ); size_t col = kih::Clamp<size_t>( index - row * columns, 0, columns - 1 ); Matrix4 matTrans; matTrans.Translate( ( ( col + 1 ) * colFactor - colFactor * ( columns * 0.5f ) ) * columns, ( ( row + 1 ) * rowFactor - rowFactor * ( columns * 0.5f ) ) * columns, ( ( row + 1 ) * rowFactor - rowFactor * ( columns * 0.5f ) ) * columns ); Matrix4 matScale; matScale.Scaling( scale, scale, scale ); Matrix4 matNewWorld = matScale * matWorld * matTrans; cbuffer.SetMatrix4( ConstantBuffer::WorldMatrix, matNewWorld ); // various color cbuffer.SetVector4( ConstantBuffer::DiffuseColor, Vector4( max( 0.2f, matTrans.A41 * 0.5f + 0.8f ), max( 0.4f, matTrans.A42 * 0.5f + 0.6f ), matTrans.A43 * 0.5f + 1.0f, 1.0f ) ); } ); RenderingContext::DrawInParallel( contexts, GetMeshes(), grid_size.Int() * grid_size.Int(), funcPreRender ); }