Add AnyOldName3's osgshadow-test commits up to Sep 21 while resolving conflicts

# Conflicts:
#	CMakeLists.txt
experimental
David Cernat 7 years ago
commit 195bd88ac0

@ -761,7 +761,7 @@ if [ -z $CI ]; then
echo " settings-default.cfg"
cp settings-default.cfg $BUILD_CONFIG/settings-default.cfg
echo " resources/"
cp -r resources $BUILD_CONFIG/resources
cp -r resources $BUILD_CONFIG
echo
fi

@ -220,7 +220,7 @@ endif()
IF(BUILD_OPENMW OR BUILD_OPENCS)
find_package(OpenSceneGraph 3.3.4 REQUIRED osgDB osgViewer osgText osgGA osgParticle osgUtil osgFX)
find_package(OpenSceneGraph 3.3.4 REQUIRED osgDB osgViewer osgText osgGA osgAnimation osgParticle osgUtil osgFX osgShadow)
include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS})
set(USED_OSG_PLUGINS

@ -159,6 +159,7 @@ target_link_libraries(tes3mp
${OSGDB_LIBRARIES}
${OSGVIEWER_LIBRARIES}
${OSGGA_LIBRARIES}
${OSGSHADOW_LIBRARIES}
${Boost_SYSTEM_LIBRARY}
${Boost_THREAD_LIBRARY}
${Boost_FILESYSTEM_LIBRARY}

@ -13,6 +13,13 @@
#include <osg/UserDataContainer>
#include <osg/ComputeBoundsVisitor>
#include <osgShadow/ShadowedScene>
#include <osgShadow/ViewDependentShadowMap>
#include <osgShadow/ShadowMap>
#include <osgShadow/ParallelSplitShadowMap>
#include <osgShadow/ShadowMap>
#include <osgShadow/LightSpacePerspectiveShadowMap>
#include <osgUtil/LineSegmentIntersector>
#include <osgUtil/IncrementalCompileOperation>
@ -183,6 +190,7 @@ namespace MWRender
, mFieldOfViewOverridden(false)
{
resourceSystem->getSceneManager()->setParticleSystemMask(MWRender::Mask_ParticleSystem);
resourceSystem->getSceneManager()->setShaderPath(resourcePath + "/shaders");
resourceSystem->getSceneManager()->setForceShaders(Settings::Manager::getBool("force shaders", "Shaders"));
resourceSystem->getSceneManager()->setClampLighting(Settings::Manager::getBool("clamp lighting", "Shaders"));
@ -198,7 +206,42 @@ namespace MWRender
mSceneRoot = sceneRoot;
sceneRoot->setStartLight(1);
mRootNode->addChild(sceneRoot);
osg::ref_ptr<osgShadow::ShadowedScene> shadowedScene (new osgShadow::ShadowedScene);
osgShadow::ShadowSettings* settings = shadowedScene->getShadowSettings();
settings->setLightNum(0);
settings->setCastsShadowTraversalMask(Mask_Scene|Mask_Actor|Mask_Player);
settings->setReceivesShadowTraversalMask(~0u);
//settings->setShadowMapProjectionHint(osgShadow::ShadowSettings::PERSPECTIVE_SHADOW_MAP);
//settings->setBaseShadowTextureUnit(1);
//settings->setMinimumShadowMapNearFarRatio(0);
//settings->setNumShadowMapsPerLight(1);
//settings->setShadowMapProjectionHint(osgShadow::ShadowSettings::ORTHOGRAPHIC_SHADOW_MAP);
//settings->setMultipleShadowMapHint(osgShadow::ShadowSettings::PARALLEL_SPLIT); // ignored
//settings->setComputeNearFarModeOverride(osg::CullSettings::COMPUTE_NEAR_FAR_USING_PRIMITIVES);
//settings->setDebugDraw(true);
//settings->setPerspectiveShadowMapCutOffAngle(0);
//settings->setShaderHint(osgShadow::ShadowSettings::PROVIDE_VERTEX_AND_FRAGMENT_SHADER);
int mapres = 2048;
settings->setTextureSize(osg::Vec2s(mapres,mapres));
osgShadow::MinimalShadowMap* tech = new osgShadow::LightSpacePerspectiveShadowMapDB();
shadowedScene->setShadowTechnique(tech);
tech->setMaxFarPlane(0);
tech->setTextureSize(osg::Vec2s(mapres, mapres));
tech->setShadowTextureCoordIndex(1);
tech->setShadowTextureUnit(1);
tech->setBaseTextureCoordIndex(0);
tech->setBaseTextureUnit(0);
//mRootNode->addChild(sceneRoot);
shadowedScene->addChild(sceneRoot);
mRootNode->addChild(shadowedScene);
mPathgrid.reset(new Pathgrid(mRootNode));
@ -229,7 +272,7 @@ namespace MWRender
mViewer->setLightingMode(osgViewer::View::NO_LIGHT);
osg::ref_ptr<osg::LightSource> source = new osg::LightSource;
source->setNodeMask(Mask_Lighting);
//source->setNodeMask(Mask_Lighting);
mSunLight = new osg::Light;
source->setLight(mSunLight);
mSunLight->setDiffuse(osg::Vec4f(0,0,0,1));
@ -273,7 +316,8 @@ namespace MWRender
mViewer->getCamera()->setComputeNearFarMode(osg::Camera::DO_NOT_COMPUTE_NEAR_FAR);
mViewer->getCamera()->setCullingMode(cullingMode);
mViewer->getCamera()->setCullMask(~(Mask_UpdateVisitor|Mask_SimpleWater));
//mViewer->getCamera()->setCullMask(~(Mask_UpdateVisitor|Mask_SimpleWater));
mViewer->getCamera()->setCullMask(~(Mask_Lighting));
mNearClip = Settings::Manager::getFloat("near clip", "Camera");
mViewDistance = Settings::Manager::getFloat("viewing distance", "Camera");

@ -51,7 +51,9 @@ namespace MWRender
Mask_PreCompile = (1<<16),
// Set on a camera's cull mask to enable the LightManager
Mask_Lighting = (1<<17)
Mask_Lighting = (1<<17),
Mask_CastsShadows = (1<<18)
};
}

@ -1,10 +1,25 @@
#define MAX_LIGHTS 8
vec4 doLighting(vec3 viewPos, vec3 viewNormal, vec4 vertexColor)
void perLight(out vec3 ambientOut, out vec3 diffuseOut, int lightIndex, vec3 viewPos, vec3 viewNormal, vec4 diffuse, vec3 ambient)
{
vec3 lightDir;
float d;
float lightDistance;
lightDir = gl_LightSource[lightIndex].position.xyz - (viewPos.xyz * gl_LightSource[lightIndex].position.w);
lightDistance = length(lightDir);
lightDir = normalize(lightDir);
float illumination = clamp(1.0 / (gl_LightSource[lightIndex].constantAttenuation + gl_LightSource[lightIndex].linearAttenuation * lightDistance + gl_LightSource[lightIndex].quadraticAttenuation * lightDistance * lightDistance), 0.0, 1.0);
ambientOut = ambient * gl_LightSource[lightIndex].ambient.xyz * illumination;
diffuseOut = diffuse.xyz * gl_LightSource[lightIndex].diffuse.xyz * max(dot(viewNormal.xyz, lightDir), 0.0) * illumination;
}
#ifdef FRAGMENT
vec4 doLighting(vec3 viewPos, vec3 viewNormal, vec4 vertexColor, float shadowing)
#else
vec4 doLighting(vec3 viewPos, vec3 viewNormal, vec4 vertexColor, out vec3 shadowDiffuse)
#endif
{
#if @colorMode == 3
vec4 diffuse = gl_FrontMaterial.diffuse;
vec3 ambient = vertexColor.xyz;
@ -17,13 +32,18 @@ vec4 doLighting(vec3 viewPos, vec3 viewNormal, vec4 vertexColor)
#endif
vec4 lightResult = vec4(0.0, 0.0, 0.0, diffuse.a);
for (int i=0; i<MAX_LIGHTS; ++i)
vec3 diffuseLight, ambientLight;
perLight(ambientLight, diffuseLight, 0, viewPos, viewNormal, diffuse, ambient);
#ifdef FRAGMENT
lightResult.xyz += ambientLight + diffuseLight * shadowing;
#else
shadowDiffuse = diffuseLight;
lightResult.xyz += ambientLight;
#endif
for (int i=1; i<MAX_LIGHTS; ++i)
{
lightDir = gl_LightSource[i].position.xyz - (viewPos.xyz * gl_LightSource[i].position.w);
d = length(lightDir);
lightDir = normalize(lightDir);
lightResult.xyz += (ambient * gl_LightSource[i].ambient.xyz + diffuse.xyz * gl_LightSource[i].diffuse.xyz * max(dot(viewNormal.xyz, lightDir), 0.0)) * clamp(1.0 / (gl_LightSource[i].constantAttenuation + gl_LightSource[i].linearAttenuation * d + gl_LightSource[i].quadraticAttenuation * d * d), 0.0, 1.0);
perLight(ambientLight, diffuseLight, i, viewPos, viewNormal, diffuse, ambient);
lightResult.xyz += ambientLight + diffuseLight;
}
lightResult.xyz += gl_LightModel.ambient.xyz * ambient;

@ -1,5 +1,7 @@
#version 120
#define FRAGMENT
#if @diffuseMap
uniform sampler2D diffuseMap;
varying vec2 diffuseMapUV;
@ -48,12 +50,16 @@ varying float depth;
#if !PER_PIXEL_LIGHTING
varying vec4 lighting;
varying vec3 shadowDiffuseLighting;
#else
varying vec4 passColor;
#endif
varying vec3 passViewPos;
varying vec3 passNormal;
uniform sampler2DShadow shadowTexture;
varying vec4 shadowSpaceCoords;
#include "lighting.glsl"
#include "parallax.glsl"
@ -112,10 +118,12 @@ void main()
gl_FragData[0].xyz = mix(gl_FragData[0].xyz, decalTex.xyz, decalTex.a);
#endif
float shadowing = shadow2DProj(shadowTexture, shadowSpaceCoords).r;
#if !PER_PIXEL_LIGHTING
gl_FragData[0] *= lighting;
gl_FragData[0] *= lighting + vec4(shadowDiffuseLighting * shadowing, 0);
#else
gl_FragData[0] *= doLighting(passViewPos, normalize(viewNormal), passColor);
gl_FragData[0] *= doLighting(passViewPos, normalize(viewNormal), passColor, shadowing);
#endif
#if @emissiveMap
@ -147,7 +155,7 @@ void main()
vec3 matSpec = gl_FrontMaterial.specular.xyz;
#endif
gl_FragData[0].xyz += getSpecular(normalize(viewNormal), normalize(passViewPos.xyz), shininess, matSpec);
gl_FragData[0].xyz += getSpecular(normalize(viewNormal), normalize(passViewPos.xyz), shininess, matSpec) * shadowing;
float fogValue = clamp((depth - gl_Fog.start) * gl_Fog.scale, 0.0, 1.0);
gl_FragData[0].xyz = mix(gl_FragData[0].xyz, gl_Fog.color.xyz, fogValue);

@ -39,12 +39,15 @@ varying float depth;
#if !PER_PIXEL_LIGHTING
varying vec4 lighting;
varying vec3 shadowDiffuseLighting;
#else
varying vec4 passColor;
#endif
varying vec3 passViewPos;
varying vec3 passNormal;
varying vec4 shadowSpaceCoords;
#include "lighting.glsl"
void main(void)
@ -93,10 +96,14 @@ void main(void)
#endif
#if !PER_PIXEL_LIGHTING
lighting = doLighting(viewPos.xyz, viewNormal, gl_Color);
lighting = doLighting(viewPos.xyz, viewNormal, gl_Color, shadowDiffuseLighting);
#else
passColor = gl_Color;
#endif
passViewPos = viewPos.xyz;
passNormal = gl_Normal.xyz;
// This matrix has the opposite handedness to the others used here, so multiplication must have the vector to the left. Alternatively it could be transposed after construction, but that's extra work for the GPU just to make the code look a tiny bit cleaner.
mat4 eyePlaneMat = mat4(gl_EyePlaneS[1], gl_EyePlaneT[1], gl_EyePlaneR[1], gl_EyePlaneQ[1]);
shadowSpaceCoords = viewPos * eyePlaneMat;
}

@ -1,5 +1,7 @@
#version 120
#define FRAGMENT
varying vec2 uv;
uniform sampler2D diffuseMap;
@ -18,12 +20,16 @@ varying float depth;
#if !PER_PIXEL_LIGHTING
varying vec4 lighting;
varying vec3 shadowDiffuseLighting;
#else
varying vec4 passColor;
#endif
varying vec3 passViewPos;
varying vec3 passNormal;
uniform sampler2DShadow shadowTexture;
varying vec4 shadowSpaceCoords;
#include "lighting.glsl"
#include "parallax.glsl"
@ -64,10 +70,12 @@ void main()
gl_FragData[0].a *= texture2D(blendMap, blendMapUV).a;
#endif
float shadowing = shadow2DProj(shadowTexture, shadowSpaceCoords).r;
#if !PER_PIXEL_LIGHTING
gl_FragData[0] *= lighting;
gl_FragData[0] *= lighting + vec4(shadowDiffuseLighting * shadowing, 0);
#else
gl_FragData[0] *= doLighting(passViewPos, normalize(viewNormal), passColor);
gl_FragData[0] *= doLighting(passViewPos, normalize(viewNormal), passColor, shadowing);
#endif
#if @specularMap
@ -78,7 +86,7 @@ void main()
vec3 matSpec = gl_FrontMaterial.specular.xyz;
#endif
gl_FragData[0].xyz += getSpecular(normalize(viewNormal), normalize(passViewPos), shininess, matSpec);
gl_FragData[0].xyz += getSpecular(normalize(viewNormal), normalize(passViewPos), shininess, matSpec) * shadowing;
float fogValue = clamp((depth - gl_Fog.start) * gl_Fog.scale, 0.0, 1.0);
gl_FragData[0].xyz = mix(gl_FragData[0].xyz, gl_Fog.color.xyz, fogValue);

@ -7,12 +7,15 @@ varying float depth;
#if !PER_PIXEL_LIGHTING
varying vec4 lighting;
varying vec3 shadowDiffuseLighting;
#else
varying vec4 passColor;
#endif
varying vec3 passViewPos;
varying vec3 passNormal;
varying vec4 shadowSpaceCoords;
#include "lighting.glsl"
void main(void)
@ -25,7 +28,7 @@ void main(void)
#if !PER_PIXEL_LIGHTING
vec3 viewNormal = normalize((gl_NormalMatrix * gl_Normal).xyz);
lighting = doLighting(viewPos.xyz, viewNormal, gl_Color);
lighting = doLighting(viewPos.xyz, viewNormal, gl_Color, shadowDiffuseLighting);
#else
passColor = gl_Color;
#endif
@ -33,4 +36,8 @@ void main(void)
passViewPos = viewPos.xyz;
uv = gl_MultiTexCoord0.xy;
// This matrix has the opposite handedness to the others used here, so multiplication must have the vector to the left. Alternatively it could be transposed after construction, but that's extra work for the GPU just to make the code look a tiny bit cleaner.
mat4 eyePlaneMat = mat4(gl_EyePlaneS[1], gl_EyePlaneT[1], gl_EyePlaneR[1], gl_EyePlaneQ[1]);
shadowSpaceCoords = viewPos * eyePlaneMat;
}

Loading…
Cancel
Save