mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 20:53:50 +00:00
Material fixes (vertex colors, alpha)
This commit is contained in:
parent
8a887a0aef
commit
2486ec6cb9
5 changed files with 53 additions and 134 deletions
|
@ -102,6 +102,7 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const
|
|||
// Set default mipmap level (NB some APIs ignore this)
|
||||
// Mipmap generation is currently disabled because it causes issues on Intel/AMD
|
||||
//TextureManager::getSingleton().setDefaultNumMipmaps(Settings::Manager::getInt("num mipmaps", "General"));
|
||||
TextureManager::getSingleton().setDefaultNumMipmaps(0);
|
||||
|
||||
// Set default texture filtering options
|
||||
TextureFilterOptions tfo;
|
||||
|
@ -128,7 +129,6 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const
|
|||
sh::Factory::getInstance ().setShadersEnabled (Settings::Manager::getBool("shaders", "Objects"));
|
||||
|
||||
sh::Factory::getInstance ().setGlobalSetting ("fog", "true");
|
||||
sh::Factory::getInstance ().setGlobalSetting ("lighting", "true");
|
||||
sh::Factory::getInstance ().setGlobalSetting ("num_lights", Settings::Manager::getString ("num lights", "Objects"));
|
||||
sh::Factory::getInstance ().setGlobalSetting ("terrain_num_lights", Settings::Manager::getString ("num lights", "Terrain"));
|
||||
sh::Factory::getInstance ().setGlobalSetting ("simple_water", Settings::Manager::getBool("shader", "Water") ? "false" : "true");
|
||||
|
@ -329,8 +329,6 @@ void RenderingManager::update (float duration, bool paused)
|
|||
float *_playerPos = data.getPosition().pos;
|
||||
Ogre::Vector3 playerPos(_playerPos[0], _playerPos[1], _playerPos[2]);
|
||||
|
||||
Ogre::Vector3 cam = mRendering.getCamera()->getRealPosition();
|
||||
|
||||
Ogre::Vector3 orig, dest;
|
||||
mPlayer->setCameraDistance();
|
||||
if (!mPlayer->getPosition(orig, dest)) {
|
||||
|
@ -353,6 +351,8 @@ void RenderingManager::update (float duration, bool paused)
|
|||
|
||||
Ogre::ControllerManager::getSingleton().setTimeFactor(paused ? 0.f : 1.f);
|
||||
|
||||
Ogre::Vector3 cam = mRendering.getCamera()->getRealPosition();
|
||||
|
||||
applyFog(world->isUnderwater (world->getPlayer().getPlayer().getCell(), cam));
|
||||
|
||||
if(paused)
|
||||
|
|
|
@ -694,21 +694,24 @@ static Ogre::String getMaterial(const Nif::NiTriShape *shape, const Ogre::String
|
|||
sh::MaterialInstance* instance = sh::Factory::getInstance ().createMaterialInstance (matname, "openmw_objects_base");
|
||||
if(vertMode == 0 || !vertexColour)
|
||||
{
|
||||
instance->setProperty("ambient", sh::makeProperty(new sh::Vector4(ambient.x, ambient.y, ambient.z, alpha)));
|
||||
instance->setProperty("ambient", sh::makeProperty(new sh::Vector4(ambient.x, ambient.y, ambient.z, 1)));
|
||||
instance->setProperty("diffuse", sh::makeProperty(new sh::Vector4(diffuse.x, diffuse.y, diffuse.z, alpha)));
|
||||
instance->setProperty("emissive", sh::makeProperty(new sh::Vector4(emissive.x, emissive.y, emissive.z, alpha)));
|
||||
instance->setProperty("emissive", sh::makeProperty(new sh::Vector4(emissive.x, emissive.y, emissive.z, 1)));
|
||||
instance->setProperty("vertmode", sh::makeProperty(new sh::StringValue("0")));
|
||||
}
|
||||
else if(vertMode == 1)
|
||||
{
|
||||
instance->setProperty("ambient", sh::makeProperty(new sh::Vector4(ambient.x, ambient.y, ambient.z, alpha)));
|
||||
instance->setProperty("ambient", sh::makeProperty(new sh::Vector4(ambient.x, ambient.y, ambient.z, 1)));
|
||||
instance->setProperty("diffuse", sh::makeProperty(new sh::Vector4(diffuse.x, diffuse.y, diffuse.z, alpha)));
|
||||
instance->setProperty("emissive", sh::makeProperty(new sh::StringValue("vertexcolour")));
|
||||
instance->setProperty("vertmode", sh::makeProperty(new sh::StringValue("1")));
|
||||
}
|
||||
else if(vertMode == 2)
|
||||
{
|
||||
instance->setProperty("ambient", sh::makeProperty(new sh::StringValue("vertexcolour")));
|
||||
instance->setProperty("diffuse", sh::makeProperty(new sh::StringValue("vertexcolour")));
|
||||
instance->setProperty("emissive", sh::makeProperty(new sh::Vector4(emissive.x, emissive.y, emissive.z, alpha)));
|
||||
instance->setProperty("emissive", sh::makeProperty(new sh::Vector4(emissive.x, emissive.y, emissive.z, 1)));
|
||||
instance->setProperty("vertmode", sh::makeProperty(new sh::StringValue("2")));
|
||||
}
|
||||
else
|
||||
std::cerr<< "Unhandled vertex mode: "<<vertMode <<std::endl;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
material openmw_objects_base
|
||||
{
|
||||
diffuse 1.0 1.0 1.0 1.0
|
||||
specular 0.4 0.4 0.4 32
|
||||
specular 0 0 0 0
|
||||
ambient 1.0 1.0 1.0
|
||||
emissive 0.0 0.0 0.0
|
||||
has_vertex_colour false
|
||||
vertmode 0
|
||||
diffuseMap black.png
|
||||
|
||||
is_transparent false // real transparency, alpha rejection doesn't count here
|
||||
|
@ -19,7 +19,7 @@ material openmw_objects_base
|
|||
|
||||
shader_properties
|
||||
{
|
||||
has_vertex_colour $has_vertex_colour
|
||||
vertexcolor_mode $vertmode
|
||||
is_transparent $is_transparent
|
||||
}
|
||||
|
||||
|
@ -31,9 +31,6 @@ material openmw_objects_base
|
|||
alpha_rejection $alpha_rejection
|
||||
depth_write $depth_write
|
||||
|
||||
ffp_vertex_colour_ambient $has_vertex_colour
|
||||
|
||||
|
||||
texture_unit diffuseMap
|
||||
{
|
||||
direct_texture $diffuseMap
|
||||
|
@ -58,10 +55,5 @@ material openmw_objects_base
|
|||
tex_address_mode clamp
|
||||
filtering none
|
||||
}
|
||||
|
||||
texture_unit causticMap
|
||||
{
|
||||
direct_texture water_nm.png
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,9 @@
|
|||
|
||||
|
||||
#define FOG @shGlobalSettingBool(fog)
|
||||
#define LIGHTING @shGlobalSettingBool(lighting)
|
||||
|
||||
#define SHADOWS_PSSM LIGHTING && @shGlobalSettingBool(shadows_pssm)
|
||||
#define SHADOWS LIGHTING && @shGlobalSettingBool(shadows)
|
||||
#define SHADOWS_PSSM @shGlobalSettingBool(shadows_pssm)
|
||||
#define SHADOWS @shGlobalSettingBool(shadows)
|
||||
|
||||
#if SHADOWS || SHADOWS_PSSM
|
||||
#include "shadows.h"
|
||||
|
@ -18,8 +17,7 @@
|
|||
|
||||
#define UNDERWATER @shGlobalSettingBool(render_refraction)
|
||||
|
||||
|
||||
#define HAS_VERTEXCOLOR @shPropertyBool(has_vertex_colour)
|
||||
#define VERTEXCOLOR_MODE @shPropertyString(vertexcolor_mode)
|
||||
|
||||
#define VERTEX_LIGHTING 1
|
||||
|
||||
|
@ -48,16 +46,10 @@
|
|||
shOutput(float, depthPassthrough)
|
||||
#endif
|
||||
|
||||
#if LIGHTING
|
||||
shOutput(float3, normalPassthrough)
|
||||
shOutput(float3, objSpacePositionPassthrough)
|
||||
#endif
|
||||
|
||||
#if HAS_VERTEXCOLOR
|
||||
#if VERTEXCOLOR_MODE != 0
|
||||
shColourInput(float4)
|
||||
#if !VERTEX_LIGHTING
|
||||
shOutput(float4, colourPassthrough)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if VERTEX_LIGHTING
|
||||
|
@ -66,11 +58,15 @@
|
|||
shUniform(float4, lightDiffuse[@shGlobalSettingString(num_lights)]) @shAutoConstant(lightDiffuse, light_diffuse_colour_array, @shGlobalSettingString(num_lights))
|
||||
shUniform(float4, lightAttenuation[@shGlobalSettingString(num_lights)]) @shAutoConstant(lightAttenuation, light_attenuation_array, @shGlobalSettingString(num_lights))
|
||||
shUniform(float4, lightAmbient) @shAutoConstant(lightAmbient, ambient_light_colour)
|
||||
#if !HAS_VERTEXCOLOUR
|
||||
#if VERTEXCOLOR_MODE != 2
|
||||
shUniform(float4, materialAmbient) @shAutoConstant(materialAmbient, surface_ambient_colour)
|
||||
#endif
|
||||
#if VERTEXCOLOR_MODE != 2
|
||||
shUniform(float4, materialDiffuse) @shAutoConstant(materialDiffuse, surface_diffuse_colour)
|
||||
#endif
|
||||
#if VERTEXCOLOR_MODE != 1
|
||||
shUniform(float4, materialEmissive) @shAutoConstant(materialEmissive, surface_emissive_colour)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -90,16 +86,13 @@
|
|||
#endif
|
||||
|
||||
#if VERTEX_LIGHTING
|
||||
shOutput(float3, lightResult)
|
||||
shOutput(float4, lightResult)
|
||||
shOutput(float3, directionalResult)
|
||||
#endif
|
||||
SH_START_PROGRAM
|
||||
{
|
||||
shOutputPosition = shMatrixMult(wvp, shInputPosition);
|
||||
UV = uv0;
|
||||
#if LIGHTING
|
||||
normalPassthrough = normal.xyz;
|
||||
#endif
|
||||
|
||||
#ifdef NEED_DEPTH
|
||||
|
||||
|
@ -124,13 +117,7 @@
|
|||
|
||||
#endif
|
||||
|
||||
#if LIGHTING
|
||||
objSpacePositionPassthrough = shInputPosition.xyz;
|
||||
#endif
|
||||
|
||||
#if HAS_VERTEXCOLOR && !VERTEX_LIGHTING
|
||||
colourPassthrough = colour;
|
||||
#endif
|
||||
|
||||
#if SHADOWS
|
||||
lightSpacePos0 = shMatrixMult(texViewProjMatrix0, shMatrixMult(worldMatrix, shInputPosition));
|
||||
|
@ -146,28 +133,43 @@
|
|||
#if VERTEX_LIGHTING
|
||||
float3 lightDir;
|
||||
float d;
|
||||
lightResult = float3(0,0,0);
|
||||
lightResult = float4(0,0,0,1);
|
||||
@shForeach(@shGlobalSettingString(num_lights))
|
||||
lightDir = lightPosition[@shIterator].xyz - (shInputPosition.xyz * lightPosition[@shIterator].w);
|
||||
d = length(lightDir);
|
||||
lightDir = normalize(lightDir);
|
||||
|
||||
lightResult += materialDiffuse.xyz * lightDiffuse[@shIterator].xyz
|
||||
|
||||
#if VERTEXCOLOR_MODE == 2
|
||||
lightResult.xyz += colour.xyz * lightDiffuse[@shIterator].xyz
|
||||
* (1.0 / ((lightAttenuation[@shIterator].y) + (lightAttenuation[@shIterator].z * d) + (lightAttenuation[@shIterator].w * d * d)))
|
||||
* max(dot(normalize(normal.xyz), normalize(lightDir)), 0);
|
||||
#else
|
||||
lightResult.xyz += materialDiffuse.xyz * lightDiffuse[@shIterator].xyz
|
||||
* (1.0 / ((lightAttenuation[@shIterator].y) + (lightAttenuation[@shIterator].z * d) + (lightAttenuation[@shIterator].w * d * d)))
|
||||
* max(dot(normalize(normal.xyz), normalize(lightDir)), 0);
|
||||
#endif
|
||||
|
||||
#if @shIterator == 0
|
||||
directionalResult = lightResult;
|
||||
directionalResult = lightResult.xyz;
|
||||
#endif
|
||||
|
||||
@shEndForeach
|
||||
|
||||
#if HAS_VERTEXCOLOR
|
||||
// ambient vertex colour tracking, FFP behaviour
|
||||
lightResult += lightAmbient.xyz * colour.xyz + materialEmissive.xyz;
|
||||
|
||||
#else
|
||||
lightResult += lightAmbient.xyz * materialAmbient.xyz + materialEmissive.xyz;
|
||||
#if VERTEXCOLOR_MODE == 2
|
||||
lightResult.xyz += lightAmbient.xyz * colour.xyz + materialEmissive.xyz;
|
||||
lightResult.a *= colour.a;
|
||||
#endif
|
||||
#if VERTEXCOLOR_MODE == 1
|
||||
lightResult.xyz += lightAmbient.xyz * materialAmbient.xyz + colour.xyz;
|
||||
#endif
|
||||
#if VERTEXCOLOR_MODE == 0
|
||||
lightResult.xyz += lightAmbient.xyz * materialAmbient.xyz + materialEmissive.xyz;
|
||||
#endif
|
||||
|
||||
#if VERTEXCOLOR_MODE != 2
|
||||
lightResult.a *= materialDiffuse.a;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -189,35 +191,13 @@
|
|||
shInput(float, depthPassthrough)
|
||||
#endif
|
||||
|
||||
#if LIGHTING
|
||||
shInput(float3, normalPassthrough)
|
||||
shInput(float3, objSpacePositionPassthrough)
|
||||
#if !HAS_VERTEXCOLOR
|
||||
shUniform(float4, materialAmbient) @shAutoConstant(materialAmbient, surface_ambient_colour)
|
||||
#endif
|
||||
shUniform(float4, materialDiffuse) @shAutoConstant(materialDiffuse, surface_diffuse_colour)
|
||||
shUniform(float4, materialEmissive) @shAutoConstant(materialEmissive, surface_emissive_colour)
|
||||
shUniform(float4, lightAmbient) @shAutoConstant(lightAmbient, ambient_light_colour)
|
||||
#if !VERTEX_LIGHTING
|
||||
|
||||
@shForeach(@shGlobalSettingString(num_lights))
|
||||
shUniform(float4, lightPosObjSpace@shIterator) @shAutoConstant(lightPosObjSpace@shIterator, light_position_object_space, @shIterator)
|
||||
shUniform(float4, lightAttenuation@shIterator) @shAutoConstant(lightAttenuation@shIterator, light_attenuation, @shIterator)
|
||||
shUniform(float4, lightDiffuse@shIterator) @shAutoConstant(lightDiffuse@shIterator, light_diffuse_colour, @shIterator)
|
||||
@shEndForeach
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if FOG
|
||||
shUniform(float3, fogColour) @shAutoConstant(fogColour, fog_colour)
|
||||
shUniform(float4, fogParams) @shAutoConstant(fogParams, fog_params)
|
||||
#endif
|
||||
|
||||
#if HAS_VERTEXCOLOR && !VERTEX_LIGHTING
|
||||
shInput(float4, colourPassthrough)
|
||||
#endif
|
||||
|
||||
#if SHADOWS
|
||||
shInput(float4, lightSpacePos0)
|
||||
shSampler2D(shadowMap0)
|
||||
|
@ -247,7 +227,7 @@
|
|||
#endif
|
||||
|
||||
#if VERTEX_LIGHTING
|
||||
shInput(float3, lightResult)
|
||||
shInput(float4, lightResult)
|
||||
shInput(float3, directionalResult)
|
||||
#endif
|
||||
|
||||
|
@ -255,12 +235,6 @@
|
|||
{
|
||||
shOutputColour(0) = shSample(diffuseMap, UV);
|
||||
|
||||
#if LIGHTING
|
||||
float3 normal = normalize(normalPassthrough);
|
||||
float3 lightDir;
|
||||
float3 diffuse = float3(0,0,0);
|
||||
float d;
|
||||
|
||||
// shadows only for the first (directional) light
|
||||
#if SHADOWS
|
||||
float shadow = depthShadowPCF (shadowMap0, lightSpacePos0, invShadowmapSize0);
|
||||
|
@ -289,45 +263,10 @@
|
|||
float3 waterEyePos = intercept(worldPos, cameraPos.xyz - worldPos, float3(0,0,1), waterLevel);
|
||||
#endif
|
||||
|
||||
#if !VERTEX_LIGHTING
|
||||
|
||||
@shForeach(@shGlobalSettingString(num_lights))
|
||||
|
||||
/// \todo use the array auto params for lights, and use a real for-loop with auto param "light_count" iterations
|
||||
lightDir = lightPosObjSpace@shIterator.xyz - (objSpacePositionPassthrough.xyz * lightPosObjSpace@shIterator.w);
|
||||
d = length(lightDir);
|
||||
|
||||
lightDir = normalize(lightDir);
|
||||
|
||||
#if @shIterator == 0
|
||||
|
||||
#if (SHADOWS || SHADOWS_PSSM)
|
||||
diffuse += materialDiffuse.xyz * lightDiffuse@shIterator.xyz * (1.0 / ((lightAttenuation@shIterator.y) + (lightAttenuation@shIterator.z * d) + (lightAttenuation@shIterator.w * d * d))) * max(dot(normal, lightDir), 0) * shadow;
|
||||
|
||||
#else
|
||||
diffuse += materialDiffuse.xyz * lightDiffuse@shIterator.xyz * (1.0 / ((lightAttenuation@shIterator.y) + (lightAttenuation@shIterator.z * d) + (lightAttenuation@shIterator.w * d * d))) * max(dot(normal, lightDir), 0);
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
diffuse += materialDiffuse.xyz * lightDiffuse@shIterator.xyz * (1.0 / ((lightAttenuation@shIterator.y) + (lightAttenuation@shIterator.z * d) + (lightAttenuation@shIterator.w * d * d))) * max(dot(normal, lightDir), 0);
|
||||
#endif
|
||||
|
||||
@shEndForeach
|
||||
|
||||
lightResult = (ambient + diffuse + materialEmissive.xyz);
|
||||
#endif
|
||||
|
||||
#if SHADOWS
|
||||
shOutputColour(0).xyz *= (lightResult - directionalResult * (1.0-shadow));
|
||||
shOutputColour(0) *= (lightResult - float4(directionalResult * (1.0-shadow),0));
|
||||
#else
|
||||
shOutputColour(0).xyz *= (lightResult);
|
||||
#endif
|
||||
|
||||
#endif // IF LIGHTING
|
||||
|
||||
#if HAS_VERTEXCOLOR && !LIGHTING
|
||||
shOutputColour(0).xyz *= colourPassthrough.xyz;
|
||||
shOutputColour(0) *= lightResult;
|
||||
#endif
|
||||
|
||||
#if FOG
|
||||
|
|
|
@ -4,10 +4,8 @@
|
|||
|
||||
#define FOG @shGlobalSettingBool(fog)
|
||||
|
||||
#define LIGHTING @shGlobalSettingBool(lighting)
|
||||
|
||||
#define SHADOWS_PSSM LIGHTING && @shGlobalSettingBool(shadows_pssm)
|
||||
#define SHADOWS LIGHTING && @shGlobalSettingBool(shadows)
|
||||
#define SHADOWS_PSSM @shGlobalSettingBool(shadows_pssm)
|
||||
#define SHADOWS @shGlobalSettingBool(shadows)
|
||||
|
||||
#if SHADOWS || SHADOWS_PSSM
|
||||
#include "shadows.h"
|
||||
|
@ -32,9 +30,7 @@
|
|||
|
||||
@shAllocatePassthrough(2, UV)
|
||||
|
||||
#if LIGHTING
|
||||
@shAllocatePassthrough(3, worldPos)
|
||||
#endif
|
||||
|
||||
#if SHADOWS
|
||||
@shAllocatePassthrough(4, lightSpacePos0)
|
||||
|
@ -123,9 +119,7 @@
|
|||
|
||||
@shPassthroughAssign(UV, uv0);
|
||||
|
||||
#if LIGHTING
|
||||
@shPassthroughAssign(worldPos, worldPos.xyz);
|
||||
#endif
|
||||
|
||||
#if SHADOWS
|
||||
float4 lightSpacePos = shMatrixMult(texViewProjMatrix0, shMatrixMult(worldMatrix, shInputPosition));
|
||||
|
@ -176,16 +170,12 @@
|
|||
|
||||
@shPassthroughFragmentInputs
|
||||
|
||||
|
||||
#if LIGHTING
|
||||
shUniform(float4, lightAmbient) @shAutoConstant(lightAmbient, ambient_light_colour)
|
||||
@shForeach(@shGlobalSettingString(terrain_num_lights))
|
||||
shUniform(float4, lightPosObjSpace@shIterator) @shAutoConstant(lightPosObjSpace@shIterator, light_position, @shIterator)
|
||||
shUniform(float4, lightAttenuation@shIterator) @shAutoConstant(lightAttenuation@shIterator, light_attenuation, @shIterator)
|
||||
shUniform(float4, lightDiffuse@shIterator) @shAutoConstant(lightDiffuse@shIterator, light_diffuse_colour, @shIterator)
|
||||
@shEndForeach
|
||||
#endif
|
||||
|
||||
|
||||
#if SHADOWS
|
||||
shSampler2D(shadowMap0)
|
||||
|
@ -222,12 +212,10 @@
|
|||
|
||||
float2 UV = @shPassthroughReceive(UV);
|
||||
|
||||
#if LIGHTING
|
||||
float3 worldPos = @shPassthroughReceive(worldPos);
|
||||
|
||||
float3 normal = shSample(normalMap, UV).rgb * 2 - 1;
|
||||
normal = normalize(normal);
|
||||
#endif
|
||||
|
||||
|
||||
#if UNDERWATER
|
||||
|
@ -268,7 +256,6 @@
|
|||
|
||||
// Lighting
|
||||
|
||||
#if LIGHTING
|
||||
// shadows only for the first (directional) light
|
||||
#if SHADOWS
|
||||
float4 lightSpacePos0 = @shPassthroughReceive(lightSpacePos0);
|
||||
|
@ -323,8 +310,6 @@
|
|||
@shEndForeach
|
||||
|
||||
shOutputColour(0).xyz *= (lightAmbient.xyz + diffuse);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue