mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-29 16:36:43 +00:00
Merge remote-tracking branch 'scrawl/graphics'
This commit is contained in:
commit
a359ba6a2f
4 changed files with 111 additions and 10 deletions
|
@ -275,17 +275,23 @@ void Objects::insertLight (const MWWorld::Ptr& ptr, Ogre::Entity* skelBase, Ogre
|
||||||
|
|
||||||
bool quadratic = lightOutQuadInLin() ? !info.interior : lightQuadratic();
|
bool quadratic = lightOutQuadInLin() ? !info.interior : lightQuadratic();
|
||||||
|
|
||||||
|
// with the standard 1 / (c + d*l + d*d*q) equation the attenuation factor never becomes zero,
|
||||||
|
// so we ignore lights if their attenuation falls below this factor.
|
||||||
|
const float threshold = 0.03;
|
||||||
|
|
||||||
if (!quadratic)
|
if (!quadratic)
|
||||||
{
|
{
|
||||||
float r = radius * lightLinearRadiusMult();
|
float r = radius * lightLinearRadiusMult();
|
||||||
float attenuation = lightLinearValue() / r;
|
float attenuation = lightLinearValue() / r;
|
||||||
light->setAttenuation(r*10, 0, attenuation, 0);
|
float activationRange = 1 / (threshold * attenuation);
|
||||||
|
light->setAttenuation(activationRange, 0, attenuation, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
float r = radius * lightQuadraticRadiusMult();
|
float r = radius * lightQuadraticRadiusMult();
|
||||||
float attenuation = lightQuadraticValue() / std::pow(r, 2);
|
float attenuation = lightQuadraticValue() / std::pow(r, 2);
|
||||||
light->setAttenuation(r*10, 0, 0, attenuation);
|
float activationRange = std::sqrt(1 / (threshold * attenuation));
|
||||||
|
light->setAttenuation(activationRange, 0, 0, attenuation);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there's an AttachLight bone, attach the light to that, otherwise attach it to the base scene node
|
// If there's an AttachLight bone, attach the light to that, otherwise attach it to the base scene node
|
||||||
|
|
|
@ -54,10 +54,11 @@
|
||||||
|
|
||||||
#if VERTEX_LIGHTING
|
#if VERTEX_LIGHTING
|
||||||
shUniform(float, lightCount) @shAutoConstant(lightCount, light_count)
|
shUniform(float, lightCount) @shAutoConstant(lightCount, light_count)
|
||||||
shUniform(float4, lightPosition[@shGlobalSettingString(num_lights)]) @shAutoConstant(lightPosition, light_position_object_space_array, @shGlobalSettingString(num_lights))
|
shUniform(float4, lightPosition[@shGlobalSettingString(num_lights)]) @shAutoConstant(lightPosition, light_position_view_space_array, @shGlobalSettingString(num_lights))
|
||||||
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)
|
||||||
|
shUniform(float4x4, worldView) @shAutoConstant(worldView, worldview_matrix)
|
||||||
#if VERTEXCOLOR_MODE != 2
|
#if VERTEXCOLOR_MODE != 2
|
||||||
shUniform(float4, materialAmbient) @shAutoConstant(materialAmbient, surface_ambient_colour)
|
shUniform(float4, materialAmbient) @shAutoConstant(materialAmbient, surface_ambient_colour)
|
||||||
#endif
|
#endif
|
||||||
|
@ -131,23 +132,26 @@
|
||||||
|
|
||||||
|
|
||||||
#if VERTEX_LIGHTING
|
#if VERTEX_LIGHTING
|
||||||
|
float3 viewPos = shMatrixMult(worldView, shInputPosition).xyz;
|
||||||
|
float3 viewNormal = normalize(shMatrixMult(worldView, float4(normal.xyz, 0)).xyz);
|
||||||
|
|
||||||
float3 lightDir;
|
float3 lightDir;
|
||||||
float d;
|
float d;
|
||||||
lightResult = float4(0,0,0,1);
|
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 - (viewPos * lightPosition[@shIterator].w);
|
||||||
d = length(lightDir);
|
d = length(lightDir);
|
||||||
lightDir = normalize(lightDir);
|
lightDir = normalize(lightDir);
|
||||||
|
|
||||||
|
|
||||||
#if VERTEXCOLOR_MODE == 2
|
#if VERTEXCOLOR_MODE == 2
|
||||||
lightResult.xyz += colour.xyz * lightDiffuse[@shIterator].xyz
|
lightResult.xyz += colour.xyz * lightDiffuse[@shIterator].xyz
|
||||||
* (1.0 / ((lightAttenuation[@shIterator].y) + (lightAttenuation[@shIterator].z * d) + (lightAttenuation[@shIterator].w * d * d)))
|
* shSaturate(1.0 / ((lightAttenuation[@shIterator].y) + (lightAttenuation[@shIterator].z * d) + (lightAttenuation[@shIterator].w * d * d)))
|
||||||
* max(dot(normalize(normal.xyz), normalize(lightDir)), 0);
|
* max(dot(viewNormal.xyz, lightDir), 0);
|
||||||
#else
|
#else
|
||||||
lightResult.xyz += materialDiffuse.xyz * lightDiffuse[@shIterator].xyz
|
lightResult.xyz += materialDiffuse.xyz * lightDiffuse[@shIterator].xyz
|
||||||
* (1.0 / ((lightAttenuation[@shIterator].y) + (lightAttenuation[@shIterator].z * d) + (lightAttenuation[@shIterator].w * d * d)))
|
* shSaturate(1.0 / ((lightAttenuation[@shIterator].y) + (lightAttenuation[@shIterator].z * d) + (lightAttenuation[@shIterator].w * d * d)))
|
||||||
* max(dot(normalize(normal.xyz), normalize(lightDir)), 0);
|
* max(dot(viewNormal.xyz, lightDir), 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if @shIterator == 0
|
#if @shIterator == 0
|
||||||
|
|
|
@ -54,5 +54,24 @@ material Water
|
||||||
scale 0.1 0.1
|
scale 0.1 0.1
|
||||||
alpha_op_ex source1 src_manual src_current 0.7
|
alpha_op_ex source1 src_manual src_current 0.7
|
||||||
}
|
}
|
||||||
|
|
||||||
|
texture_unit shadowMap0
|
||||||
|
{
|
||||||
|
content_type shadow
|
||||||
|
tex_address_mode clamp
|
||||||
|
filtering none
|
||||||
|
}
|
||||||
|
texture_unit shadowMap1
|
||||||
|
{
|
||||||
|
content_type shadow
|
||||||
|
tex_address_mode clamp
|
||||||
|
filtering none
|
||||||
|
}
|
||||||
|
texture_unit shadowMap2
|
||||||
|
{
|
||||||
|
content_type shadow
|
||||||
|
tex_address_mode clamp
|
||||||
|
filtering none
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,13 @@
|
||||||
|
|
||||||
// Inspired by Blender GLSL Water by martinsh ( http://devlog-martinsh.blogspot.de/2012/07/waterundewater-shader-wip.html )
|
// Inspired by Blender GLSL Water by martinsh ( http://devlog-martinsh.blogspot.de/2012/07/waterundewater-shader-wip.html )
|
||||||
|
|
||||||
|
#define SHADOWS_PSSM @shGlobalSettingBool(shadows_pssm)
|
||||||
|
#define SHADOWS @shGlobalSettingBool(shadows)
|
||||||
|
|
||||||
|
#if SHADOWS || SHADOWS_PSSM
|
||||||
|
#include "shadows.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define RIPPLES 1
|
#define RIPPLES 1
|
||||||
#define REFRACTION @shGlobalSettingBool(refraction)
|
#define REFRACTION @shGlobalSettingBool(refraction)
|
||||||
|
|
||||||
|
@ -64,6 +71,23 @@
|
||||||
shOutput(float4, position)
|
shOutput(float4, position)
|
||||||
shOutput(float, depthPassthrough)
|
shOutput(float, depthPassthrough)
|
||||||
|
|
||||||
|
|
||||||
|
#if SHADOWS
|
||||||
|
shOutput(float4, lightSpacePos0)
|
||||||
|
shUniform(float4x4, texViewProjMatrix0) @shAutoConstant(texViewProjMatrix0, texture_viewproj_matrix)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if SHADOWS_PSSM
|
||||||
|
@shForeach(3)
|
||||||
|
shOutput(float4, lightSpacePos@shIterator)
|
||||||
|
shUniform(float4x4, texViewProjMatrix@shIterator) @shAutoConstant(texViewProjMatrix@shIterator, texture_viewproj_matrix, @shIterator)
|
||||||
|
@shEndForeach
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if SHADOWS || SHADOWS_PSSM
|
||||||
|
shUniform(float4x4, worldMatrix) @shAutoConstant(worldMatrix, world_matrix)
|
||||||
|
#endif
|
||||||
|
|
||||||
SH_START_PROGRAM
|
SH_START_PROGRAM
|
||||||
{
|
{
|
||||||
shOutputPosition = shMatrixMult(wvp, shInputPosition);
|
shOutputPosition = shMatrixMult(wvp, shInputPosition);
|
||||||
|
@ -88,6 +112,17 @@
|
||||||
position = shInputPosition;
|
position = shInputPosition;
|
||||||
|
|
||||||
depthPassthrough = shOutputPosition.z;
|
depthPassthrough = shOutputPosition.z;
|
||||||
|
|
||||||
|
|
||||||
|
#if SHADOWS
|
||||||
|
lightSpacePos0 = shMatrixMult(texViewProjMatrix0, shMatrixMult(worldMatrix, shInputPosition));
|
||||||
|
#endif
|
||||||
|
#if SHADOWS_PSSM
|
||||||
|
float4 wPos = shMatrixMult(worldMatrix, shInputPosition);
|
||||||
|
@shForeach(3)
|
||||||
|
lightSpacePos@shIterator = shMatrixMult(texViewProjMatrix@shIterator, wPos);
|
||||||
|
@shEndForeach
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
@ -188,8 +223,45 @@
|
||||||
shUniform(float4, cameraPos) @shAutoConstant(cameraPos, camera_position_object_space)
|
shUniform(float4, cameraPos) @shAutoConstant(cameraPos, camera_position_object_space)
|
||||||
|
|
||||||
|
|
||||||
|
#if SHADOWS
|
||||||
|
shInput(float4, lightSpacePos0)
|
||||||
|
shSampler2D(shadowMap0)
|
||||||
|
shUniform(float2, invShadowmapSize0) @shAutoConstant(invShadowmapSize0, inverse_texture_size, 1)
|
||||||
|
#endif
|
||||||
|
#if SHADOWS_PSSM
|
||||||
|
@shForeach(3)
|
||||||
|
shInput(float4, lightSpacePos@shIterator)
|
||||||
|
shSampler2D(shadowMap@shIterator)
|
||||||
|
shUniform(float2, invShadowmapSize@shIterator) @shAutoConstant(invShadowmapSize@shIterator, inverse_texture_size, @shIterator(1))
|
||||||
|
@shEndForeach
|
||||||
|
shUniform(float3, pssmSplitPoints) @shSharedParameter(pssmSplitPoints)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if SHADOWS || SHADOWS_PSSM
|
||||||
|
shUniform(float4, shadowFar_fadeStart) @shSharedParameter(shadowFar_fadeStart)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
SH_START_PROGRAM
|
SH_START_PROGRAM
|
||||||
{
|
{
|
||||||
|
#if SHADOWS
|
||||||
|
float shadow = depthShadowPCF (shadowMap0, lightSpacePos0, invShadowmapSize0);
|
||||||
|
#endif
|
||||||
|
#if SHADOWS_PSSM
|
||||||
|
float shadow = pssmDepthShadow (lightSpacePos0, invShadowmapSize0, shadowMap0, lightSpacePos1, invShadowmapSize1, shadowMap1, lightSpacePos2, invShadowmapSize2, shadowMap2, depthPassthrough, pssmSplitPoints);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if SHADOWS || SHADOWS_PSSM
|
||||||
|
float fadeRange = shadowFar_fadeStart.x - shadowFar_fadeStart.y;
|
||||||
|
float fade = 1-((depthPassthrough - shadowFar_fadeStart.y) / fadeRange);
|
||||||
|
shadow = (depthPassthrough > shadowFar_fadeStart.x) ? 1.0 : ((depthPassthrough > shadowFar_fadeStart.y) ? 1.0-((1.0-shadow)*fade) : shadow);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !SHADOWS && !SHADOWS_PSSM
|
||||||
|
float shadow = 1.0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
float2 screenCoords = screenCoordsPassthrough.xy / screenCoordsPassthrough.z;
|
float2 screenCoords = screenCoordsPassthrough.xy / screenCoordsPassthrough.z;
|
||||||
screenCoords.y = (1-shSaturate(renderTargetFlipping))+renderTargetFlipping*screenCoords.y;
|
screenCoords.y = (1-shSaturate(renderTargetFlipping))+renderTargetFlipping*screenCoords.y;
|
||||||
|
|
||||||
|
@ -244,7 +316,7 @@
|
||||||
float3 llR = reflect(lVec, pNormal);
|
float3 llR = reflect(lVec, pNormal);
|
||||||
|
|
||||||
float s = shSaturate(dot(lR, vVec)*2.0-1.2);
|
float s = shSaturate(dot(lR, vVec)*2.0-1.2);
|
||||||
float lightScatter = shSaturate(dot(-lVec,lNormal)*0.7+0.3) * s * SCATTER_AMOUNT * waterSunFade_sunHeight.x * shSaturate(1.0-exp(-waterSunFade_sunHeight.y));
|
float lightScatter = shadow * shSaturate(dot(-lVec,lNormal)*0.7+0.3) * s * SCATTER_AMOUNT * waterSunFade_sunHeight.x * shSaturate(1.0-exp(-waterSunFade_sunHeight.y));
|
||||||
float3 scatterColour = shLerp(float3(SCATTER_COLOUR)*float3(1.0,0.4,0.0), SCATTER_COLOUR, shSaturate(1.0-exp(-waterSunFade_sunHeight.y*SUN_EXT)));
|
float3 scatterColour = shLerp(float3(SCATTER_COLOUR)*float3(1.0,0.4,0.0), SCATTER_COLOUR, shSaturate(1.0-exp(-waterSunFade_sunHeight.y*SUN_EXT)));
|
||||||
|
|
||||||
// fresnel
|
// fresnel
|
||||||
|
@ -267,7 +339,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// specular
|
// specular
|
||||||
float specular = pow(max(dot(R, lVec), 0.0),SPEC_HARDNESS);
|
float specular = pow(max(dot(R, lVec), 0.0),SPEC_HARDNESS) * shadow;
|
||||||
|
|
||||||
#if REFRACTION
|
#if REFRACTION
|
||||||
shOutputColour(0).xyz = shLerp( shLerp(refraction, scatterColour, lightScatter), reflection, fresnel) + specular * sunSpecular.xyz;
|
shOutputColour(0).xyz = shLerp( shLerp(refraction, scatterColour, lightScatter), reflection, fresnel) + specular * sunSpecular.xyz;
|
||||||
|
|
Loading…
Reference in a new issue