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