mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-19 02:39:19 +02:00
feat(materials): texture randomization for loads
This commit is contained in:
@@ -1286,6 +1286,7 @@ bool opengl33_renderer::Render_lowpoly( TDynamicObject *Dynamic, float const Squ
|
||||
if( Setup ) {
|
||||
|
||||
TSubModel::iInstance = reinterpret_cast<std::uintptr_t>( Dynamic ); //żeby nie robić cudzych animacji
|
||||
TSubModel::iVariantSeed = Dynamic->variant_seed();
|
||||
glm::dvec3 const originoffset{ Dynamic->vPosition - m_renderpass.pass_camera.position() };
|
||||
|
||||
Dynamic->ABuLittleUpdate( Squaredistance ); // ustawianie zmiennych submodeli dla wspólnego modelu
|
||||
@@ -2262,14 +2263,21 @@ void opengl33_renderer::Bind_Material( material_handle const Material, TSubModel
|
||||
else
|
||||
model_ubs.alpha_mult = 1.0f;
|
||||
|
||||
// materials which declare texture variants provide a different texture set per model instance,
|
||||
// picked from the seed of the rendered instance and the variant group of the submodel
|
||||
auto const &materialtextures{
|
||||
material.texture_variants.empty() ?
|
||||
material.textures :
|
||||
material.GetTextures(TSubModel::VariantId(sm))};
|
||||
|
||||
if (GLAD_GL_ARB_multi_bind)
|
||||
{
|
||||
GLuint lastdiff = 0;
|
||||
size_t i;
|
||||
for (i = 0; i < gl::MAX_TEXTURES; i++)
|
||||
if (material.textures[i] != null_handle)
|
||||
if (materialtextures[i] != null_handle)
|
||||
{
|
||||
opengl_texture &tex = m_textures.mark_as_used(material.textures[i]);
|
||||
opengl_texture &tex = m_textures.mark_as_used(materialtextures[i]);
|
||||
tex.create();
|
||||
if (opengl_texture::units[i] != tex.id)
|
||||
{
|
||||
@@ -2286,7 +2294,7 @@ void opengl33_renderer::Bind_Material( material_handle const Material, TSubModel
|
||||
else
|
||||
{
|
||||
size_t unit = 0;
|
||||
for (auto &tex : material.textures)
|
||||
for (auto &tex : materialtextures)
|
||||
{
|
||||
if (tex == null_handle)
|
||||
break;
|
||||
@@ -3351,6 +3359,7 @@ bool opengl33_renderer::Render(TDynamicObject *Dynamic)
|
||||
|
||||
// setup
|
||||
TSubModel::iInstance = reinterpret_cast<std::uintptr_t>(Dynamic); //żeby nie robić cudzych animacji
|
||||
TSubModel::iVariantSeed = Dynamic->variant_seed();
|
||||
glm::dvec3 const originoffset = Dynamic->vPosition - m_renderpass.pass_camera.position();
|
||||
// lod visibility ranges are defined for base (x 1.0) viewing distance. for render we adjust them for actual range multiplier and zoom
|
||||
float squaredistance;
|
||||
@@ -3518,10 +3527,12 @@ bool opengl33_renderer::Render_cab(TDynamicObject const *Dynamic, float const Li
|
||||
{
|
||||
|
||||
TSubModel::iInstance = 0;
|
||||
TSubModel::iVariantSeed = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
TSubModel::iInstance = reinterpret_cast<std::uintptr_t>(Dynamic);
|
||||
TSubModel::iVariantSeed = Dynamic->variant_seed();
|
||||
|
||||
if ((true == FreeFlyModeFlag) || (false == Dynamic->bDisplayCab) || (Dynamic->mdKabina == Dynamic->mdModel))
|
||||
{
|
||||
@@ -4445,6 +4456,7 @@ bool opengl33_renderer::Render_Alpha(TDynamicObject *Dynamic)
|
||||
|
||||
// setup
|
||||
TSubModel::iInstance = (size_t)Dynamic; //żeby nie robić cudzych animacji
|
||||
TSubModel::iVariantSeed = Dynamic->variant_seed();
|
||||
glm::dvec3 const originoffset = Dynamic->vPosition - m_renderpass.pass_camera.position();
|
||||
// lod visibility ranges are defined for base (x 1.0) viewing distance. for render we adjust them for actual range multiplier and zoom
|
||||
float squaredistance;
|
||||
|
||||
@@ -801,6 +801,7 @@ bool opengl_renderer::Render_lowpoly( TDynamicObject *Dynamic, float const Squar
|
||||
if( Setup ) {
|
||||
|
||||
TSubModel::iInstance = reinterpret_cast<std::uintptr_t>( Dynamic ); //żeby nie robić cudzych animacji
|
||||
TSubModel::iVariantSeed = Dynamic->variant_seed();
|
||||
Dynamic->ABuLittleUpdate( Squaredistance ); // ustawianie zmiennych submodeli dla wspólnego modelu
|
||||
::glPushMatrix();
|
||||
|
||||
@@ -1759,10 +1760,17 @@ opengl_renderer::Bind_Material( material_handle const Material, TSubModel const
|
||||
return;
|
||||
}
|
||||
|
||||
// materials which declare texture variants provide a different texture set per model instance,
|
||||
// picked from the seed of the rendered instance and the variant group of the submodel
|
||||
auto const &materialtextures {
|
||||
material.texture_variants.empty() ?
|
||||
material.textures :
|
||||
material.GetTextures( TSubModel::VariantId( sm ) ) };
|
||||
|
||||
if( false == Global.BasicRenderer ) {
|
||||
m_textures.bind( m_normaltextureunit, material.textures[1] );
|
||||
m_textures.bind( m_normaltextureunit, materialtextures[1] );
|
||||
}
|
||||
m_textures.bind( m_diffusetextureunit, material.textures[0] );
|
||||
m_textures.bind( m_diffusetextureunit, materialtextures[0] );
|
||||
}
|
||||
else {
|
||||
// null material, unbind all textures
|
||||
@@ -2475,6 +2483,7 @@ opengl_renderer::Render( TDynamicObject *Dynamic ) {
|
||||
|
||||
// setup
|
||||
TSubModel::iInstance = reinterpret_cast<std::uintptr_t>( Dynamic ); //żeby nie robić cudzych animacji
|
||||
TSubModel::iVariantSeed = Dynamic->variant_seed();
|
||||
Dynamic->ABuLittleUpdate( squaredistance ); // ustawianie zmiennych submodeli dla wspólnego modelu
|
||||
::glPushMatrix();
|
||||
|
||||
@@ -2574,10 +2583,12 @@ opengl_renderer::Render_cab( TDynamicObject const *Dynamic, float const Lightlev
|
||||
if( Dynamic == nullptr ) {
|
||||
|
||||
TSubModel::iInstance = 0;
|
||||
TSubModel::iVariantSeed = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
TSubModel::iInstance = reinterpret_cast<std::uintptr_t>( Dynamic );
|
||||
TSubModel::iVariantSeed = Dynamic->variant_seed();
|
||||
|
||||
if( ( true == FreeFlyModeFlag )
|
||||
|| ( false == Dynamic->bDisplayCab )
|
||||
@@ -2866,11 +2877,11 @@ opengl_renderer::Render( TSubModel *Submodel ) {
|
||||
// material configuration:
|
||||
// textures...
|
||||
if( Submodel->m_material < 0 ) { // zmienialne skóry
|
||||
Bind_Material( Submodel->ReplacableSkinId[ -Submodel->m_material ] );
|
||||
Bind_Material( Submodel->ReplacableSkinId[ -Submodel->m_material ], Submodel );
|
||||
}
|
||||
else {
|
||||
// również 0
|
||||
Bind_Material( Submodel->m_material );
|
||||
Bind_Material( Submodel->m_material, Submodel );
|
||||
}
|
||||
// main draw call
|
||||
m_geometry.draw( Submodel->m_geometry.handle );
|
||||
@@ -2884,11 +2895,11 @@ opengl_renderer::Render( TSubModel *Submodel ) {
|
||||
::glColor3fv( glm::value_ptr( pick_color( m_pickcontrolsitems.size() ) ) );
|
||||
// textures...
|
||||
if( Submodel->m_material < 0 ) { // zmienialne skóry
|
||||
Bind_Material( Submodel->ReplacableSkinId[ -Submodel->m_material ] );
|
||||
Bind_Material( Submodel->ReplacableSkinId[ -Submodel->m_material ], Submodel );
|
||||
}
|
||||
else {
|
||||
// również 0
|
||||
Bind_Material( Submodel->m_material );
|
||||
Bind_Material( Submodel->m_material, Submodel );
|
||||
}
|
||||
// main draw call
|
||||
m_geometry.draw( Submodel->m_geometry.handle );
|
||||
@@ -3657,6 +3668,7 @@ opengl_renderer::Render_Alpha( TDynamicObject *Dynamic ) {
|
||||
|
||||
// setup
|
||||
TSubModel::iInstance = ( size_t )Dynamic; //żeby nie robić cudzych animacji
|
||||
TSubModel::iVariantSeed = Dynamic->variant_seed();
|
||||
glm::dvec3 const originoffset = Dynamic->vPosition - m_renderpass.camera.position();
|
||||
// lod visibility ranges are defined for base (x 1.0) viewing distance. for render we adjust them for actual range multiplier and zoom
|
||||
float squaredistance;
|
||||
@@ -3909,11 +3921,11 @@ opengl_renderer::Render_Alpha( TSubModel *Submodel ) {
|
||||
// material configuration:
|
||||
// textures...
|
||||
if( Submodel->m_material < 0 ) { // zmienialne skóry
|
||||
Bind_Material( Submodel->ReplacableSkinId[ -Submodel->m_material ] );
|
||||
Bind_Material( Submodel->ReplacableSkinId[ -Submodel->m_material ], Submodel );
|
||||
}
|
||||
else {
|
||||
// również 0
|
||||
Bind_Material( Submodel->m_material );
|
||||
Bind_Material( Submodel->m_material, Submodel );
|
||||
}
|
||||
// main draw call
|
||||
m_geometry.draw( Submodel->m_geometry.handle );
|
||||
|
||||
Reference in New Issue
Block a user