Fixed shadow maps for MeshHierarchies, radius can be specfied when creating sphere meshes
parent
2365fe04ff
commit
4deba61a09
|
@ -744,7 +744,7 @@ void Camera::updateMatrices() {
|
||||||
-height * 0.5f, height * 0.5f,
|
-height * 0.5f, height * 0.5f,
|
||||||
near, far);
|
near, far);
|
||||||
} else {
|
} else {
|
||||||
float aspect = width / height;
|
float aspect = static_cast<float>(width) / height;
|
||||||
float mtx_proj[16];
|
float mtx_proj[16];
|
||||||
bx::mtxProjRh(mtxProj, fov, aspect, near, far);
|
bx::mtxProjRh(mtxProj, fov, aspect, near, far);
|
||||||
}
|
}
|
||||||
|
@ -1446,16 +1446,39 @@ void Renderer::paintGL() {
|
||||||
for (size_t i = 0; i < entities.size(); i++) {
|
for (size_t i = 0; i < entities.size(); i++) {
|
||||||
float mtxLightViewProjInv[16];
|
float mtxLightViewProjInv[16];
|
||||||
float light_pos_world[3];
|
float light_pos_world[3];
|
||||||
|
|
||||||
// shadow map pass
|
// shadow map pass
|
||||||
bx::mtxMul(lightMtx, entities[i]->transform.toMatrix().data(), lights[0].mtxShadow);
|
for (uint32_t j = 0; j < entities[i]->mesh.meshes.size(); ++j) {
|
||||||
|
bx::mtxMul(
|
||||||
|
lightMtx,
|
||||||
|
entities[i]->mesh.meshMatrices[j].data(),
|
||||||
|
lights[0].mtxShadow
|
||||||
|
);
|
||||||
bgfx::setUniform(lights[0].u_lightMtx, lightMtx);
|
bgfx::setUniform(lights[0].u_lightMtx, lightMtx);
|
||||||
entities[i]->mesh.submit (&s_renderStates[RenderState::ShadowMap]);
|
bgfxutils::meshSubmit (
|
||||||
|
entities[i]->mesh.meshes[j],
|
||||||
|
&s_renderStates[RenderState::ShadowMap],
|
||||||
|
1,
|
||||||
|
entities[i]->mesh.meshMatrices[j].data()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// scene pass
|
// scene pass
|
||||||
bx::mtxMul(lightMtx, entities[i]->transform.toMatrix().data(), lights[0].mtxShadow);
|
for (uint32_t j = 0; j < entities[i]->mesh.meshes.size(); ++j) {
|
||||||
|
bx::mtxMul(
|
||||||
|
lightMtx,
|
||||||
|
entities[i]->mesh.meshMatrices[j].data(),
|
||||||
|
lights[0].mtxShadow
|
||||||
|
);
|
||||||
bgfx::setUniform(lights[0].u_lightMtx, lightMtx);
|
bgfx::setUniform(lights[0].u_lightMtx, lightMtx);
|
||||||
bgfx::setUniform(u_color, entities[i]->color, 4);
|
bgfx::setUniform(u_color, entities[i]->color, 4);
|
||||||
entities[i]->mesh.submit (&s_renderStates[RenderState::Scene]);
|
bgfxutils::meshSubmit (
|
||||||
|
entities[i]->mesh.meshes[j],
|
||||||
|
&s_renderStates[RenderState::Scene],
|
||||||
|
1,
|
||||||
|
entities[i]->mesh.meshMatrices[j].data()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// render debug information
|
// render debug information
|
||||||
|
@ -1641,8 +1664,9 @@ void Renderer::paintGL() {
|
||||||
|
|
||||||
float thickness = 0.05f;
|
float thickness = 0.05f;
|
||||||
float miter = 0.0f;
|
float miter = 0.0f;
|
||||||
|
float aspect = static_cast<float>(width) / height;
|
||||||
|
|
||||||
Vector4f params (thickness, miter, width / height, 0.0f);
|
Vector4f params (thickness, miter, aspect, 0.0f);
|
||||||
|
|
||||||
Camera &active_camera = cameras[activeCameraIndex];
|
Camera &active_camera = cameras[activeCameraIndex];
|
||||||
|
|
||||||
|
|
|
@ -218,6 +218,27 @@ struct Transform {
|
||||||
return Vector3f::Zero();
|
return Vector3f::Zero();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Transform fromTrans(
|
||||||
|
const Vector3f &translation
|
||||||
|
) {
|
||||||
|
return Transform (
|
||||||
|
translation,
|
||||||
|
Quaternion(0.0f, 0.0f, 0.0f, 1.0f),
|
||||||
|
Vector3f(1.0f, 1.0f, 1.0f)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Transform fromTransRot(
|
||||||
|
const Vector3f &translation,
|
||||||
|
const Quaternion &rotation
|
||||||
|
) {
|
||||||
|
return Transform (
|
||||||
|
translation,
|
||||||
|
rotation,
|
||||||
|
Vector3f(1.0f, 1.0f, 1.0f)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
static Transform fromTransRotScale(
|
static Transform fromTransRotScale(
|
||||||
const Vector3f &translation,
|
const Vector3f &translation,
|
||||||
const Quaternion &rotation,
|
const Quaternion &rotation,
|
||||||
|
@ -248,7 +269,7 @@ struct MeshHierarchy {
|
||||||
const int parent_idx,
|
const int parent_idx,
|
||||||
const Transform& transform,
|
const Transform& transform,
|
||||||
bgfxutils::Mesh* mesh) {
|
bgfxutils::Mesh* mesh) {
|
||||||
assert (parent_idx == -1 || parent_idx < parent.size() - 1);
|
assert (parent_idx == -1 || parent_idx < parent.size());
|
||||||
parent.push_back(parent_idx);
|
parent.push_back(parent_idx);
|
||||||
localTransforms.push_back(transform);
|
localTransforms.push_back(transform);
|
||||||
meshes.push_back(mesh);
|
meshes.push_back(mesh);
|
||||||
|
|
|
@ -1101,7 +1101,7 @@ Mesh *createCuboid (float width, float height, float depth) {
|
||||||
return createMeshFromStdVectors (vertices, normals, colors);
|
return createMeshFromStdVectors (vertices, normals, colors);
|
||||||
}
|
}
|
||||||
|
|
||||||
Mesh *createUVSphere (int rows, int segments) {
|
Mesh *createUVSphere (int rows, int segments, float radius) {
|
||||||
// work arrays that we fill with data
|
// work arrays that we fill with data
|
||||||
std::vector<Vector4f> vertices;
|
std::vector<Vector4f> vertices;
|
||||||
std::vector<Vector3f> normals;
|
std::vector<Vector3f> normals;
|
||||||
|
@ -1115,11 +1115,11 @@ Mesh *createUVSphere (int rows, int segments) {
|
||||||
float alpha0 = j * row_d * M_PI;
|
float alpha0 = j * row_d * M_PI;
|
||||||
float alpha1 = (j + 1) * row_d * M_PI;
|
float alpha1 = (j + 1) * row_d * M_PI;
|
||||||
|
|
||||||
float r0 = sin (alpha0) * 0.5f;
|
float r0 = sin (alpha0) * 0.5f * radius;
|
||||||
float r1 = sin (alpha1) * 0.5f;
|
float r1 = sin (alpha1) * 0.5f * radius;
|
||||||
|
|
||||||
float h0 = cos (alpha0) * 0.5f;
|
float h0 = cos (alpha0) * 0.5f * radius;
|
||||||
float h1 = cos (alpha1) * 0.5f;
|
float h1 = cos (alpha1) * 0.5f * radius;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < segments; i++) {
|
for (unsigned int i = 0; i < segments; i++) {
|
||||||
Vector3f v0, v1, v2, v3;
|
Vector3f v0, v1, v2, v3;
|
||||||
|
|
|
@ -55,8 +55,10 @@ namespace bgfxutils {
|
||||||
// Loads the mesh data from a VBO into a bgfx Mesh
|
// Loads the mesh data from a VBO into a bgfx Mesh
|
||||||
// Mesh *createMeshFromVBO (const MeshVBO& mesh_buffer);
|
// Mesh *createMeshFromVBO (const MeshVBO& mesh_buffer);
|
||||||
|
|
||||||
|
void meshTransform (Mesh* mesh, const float *mtx);
|
||||||
|
|
||||||
Mesh *createCuboid (float width, float height, float depth);
|
Mesh *createCuboid (float width, float height, float depth);
|
||||||
Mesh *createUVSphere (int rows, int segments);
|
Mesh *createUVSphere (int rows, int segments, float radius = 1.0f);
|
||||||
Mesh *createCylinder (int segments);
|
Mesh *createCylinder (int segments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -285,6 +285,7 @@ static void module_serialize (
|
||||||
struct module_state *state,
|
struct module_state *state,
|
||||||
Serializer* serializer) {
|
Serializer* serializer) {
|
||||||
SerializeVec3(*serializer, "protot.TestModule.entity.position", state->character->position);
|
SerializeVec3(*serializer, "protot.TestModule.entity.position", state->character->position);
|
||||||
|
SerializeVec3(*serializer, "protot.TestModule.entity.velocity", state->character->velocity);
|
||||||
SerializeBool(*serializer, "protot.TestModule.character_window.visible", state->character_properties_window_visible);
|
SerializeBool(*serializer, "protot.TestModule.character_window.visible", state->character_properties_window_visible);
|
||||||
SerializeBool(*serializer, "protot.TestModule.modules_window.visible", state->modules_window_visible);
|
SerializeBool(*serializer, "protot.TestModule.modules_window.visible", state->modules_window_visible);
|
||||||
SerializeInt(*serializer, "protot.TestModule.modules_window.selection_index", state->modules_window_selected_index);
|
SerializeInt(*serializer, "protot.TestModule.modules_window.selection_index", state->modules_window_selected_index);
|
||||||
|
@ -309,24 +310,30 @@ static void module_reload(struct module_state *state, void* read_serializer) {
|
||||||
|
|
||||||
cout << "Creating render entity mesh ..." << endl;
|
cout << "Creating render entity mesh ..." << endl;
|
||||||
|
|
||||||
Vector3f snowman_offsets (0.45f, 0.35f, 0.25f);
|
// Build the snowman
|
||||||
float height_offset = 0.0f;
|
state->character->entity->mesh.addMesh(
|
||||||
for (int i = 0; i < 3; i++) {
|
- 1,
|
||||||
float radius = cCharacterHeight * snowman_offsets[i];
|
Transform::fromTrans(
|
||||||
Transform transform = Transform::fromTransRotScale(
|
Vector3f (0.0f, 0.9 * 0.5f, 0.0f)
|
||||||
Vector3f(0.f, height_offset + radius * 0.5f, 0.0f),
|
),
|
||||||
Quaternion(0.0f, 0.0f, 0.0f, 1.0f),
|
bgfxutils::createUVSphere (45, 45, 0.9)
|
||||||
Vector3f(radius, radius, radius)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
state->character->entity->mesh.addMesh(
|
state->character->entity->mesh.addMesh(
|
||||||
-1,
|
0,
|
||||||
transform,
|
Transform::fromTrans(
|
||||||
bgfxutils::createUVSphere (45, 45)
|
Vector3f (0.0f, 0.55f, 0.0f)
|
||||||
|
),
|
||||||
|
bgfxutils::createUVSphere (45, 45, 0.7)
|
||||||
);
|
);
|
||||||
|
|
||||||
height_offset += radius * 0.8;
|
state->character->entity->mesh.addMesh(
|
||||||
}
|
1,
|
||||||
|
Transform::fromTrans(
|
||||||
|
Vector3f (0.0f, 0.4f, 0.0f)
|
||||||
|
),
|
||||||
|
bgfxutils::createUVSphere (45, 45, 0.5)
|
||||||
|
);
|
||||||
|
|
||||||
// state->character->entity->mesh = bgfxutils::createCuboid (1.f, 1.f, 1.f);
|
// state->character->entity->mesh = bgfxutils::createCuboid (1.f, 1.f, 1.f);
|
||||||
// state->character->entity->mesh = bgfxutils::createCylinder (20);
|
// state->character->entity->mesh = bgfxutils::createCylinder (20);
|
||||||
|
|
Loading…
Reference in New Issue