Skip to content

Commit

Permalink
Fixed invisible Oblivion models due invalid use of the cube map sampler
Browse files Browse the repository at this point in the history
  • Loading branch information
fo76utils committed Aug 21, 2024
1 parent 6ccaa0a commit 31f6659
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* Implemented the 'Startup Direction' render setting that was previously disabled.
* Skyrim and Fallout 4 shader property data is no longer moved to a sub-structure of BSLightingShaderProperty or BSEffectShaderProperty.
* Fixed the geometry of docked widgets not being restored.
* Fixed invisible Oblivion models with Mesa (and possibly other) OpenGL drivers.
* Fixed error messages on macOS about unsupported GLSL version in the shaders. Note that Starfield shading is currently disabled on macOS.

#### NifSkope-2.0.dev9-20240818

Expand Down
46 changes: 29 additions & 17 deletions src/gl/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,18 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
static bool shader_initialized = false;
static bool shader_ready = true;

static QString white = "#FFFFFFFF";
static QString black = "#FF000000";
static QString lighting = "#FF00F040";
static QString reflectivity = "#FF0A0A0A";
static QString gray = "#FF808080s";
static QString magenta = "#FFFF00FF";
static QString default_n = "#FFFF8080";
static QString default_ns = "#FFFF8080n";
static QString cube_sk = "textures/cubemaps/bleakfallscube_e.dds";
static QString cube_fo4 = "textures/shared/cubemaps/mipblur_defaultoutside1.dds";
static QString pbr_lut_sf = "#sfpbr.dds";
static const QString white = "#FFFFFFFF";
static const QString black = "#FF000000";
static const QString lighting = "#FF00F040";
static const QString reflectivity = "#FF0A0A0A";
static const QString gray = "#FF808080s";
static const QString magenta = "#FFFF00FF";
static const QString default_n = "#FFFF8080";
static const QString default_ns = "#FFFF8080n";
static const QString cube_sk = "textures/cubemaps/bleakfallscube_e.dds";
static const QString cube_fo4 = "textures/shared/cubemaps/mipblur_defaultoutside1.dds";
static const QString grayCube = "#FF555555c";
static const QString pbr_lut_sf = "#sfpbr.dds";

static const std::uint32_t defaultSFTextureSet[21] = {
0xFFFF00FFU, 0xFFFF8080U, 0xFFFFFFFFU, 0xFFC0C0C0U, 0xFF000000U, 0xFFFFFFFFU,
Expand Down Expand Up @@ -1808,6 +1809,11 @@ bool Renderer::setupProgramFO3( const NifModel * nif, Program * prog, Shape * me
}
}

GLint uniCubeMap = prog->uniformLocations[SAMP_CUBE];
if ( uniCubeMap < 0 )
hasCubeMap = false;
bool cubeBound = false;

if ( bsprop && !esp ) {
hasGlowMap = !bsprop->fileName( 2 ).isEmpty();
prog->uniSampler( bsprop, SAMP_GLOW, 2, texunit, black, clamp );
Expand All @@ -1817,18 +1823,16 @@ bool Renderer::setupProgramFO3( const NifModel * nif, Program * prog, Shape * me

// Environment Mapping (always bind cube and mask regardless of shader settings)

GLint uniCubeMap = prog->uniformLocations[SAMP_CUBE];
if ( uniCubeMap < 0 ) {
hasCubeMap = false;
} else {
if ( uniCubeMap >= 0 ) {
if ( !activateTextureUnit( texunit ) )
return false;
QString fname = bsprop->fileName( 4 );
if ( hasCubeMap && !fname.isEmpty() )
hasCubeMap = bsprop->bindCube( fname );
if ( !hasCubeMap )
bsprop->bindCube( "#FF555555c" );
bsprop->bindCube( grayCube );
fn->glUniform1i( uniCubeMap, texunit++ );
cubeBound = true;
}

hasCubeMask = !bsprop->fileName( 5 ).isEmpty();
Expand Down Expand Up @@ -1857,6 +1861,14 @@ bool Renderer::setupProgramFO3( const NifModel * nif, Program * prog, Shape * me
}
}

if ( !cubeBound && uniCubeMap >= 0 ) {
// make sure that a cube map is always bound to the cube sampler uniform to avoid invalid operation error
if ( !activateTextureUnit( texunit ) )
return false;
BSShaderLightingProperty::bindCube( scene, grayCube );
fn->glUniform1i( uniCubeMap, texunit++ );
}

if ( texprop ) {
auto t = texprop->getTexture( 0 );
if ( t && t->hasTransform ) {
Expand Down Expand Up @@ -2330,7 +2342,7 @@ void Renderer::drawSkyBox( Scene * scene )
if ( hasCubeMap )
hasCubeMap = scene->bindTexture( bsVersion < 170 ? cfg.cubeMapPathFO76 : cfg.cubeMapPathSTF );
if ( !hasCubeMap )
scene->bindTexture( "#FF555555c", false, true );
scene->bindTexture( grayCube, false, true );
fn->glUniform1i( uniCubeMap, texunit++ );

glEnable( GL_TEXTURE_CUBE_MAP_SEAMLESS );
Expand Down

0 comments on commit 31f6659

Please sign in to comment.