alpha to coverage in the material editor; all of the grass is rendered
This commit is contained in:
parent
defb3ca094
commit
efe647031d
6 changed files with 44 additions and 55 deletions
|
@ -80,16 +80,31 @@ void MaterialManager::fillObjectMaterials()
|
|||
}
|
||||
}
|
||||
|
||||
void MaterialManager::setWorldEditor(Lumix::WorldEditor& server)
|
||||
|
||||
void MaterialManager::onEntitySelected(Lumix::Entity& entity)
|
||||
{
|
||||
if (entity.isValid())
|
||||
{
|
||||
Lumix::Component cmp = entity.getComponent(crc32("renderable"));
|
||||
if (cmp.isValid())
|
||||
{
|
||||
m_impl->m_selected_object_model = static_cast<Lumix::RenderScene*>(cmp.system)->getModel(cmp);
|
||||
fillObjectMaterials();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MaterialManager::setWorldEditor(Lumix::WorldEditor& editor)
|
||||
{
|
||||
ASSERT(m_impl->m_engine == NULL);
|
||||
HWND hwnd = (HWND)m_ui->previewWidget->winId();
|
||||
m_impl->m_engine = &server.getEngine();
|
||||
editor.entitySelected().bind<MaterialManager, &MaterialManager::onEntitySelected>(this);
|
||||
m_impl->m_engine = &editor.getEngine();
|
||||
m_impl->m_universe = new Lumix::Universe();
|
||||
m_impl->m_universe->create();
|
||||
|
||||
m_impl->m_render_scene = Lumix::RenderScene::createInstance(server.getEngine(), *m_impl->m_universe);
|
||||
m_impl->m_render_device = new WGLRenderDevice(server.getEngine(), "pipelines/main.json");
|
||||
m_impl->m_render_scene = Lumix::RenderScene::createInstance(editor.getEngine(), *m_impl->m_universe);
|
||||
m_impl->m_render_device = new WGLRenderDevice(editor.getEngine(), "pipelines/main.json");
|
||||
m_impl->m_render_device->m_hdc = GetDC(hwnd);
|
||||
m_impl->m_render_device->m_opengl_context = wglGetCurrentContext();
|
||||
m_impl->m_render_device->getPipeline().setScene(m_impl->m_render_scene);
|
||||
|
@ -268,6 +283,7 @@ void MaterialManager::onMaterialLoaded(Lumix::Resource::State, Lumix::Resource::
|
|||
ICppObjectProperty* properties[] =
|
||||
{
|
||||
new CppObjectProperty<bool, Lumix::Material>("Z test", &Lumix::Material::isZTest, &Lumix::Material::enableZTest),
|
||||
new CppObjectProperty<bool, Lumix::Material>("Alpha to coverage", &Lumix::Material::isAlphaToCoverage, &Lumix::Material::enableAlphaToCoverage),
|
||||
new CppObjectProperty<bool, Lumix::Material>("Backface culling", &Lumix::Material::isBackfaceCulling, &Lumix::Material::enableBackfaceCulling),
|
||||
new CppObjectProperty<Lumix::Shader*, Lumix::Material>("Shader", &Lumix::Material::getShader, &Lumix::Material::setShader)
|
||||
};
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace Ui
|
|||
namespace Lumix
|
||||
{
|
||||
class WorldEditor;
|
||||
struct Entity;
|
||||
class Event;
|
||||
struct PropertyListEvent;
|
||||
}
|
||||
|
@ -26,10 +27,10 @@ class MaterialManager : public QDockWidget
|
|||
void updatePreview();
|
||||
|
||||
private:
|
||||
void onPropertyList(Lumix::PropertyListEvent& event);
|
||||
void fillObjectMaterials();
|
||||
void selectMaterial(const char* path);
|
||||
void onMaterialLoaded(Lumix::Resource::State, Lumix::Resource::State);
|
||||
void onEntitySelected(Lumix::Entity& entity);
|
||||
|
||||
private slots:
|
||||
void on_fileListView_doubleClicked(const QModelIndex& index);
|
||||
|
|
|
@ -37,6 +37,8 @@ public:
|
|||
void enableZTest(bool enable) { m_is_z_test = enable; }
|
||||
bool isBackfaceCulling() const { return m_is_backface_culling; }
|
||||
void enableBackfaceCulling(bool enable) { m_is_backface_culling = enable; }
|
||||
bool isAlphaToCoverage() const { return m_is_alpha_to_coverage; }
|
||||
void enableAlphaToCoverage(bool enable) { m_is_alpha_to_coverage = enable; }
|
||||
|
||||
void setShader(Shader* shader);
|
||||
Shader* getShader() const { return m_shader; }
|
||||
|
|
|
@ -561,17 +561,17 @@ struct PipelineInstanceImpl : public PipelineInstance
|
|||
if (m_grass_infos[i].m_mesh->getMaterial() != last_material)
|
||||
{
|
||||
m_grass_infos[i].m_mesh->getMaterial()->apply(*m_renderer, *this);
|
||||
/*shader->setUniform("shadowmap_matrix0", m_shadow_modelviewprojection[0]);
|
||||
shader->setUniform("shadowmap_matrix0", m_shadow_modelviewprojection[0]);
|
||||
shader->setUniform("shadowmap_matrix1", m_shadow_modelviewprojection[1]);
|
||||
shader->setUniform("shadowmap_matrix2", m_shadow_modelviewprojection[2]);
|
||||
shader->setUniform("shadowmap_matrix3", m_shadow_modelviewprojection[3]);
|
||||
shader->setUniform("light_dir", m_light_dir);*/
|
||||
shader->setUniform("light_dir", m_light_dir);
|
||||
last_material = m_grass_infos[i].m_mesh->getMaterial();
|
||||
}
|
||||
shader->setUniform("grass_matrices", m_grass_infos[i].m_matrices, 50); /// TODO get rid of the constant
|
||||
shader->setUniform("grass_matrices", m_grass_infos[i].m_matrices, m_grass_infos[i].m_matrix_count);
|
||||
|
||||
Mesh& mesh = *m_grass_infos[i].m_mesh;
|
||||
m_grass_infos[i].m_geometry->draw(mesh.getStart(), mesh.getCount(), *shader);
|
||||
m_grass_infos[i].m_geometry->draw(mesh.getStart(), mesh.getCount() / m_grass_infos[i].m_mesh_copy_count * m_grass_infos[i].m_matrix_count, *shader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,6 +47,8 @@ namespace Lumix
|
|||
Geometry* m_geometry;
|
||||
Mesh* m_mesh;
|
||||
const Matrix* m_matrices;
|
||||
int m_matrix_count;
|
||||
int m_mesh_copy_count;
|
||||
};
|
||||
|
||||
struct DebugLine
|
||||
|
|
|
@ -294,49 +294,6 @@ namespace Lumix
|
|||
}
|
||||
}
|
||||
|
||||
/*void Terrain::initGrass(const Vec3& camera_position)
|
||||
{
|
||||
PROFILE_FUNCTION();
|
||||
Matrix mtx = m_entity.getMatrix();
|
||||
Matrix inv_mtx = m_entity.getMatrix();
|
||||
inv_mtx.fastInverse();
|
||||
Vec3 local_camera_position = inv_mtx.multiplyPosition(camera_position);
|
||||
float cx = (int)(local_camera_position.x / (GRASS_QUAD_SIZE)) * (float)GRASS_QUAD_SIZE;
|
||||
float cz = (int)(local_camera_position.z / (GRASS_QUAD_SIZE)) * (float)GRASS_QUAD_SIZE;
|
||||
m_grass_quads_world.resize(GRASS_QUADS_HEIGHT);
|
||||
for (int j = 0; j < GRASS_QUADS_HEIGHT; ++j)
|
||||
{
|
||||
m_grass_quads_world[j].resize(GRASS_QUADS_HEIGHT);
|
||||
for (int i = 0; i < GRASS_QUADS_WIDTH; ++i)
|
||||
{
|
||||
float quad_x = cx - (i - (GRASS_QUADS_WIDTH >> 1)) * GRASS_QUAD_SIZE;
|
||||
float quad_z = cz - (j - (GRASS_QUADS_HEIGHT >> 1)) * GRASS_QUAD_SIZE;
|
||||
if (quad_x > -1 && quad_z > -1)
|
||||
{
|
||||
m_grass_quads[i][j].m_matrices.resize(31 * 31);
|
||||
m_grass_quads[i][j].m_x = quad_x;
|
||||
m_grass_quads[i][j].m_z = quad_z;
|
||||
m_grass_quads_world[j][i] = &m_grass_quads[i][j];
|
||||
srand((int)quad_x + (int)quad_z * GRASS_QUADS_WIDTH);
|
||||
int index = 0;
|
||||
for (float dx = 0; dx < GRASS_QUAD_SIZE; dx += 0.333f)
|
||||
{
|
||||
for (float dz = 0; dz < GRASS_QUAD_SIZE; dz += 0.333f)
|
||||
{
|
||||
m_grass_quads[i][j].m_matrices[index] = Matrix::IDENTITY;
|
||||
float x = quad_x + dx + (rand() % 100 - 50) / 100.0f;
|
||||
float z = quad_z + dz + (rand() % 100 - 50) / 100.0f;;
|
||||
m_grass_quads[i][j].m_matrices[index].setTranslation(Vec3(x, getHeight(x / m_xz_scale, z / m_xz_scale), z));
|
||||
m_grass_quads[i][j].m_matrices[index] = mtx * m_grass_quads[i][j].m_matrices[index];
|
||||
++index;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
m_last_camera_position = camera_position;
|
||||
}*/
|
||||
|
||||
|
||||
void Terrain::grassVertexCopyCallback(Array<uint8_t>& data)
|
||||
{
|
||||
|
@ -400,12 +357,23 @@ namespace Lumix
|
|||
updateGrass(camera_position);
|
||||
for (int i = 0; i < m_grass_quads.size(); ++i)
|
||||
{
|
||||
for (int k = 0, kc = m_grass_quads[i]->m_matrices.size() / 50; k < kc; ++k)
|
||||
for (int k = 0, kc = m_grass_quads[i]->m_matrices.size() / COPY_COUNT; k < kc; ++k)
|
||||
{
|
||||
GrassInfo& info = infos.pushEmpty();
|
||||
info.m_geometry = m_grass_geometry;
|
||||
info.m_matrices = &m_grass_quads[i]->m_matrices[50 * k];
|
||||
info.m_matrices = &m_grass_quads[i]->m_matrices[COPY_COUNT * k];
|
||||
info.m_mesh = m_grass_mesh;
|
||||
info.m_matrix_count = COPY_COUNT;
|
||||
info.m_mesh_copy_count = COPY_COUNT;
|
||||
}
|
||||
if (m_grass_quads[i]->m_matrices.size() % COPY_COUNT != 0)
|
||||
{
|
||||
GrassInfo& info = infos.pushEmpty();
|
||||
info.m_geometry = m_grass_geometry;
|
||||
info.m_matrices = &m_grass_quads[i]->m_matrices[COPY_COUNT * (m_grass_quads[i]->m_matrices.size() / COPY_COUNT)];
|
||||
info.m_mesh = m_grass_mesh;
|
||||
info.m_matrix_count = m_grass_quads[i]->m_matrices.size() % COPY_COUNT;
|
||||
info.m_mesh_copy_count = COPY_COUNT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -517,7 +485,7 @@ namespace Lumix
|
|||
}
|
||||
else
|
||||
{
|
||||
ASSERT(false); TODO("todo");
|
||||
ASSERT(false);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue