diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index d0613648d..475e906c4 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -63,6 +63,16 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const platform->setCacheFolder ("./"); mFactory = new sh::Factory(platform); + sh::Language lang; + std::string l = Settings::Manager::getString("shader mode", "General"); + if (l == "glsl") + lang = sh::Language_GLSL; + else if (l == "hlsl") + lang = sh::Language_HLSL; + else + lang = sh::Language_CG; + mFactory->setCurrentLanguage (lang); + //The fog type must be set before any terrain objects are created as if the //fog type is set to FOG_NONE then the initially created terrain won't have any fog configureFog(1, ColourValue(1,1,1)); diff --git a/apps/openmw/mwrender/shadows.cpp b/apps/openmw/mwrender/shadows.cpp index 4c5188e37..3d9f13243 100644 --- a/apps/openmw/mwrender/shadows.cpp +++ b/apps/openmw/mwrender/shadows.cpp @@ -91,16 +91,16 @@ void Shadows::recreate() // Populate from split point 1, not 0, since split 0 isn't useful (usually 0) const PSSMShadowCameraSetup::SplitPointList& splitPointList = getPSSMSetup()->getSplitPoints(); - sh::Vector4* splitPoints = new sh::Vector4(splitPointList[1], splitPointList[2], splitPointList[3], 1.0); + sh::Vector3* splitPoints = new sh::Vector3(splitPointList[1], splitPointList[2], splitPointList[3]); - sh::Factory::getInstance ().setSharedParameter ("pssmSplitPoints", sh::makeProperty(splitPoints)); + sh::Factory::getInstance ().setSharedParameter ("pssmSplitPoints", sh::makeProperty(splitPoints)); shadowCameraSetup = ShadowCameraSetupPtr(mPSSMSetup); } else { LiSPSMShadowCameraSetup* lispsmSetup = new LiSPSMShadowCameraSetup(); - lispsmSetup->setOptimalAdjustFactor(2); + lispsmSetup->setOptimalAdjustFactor(64); //lispsmSetup->setCameraLightDirectionThreshold(Degree(0)); //lispsmSetup->setUseAggressiveFocusRegion(false); shadowCameraSetup = ShadowCameraSetupPtr(lispsmSetup); @@ -131,7 +131,7 @@ void Shadows::recreate() Overlay* overlay; // destroy if already exists - if (overlay = mgr.getByName("DebugOverlay")) + if ((overlay = mgr.getByName("DebugOverlay"))) mgr.destroy(overlay); overlay = mgr.create("DebugOverlay"); @@ -155,10 +155,10 @@ void Shadows::recreate() // destroy container if exists try { - if (debugPanel = + if ((debugPanel = static_cast( mgr.getOverlayElement("Ogre/DebugTexPanel" + StringConverter::toString(i) - ))) + )))) mgr.destroyOverlayElement(debugPanel); } catch (Ogre::Exception&) {} @@ -178,7 +178,7 @@ void Shadows::recreate() OverlayManager& mgr = OverlayManager::getSingleton(); Overlay* overlay; - if (overlay = mgr.getByName("DebugOverlay")) + if ((overlay = mgr.getByName("DebugOverlay"))) mgr.destroy(overlay); } } diff --git a/apps/openmw/mwrender/sky.cpp b/apps/openmw/mwrender/sky.cpp index f79ab6116..65a9e8953 100644 --- a/apps/openmw/mwrender/sky.cpp +++ b/apps/openmw/mwrender/sky.cpp @@ -15,6 +15,8 @@ #include #include +#include + #include #include "../mwbase/environment.hpp" @@ -50,7 +52,7 @@ void BillboardObject::setSize(const float size) void BillboardObject::setVisibility(const float visibility) { - mMaterial->getTechnique(0)->getPass(0)->setDiffuse(0.0, 0.0, 0.0, visibility); + //mMaterial->getTechnique(0)->getPass(0)->setDiffuse(0.0, 0.0, 0.0, visibility); } void BillboardObject::setPosition(const Vector3& pPosition) @@ -76,7 +78,7 @@ void BillboardObject::setVisibilityFlags(int flags) void BillboardObject::setColour(const ColourValue& pColour) { - mMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(pColour); + //mMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(pColour); } void BillboardObject::setRenderQueue(unsigned int id) @@ -112,6 +114,12 @@ void BillboardObject::init(const String& textureName, mBBSet->createBillboard(0,0,0); mBBSet->setCastShadows(false); + sh::MaterialInstance* m = sh::Factory::getInstance().createMaterialInstance ("BillboardMaterial"+StringConverter::toString(bodyCount), "openmw_sun"); + m->setProperty("texture", sh::makeProperty(new sh::StringValue(textureName))); + + mBBSet->setMaterialName("BillboardMaterial"+StringConverter::toString(bodyCount)); + + /* mMaterial = MaterialManager::getSingleton().create("BillboardMaterial"+StringConverter::toString(bodyCount), ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); mMaterial->removeAllTechniques(); Pass* p = mMaterial->createTechnique()->createPass(); @@ -123,7 +131,6 @@ void BillboardObject::init(const String& textureName, p->setAmbient(0.0,0.0,0.0); p->setPolygonModeOverrideable(false); p->createTextureUnitState(textureName); - mBBSet->setMaterialName("BillboardMaterial"+StringConverter::toString(bodyCount)); HighLevelGpuProgramManager& mgr = HighLevelGpuProgramManager::getSingleton(); HighLevelGpuProgramPtr vshader; @@ -183,7 +190,7 @@ void BillboardObject::init(const String& textureName, fshader->getDefaultParameters()->setNamedAutoConstant("diffuse", GpuProgramParameters::ACT_SURFACE_DIFFUSE_COLOUR); fshader->getDefaultParameters()->setNamedAutoConstant("emissive", GpuProgramParameters::ACT_SURFACE_EMISSIVE_COLOUR); mMaterial->getTechnique(0)->getPass(0)->setFragmentProgram(fshader->getName()); - +*/ bodyCount++; } @@ -194,6 +201,8 @@ Moon::Moon( const String& textureName, { init(textureName, initialSize, position, rootNode); + + /* HighLevelGpuProgramManager& mgr = HighLevelGpuProgramManager::getSingleton(); HighLevelGpuProgramPtr vshader; if (mgr.resourceExists("Moon_VP")) @@ -261,6 +270,8 @@ Moon::Moon( const String& textureName, fshader->getDefaultParameters()->setNamedAutoConstant("emissive", GpuProgramParameters::ACT_SURFACE_EMISSIVE_COLOUR); mMaterial->getTechnique(0)->getPass(0)->setFragmentProgram(fshader->getName()); + */ + setVisibility(1.0); mPhase = Moon::Phase_Full; @@ -273,7 +284,7 @@ void Moon::setType(const Moon::Type& type) void Moon::setSkyColour(const Ogre::ColourValue& colour) { - mMaterial->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("skyColour", colour); + //mMaterial->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("skyColour", colour); } void Moon::setPhase(const Moon::Phase& phase) @@ -295,7 +306,7 @@ void Moon::setPhase(const Moon::Phase& phase) textureName += ".dds"; - mMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(textureName); + //mMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(textureName); mPhase = phase; } @@ -387,8 +398,6 @@ SkyManager::SkyManager (SceneNode* pMwRoot, Camera* pCamera) , mSceneMgr(NULL) , mAtmosphereDay(NULL) , mAtmosphereNight(NULL) - , mCloudMaterial() - , mAtmosphereMaterial() , mCloudFragmentShader() , mClouds() , mNextClouds() @@ -406,6 +415,7 @@ SkyManager::SkyManager (SceneNode* pMwRoot, Camera* pCamera) , mMasserEnabled(true) , mSecundaEnabled(true) , mCreated(false) + , mCloudAnimationTimer(0.f) { mSceneMgr = pMwRoot->getCreator(); mRootNode = mCamera->getParentSceneNode()->createChildSceneNode(); @@ -415,7 +425,19 @@ SkyManager::SkyManager (SceneNode* pMwRoot, Camera* pCamera) void SkyManager::create() { - /// \todo preload all the textures and meshes that are used for sky rendering + sh::Factory::getInstance().setSharedParameter ("cloudBlendFactor", + sh::makeProperty(new sh::FloatValue(0))); + sh::Factory::getInstance().setSharedParameter ("cloudOpacity", + sh::makeProperty(new sh::FloatValue(1))); + sh::Factory::getInstance().setSharedParameter ("cloudColour", + sh::makeProperty(new sh::Vector3(1,1,1))); + sh::Factory::getInstance().setSharedParameter ("cloudAnimationTimer", + sh::makeProperty(new sh::FloatValue(0))); + sh::Factory::getInstance().setSharedParameter ("nightFade", + sh::makeProperty(new sh::FloatValue(0))); + + sh::Factory::getInstance().setTextureAlias ("cloud_texture_1", ""); + sh::Factory::getInstance().setTextureAlias ("cloud_texture_2", ""); // Create overlay used for thunderstorm MaterialPtr material = MaterialManager::getSingleton().create( "ThunderMaterial", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME ); @@ -449,9 +471,6 @@ void SkyManager::create() mSunGlare->setRenderQueue(RQG_SkiesLate); mSunGlare->setVisibilityFlags(RV_Glare); - - HighLevelGpuProgramManager& mgr = HighLevelGpuProgramManager::getSingleton(); - // Stars MeshPtr mesh = NifOgre::NIFLoader::load("meshes\\sky_night_01.nif"); Entity* night1_ent = mSceneMgr->createEntity("meshes\\sky_night_01.nif"); @@ -462,76 +481,18 @@ void SkyManager::create() mAtmosphereNight = mRootNode->createChildSceneNode(); mAtmosphereNight->attachObject(night1_ent); - // Stars vertex shader - HighLevelGpuProgramPtr stars_vp = mgr.createProgram("Stars_VP", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, - "cg", GPT_VERTEX_PROGRAM); - stars_vp->setParameter("profiles", "vs_2_x arbvp1"); - stars_vp->setParameter("entry_point", "main_vp"); - StringUtil::StrStreamType outStream4; - outStream4 << - "void main_vp( \n" - " float4 position : POSITION, \n" - " in float2 uv : TEXCOORD0, \n" - " out float2 oUV : TEXCOORD0, \n" - " out float oFade : TEXCOORD1, \n" - " out float4 oPosition : POSITION, \n" - " uniform float4x4 worldViewProj \n" - ") \n" - "{ \n" - " oUV = uv; \n" - " oFade = (position.z > 50) ? 1.f : 0.f; \n" - " oPosition = mul( worldViewProj, position ); \n" - "}"; - stars_vp->setSource(outStream4.str()); - stars_vp->load(); - stars_vp->getDefaultParameters()->setNamedAutoConstant("worldViewProj", GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX); - - // Stars fragment shader - HighLevelGpuProgramPtr stars_fp = mgr.createProgram("Stars_FP", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, - "cg", GPT_FRAGMENT_PROGRAM); - stars_fp->setParameter("profiles", "ps_2_x arbfp1"); - stars_fp->setParameter("entry_point", "main_fp"); - StringUtil::StrStreamType outStream5; - outStream5 << - "void main_fp( \n" - " in float2 uv : TEXCOORD0, \n" - " out float4 oColor : COLOR, \n"; - if (RenderingManager::useMRT()) outStream5 << - " out float4 oColor1 : COLOR1, \n"; - outStream5 << - " in float fade : TEXCOORD1, \n" - " uniform sampler2D texture : TEXUNIT0, \n" - " uniform float opacity, \n" - " uniform float4 diffuse, \n" - " uniform float4 emissive \n" - ") \n" - "{ \n" - " oColor = tex2D(texture, uv) * float4(emissive.xyz, 1) * float4(1,1,1,fade*diffuse.a); \n"; - if (RenderingManager::useMRT()) outStream5 << - " oColor1 = float4(1, 0, 0, 1); \n"; - outStream5 << - "}"; - stars_fp->setSource(outStream5.str()); - stars_fp->load(); - stars_fp->getDefaultParameters()->setNamedAutoConstant("emissive", GpuProgramParameters::ACT_SURFACE_EMISSIVE_COLOUR); - stars_fp->getDefaultParameters()->setNamedAutoConstant("diffuse", GpuProgramParameters::ACT_SURFACE_DIFFUSE_COLOUR); - - /* for (unsigned int i=0; igetNumSubEntities(); ++i) { - MaterialPtr mp = night1_ent->getSubEntity(i)->getMaterial(); - mp->getTechnique(0)->getPass(0)->setSelfIllumination(1.0, 1.0, 1.0); - mp->getTechnique(0)->getPass(0)->setAmbient(0.0, 0.0, 0.0); - mp->getTechnique(0)->getPass(0)->setDiffuse(0.0, 0.0, 0.0, 1.0); - mp->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false); - mp->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false); - mp->getTechnique(0)->getPass(0)->setSceneBlending(SBT_TRANSPARENT_ALPHA); - mp->getTechnique(0)->getPass(0)->setVertexProgram(stars_vp->getName()); - mp->getTechnique(0)->getPass(0)->setFragmentProgram(stars_fp->getName()); - mp->getTechnique(0)->getPass(0)->setPolygonModeOverrideable(false); - mStarsMaterials[i] = mp; + std::string matName = "openmw_stars_" + boost::lexical_cast(i); + sh::MaterialInstance* m = sh::Factory::getInstance ().createMaterialInstance (matName, "openmw_stars"); + + std::string textureName = sh::retrieveValue( + sh::Factory::getInstance().getMaterialInstance(night1_ent->getSubEntity (i)->getMaterialName ())->getProperty("diffuseMap"), NULL).get(); + + m->setProperty ("texture", sh::makeProperty(new sh::StringValue(textureName))); + + night1_ent->getSubEntity(i)->setMaterialName (matName); } - */ // Atmosphere (day) mesh = NifOgre::NIFLoader::load("meshes\\sky_atmosphere.nif"); @@ -545,11 +506,6 @@ void SkyManager::create() mAtmosphereDay = mRootNode->createChildSceneNode(); mAtmosphereDay->attachObject(atmosphere_ent); atmosphere_ent->getSubEntity (0)->setMaterialName ("openmw_atmosphere"); - //mAtmosphereMaterial = atmosphere_ent->getSubEntity(0)->getMaterial(); - //mAtmosphereMaterial->getTechnique(0)->getPass(0)->setPolygonModeOverrideable(false); - // Atmosphere shader - // mAtmosphereMaterial->getTechnique(0)->getPass(0)->setFragmentProgram(fshader->getName()); - atmosphere_ent->getSubEntity (0)->setMaterialName("openmw_atmosphere"); // Clouds NifOgre::NIFLoader::load("meshes\\sky_clouds_01.nif"); @@ -558,89 +514,11 @@ void SkyManager::create() clouds_ent->setRenderQueueGroup(RQG_SkiesEarly+5); SceneNode* clouds_node = mRootNode->createChildSceneNode(); clouds_node->attachObject(clouds_ent); - //mCloudMaterial = clouds_ent->getSubEntity(0)->getMaterial(); clouds_ent->getSubEntity(0)->setMaterialName ("openmw_clouds"); - //mCloudMaterial->getTechnique(0)->getPass(0)->setPolygonModeOverrideable(false); clouds_ent->setCastShadows(false); - // Clouds vertex shader - HighLevelGpuProgramPtr vshader2 = mgr.createProgram("Clouds_VP", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, - "cg", GPT_VERTEX_PROGRAM); - vshader2->setParameter("profiles", "vs_2_x arbvp1"); - vshader2->setParameter("entry_point", "main_vp"); - StringUtil::StrStreamType outStream3; - outStream3 << - "void main_vp( \n" - " float4 position : POSITION, \n" - " in float4 color : COLOR, \n" - " out float4 oColor : TEXCOORD1, \n" - " in float2 uv : TEXCOORD0, \n" - " out float2 oUV : TEXCOORD0, \n" - " out float4 oPosition : POSITION, \n" - " uniform float4x4 worldViewProj \n" - ") \n" - "{ \n" - " oUV = uv; \n" - " oColor = color; \n" - " oPosition = mul( worldViewProj, position ); \n" - "}"; - vshader2->setSource(outStream3.str()); - vshader2->load(); - vshader2->getDefaultParameters()->setNamedAutoConstant("worldViewProj", GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX); - //mCloudMaterial->getTechnique(0)->getPass(0)->setVertexProgram(vshader2->getName()); - - // Clouds fragment shader - mCloudFragmentShader = mgr.createProgram("Clouds_FP", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, - "cg", GPT_FRAGMENT_PROGRAM); - mCloudFragmentShader->setParameter("profiles", "ps_2_x arbfp1"); - mCloudFragmentShader->setParameter("entry_point", "main_fp"); - StringUtil::StrStreamType outStream2; - outStream2 << - "void main_fp( \n" - " in float2 uv : TEXCOORD0, \n" - " in float4 color : TEXCOORD1, \n" - " out float4 oColor : COLOR, \n"; - if (RenderingManager::useMRT()) outStream2 << - " out float4 oColor1 : COLOR1, \n"; - outStream2 << - " uniform sampler2D texture : TEXUNIT0, \n" - " uniform sampler2D secondTexture : TEXUNIT1, \n" - " uniform float transitionFactor, \n" - " uniform float time, \n" - " uniform float speed, \n" - " uniform float opacity, \n" - " uniform float4 emissive \n" - ") \n" - "{ \n" - " uv += float2(0,1) * time * speed * 0.003; \n" // Scroll in y direction - " float4 tex = lerp(tex2D(texture, uv), tex2D(secondTexture, uv), transitionFactor); \n" - " oColor = color * float4(emissive.xyz,1) * tex * float4(1,1,1,opacity); \n"; - if (RenderingManager::useMRT()) outStream2 << - " oColor1 = float4(1, 0, 0, 1); \n"; - outStream2 << - "}"; - mCloudFragmentShader->setSource(outStream2.str()); - mCloudFragmentShader->load(); - mCloudFragmentShader->getDefaultParameters()->setNamedAutoConstant("emissive", GpuProgramParameters::ACT_SURFACE_EMISSIVE_COLOUR); - //mCloudMaterial->getTechnique(0)->getPass(0)->setFragmentProgram(mCloudFragmentShader->getName()); - setCloudsOpacity(0.75); - ModVertexAlpha(clouds_ent, 1); - // I'm not sure if the materials are being used by any other objects - // Make a unique "modifiable" copy of the materials to be sure - //mCloudMaterial = mCloudMaterial->clone("Clouds"); - //clouds_ent->getSubEntity(0)->setMaterial(mCloudMaterial); - /* - mCloudMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(1.0, 1.0, 1.0); - mCloudMaterial->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false); - mCloudMaterial->getTechnique(0)->getPass(0)->setSceneBlending(SBT_TRANSPARENT_ALPHA); - - mCloudMaterial->getTechnique(0)->getPass(0)->removeAllTextureUnitStates(); - mCloudMaterial->getTechnique(0)->getPass(0)->createTextureUnitState("textures\\tx_sky_cloudy.dds"); - mCloudMaterial->getTechnique(0)->getPass(0)->createTextureUnitState(""); -*/ - mCreated = true; } @@ -669,7 +547,10 @@ void SkyManager::update(float duration) if (!mEnabled) return; // UV Scroll the clouds - //mCloudMaterial->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstantFromTime("time", MWBase::Environment::get().getWorld()->getTimeScaleFactor()/30.f); + mCloudAnimationTimer += duration * mCloudSpeed * (MWBase::Environment::get().getWorld()->getTimeScaleFactor()/30.f); + sh::Factory::getInstance().setSharedParameter ("cloudAnimationTimer", + sh::makeProperty(new sh::FloatValue(mCloudAnimationTimer))); + /// \todo improve this mMasser->setPhase( static_cast( (int) ((mDay % 32)/4.f)) ); @@ -678,15 +559,15 @@ void SkyManager::update(float duration) if (mSunEnabled) { - // take 1/5 sec for fading the glare effect from invisible to full + // take 1/10 sec for fading the glare effect from invisible to full if (mGlareFade > mGlare) { - mGlareFade -= duration*5; + mGlareFade -= duration*10; if (mGlareFade < mGlare) mGlareFade = mGlare; } else if (mGlareFade < mGlare) { - mGlareFade += duration*5; + mGlareFade += duration*10; if (mGlareFade > mGlare) mGlareFade = mGlare; } @@ -733,39 +614,34 @@ void SkyManager::setMoonColour (bool red) : ColourValue(1.0, 1.0, 1.0)); } -void SkyManager::setCloudsOpacity(float opacity) -{ - if (!mCreated) return; - //mCloudMaterial->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("opacity", Real(opacity)); -} - void SkyManager::setWeather(const MWWorld::WeatherResult& weather) { if (!mCreated) return; - /* if (mClouds != weather.mCloudTexture) { - mCloudMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName("textures\\"+weather.mCloudTexture); + sh::Factory::getInstance().setTextureAlias ("cloud_texture_1", "textures\\"+weather.mCloudTexture); mClouds = weather.mCloudTexture; } if (mNextClouds != weather.mNextCloudTexture) { - mCloudMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(1)->setTextureName("textures\\"+weather.mNextCloudTexture); + sh::Factory::getInstance().setTextureAlias ("cloud_texture_2", "textures\\"+weather.mNextCloudTexture); mNextClouds = weather.mNextCloudTexture; } if (mCloudBlendFactor != weather.mCloudBlendFactor) { - mCloudMaterial->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("transitionFactor", Real(weather.mCloudBlendFactor)); mCloudBlendFactor = weather.mCloudBlendFactor; + sh::Factory::getInstance().setSharedParameter ("cloudBlendFactor", + sh::makeProperty(new sh::FloatValue(weather.mCloudBlendFactor))); } if (mCloudOpacity != weather.mCloudOpacity) { - mCloudMaterial->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("opacity", Real(weather.mCloudOpacity)); mCloudOpacity = weather.mCloudOpacity; + sh::Factory::getInstance().setSharedParameter ("cloudOpacity", + sh::makeProperty(new sh::FloatValue(weather.mCloudOpacity))); } if (mCloudColour != weather.mSunColor) @@ -774,23 +650,21 @@ void SkyManager::setWeather(const MWWorld::WeatherResult& weather) weather.mSunColor.g*0.7 + weather.mAmbientColor.g*0.7, weather.mSunColor.b*0.7 + weather.mAmbientColor.b*0.7); - mCloudMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(clr); + sh::Factory::getInstance().setSharedParameter ("cloudColour", + sh::makeProperty(new sh::Vector3(clr.r, clr.g, clr.b))); + mCloudColour = weather.mSunColor; } -*/ + if (mSkyColour != weather.mSkyColor) { mSkyColour = weather.mSkyColor; sh::Factory::getInstance().setSharedParameter ("atmosphereColour", sh::makeProperty(new sh::Vector4( - weather.mSkyColor.r, weather.mSkyColor.g, weather.mSkyColor.b, 1.0))); - } -/* - if (mCloudSpeed != weather.mCloudSpeed) - { - mCloudMaterial->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("speed", Real(weather.mCloudSpeed)); - mCloudSpeed = weather.mCloudSpeed; + weather.mSkyColor.r, weather.mSkyColor.g, weather.mSkyColor.b, weather.mSkyColor.a))); } + mCloudSpeed = weather.mCloudSpeed; + if (weather.mNight && mStarsOpacity != weather.mNightFade) { if (weather.mNightFade == 0) @@ -798,12 +672,14 @@ void SkyManager::setWeather(const MWWorld::WeatherResult& weather) else { mAtmosphereNight->setVisible(true); - for (int i=0; i<7; ++i) - mStarsMaterials[i]->getTechnique(0)->getPass(0)->setDiffuse(0.0, 0.0, 0.0, weather.mNightFade); + + sh::Factory::getInstance().setSharedParameter ("nightFade", + sh::makeProperty(new sh::FloatValue(weather.mNightFade))); + mStarsOpacity = weather.mNightFade; } } - */ + float strength; float timeofday_angle = std::abs(mSunGlare->getPosition().z/mSunGlare->getPosition().length()); diff --git a/apps/openmw/mwrender/sky.hpp b/apps/openmw/mwrender/sky.hpp index 6bb055824..f59583c04 100644 --- a/apps/openmw/mwrender/sky.hpp +++ b/apps/openmw/mwrender/sky.hpp @@ -139,9 +139,6 @@ namespace MWRender void setMoonColour (bool red); ///< change Secunda colour to red - void setCloudsOpacity(float opacity); - ///< change opacity of the clouds - void setWeather(const MWWorld::WeatherResult& weather); Ogre::SceneNode* getSunNode(); @@ -182,6 +179,8 @@ namespace MWRender int mDay; int mMonth; + float mCloudAnimationTimer; + BillboardObject* mSun; BillboardObject* mSunGlare; Moon* mMasser; @@ -194,11 +193,6 @@ namespace MWRender Ogre::SceneNode* mAtmosphereDay; Ogre::SceneNode* mAtmosphereNight; - Ogre::MaterialPtr mCloudMaterial; - Ogre::MaterialPtr mAtmosphereMaterial; - - Ogre::MaterialPtr mStarsMaterials[7]; - Ogre::HighLevelGpuProgramPtr mCloudFragmentShader; // remember some settings so we don't have to apply them again if they didnt change diff --git a/extern/shiny b/extern/shiny index 34e952bf3..7485a15c2 160000 --- a/extern/shiny +++ b/extern/shiny @@ -1 +1 @@ -Subproject commit 34e952bf3d5e09adfd3e5c0f6462d612e193e447 +Subproject commit 7485a15c26f129084a1c264fa1a98dc2de86f298 diff --git a/files/materials/atmosphere.shader b/files/materials/atmosphere.shader index 831ba1138..295fa9376 100644 --- a/files/materials/atmosphere.shader +++ b/files/materials/atmosphere.shader @@ -1,11 +1,11 @@ #include "core.h" -#define MRT @shPropertyBool(mrt_output) +#define MRT @shGlobalSettingBool(mrt_output) #ifdef SH_VERTEX_SHADER SH_BEGIN_PROGRAM - shUniform(float4x4 wvp) @shAutoConstant(wvp, worldviewproj_matrix) + shUniform(float4x4, wvp) @shAutoConstant(wvp, worldviewproj_matrix) shColourInput(float4) shOutput(float4, colourPassthrough) @@ -23,7 +23,7 @@ #if MRT shDeclareMrtOutput(1) #endif - shUniform(float4 atmosphereColour) @shSharedParameter(atmosphereColour) + shUniform(float4, atmosphereColour) @shSharedParameter(atmosphereColour) SH_START_PROGRAM { diff --git a/files/materials/clouds.shader b/files/materials/clouds.shader index 1a80a27dd..7677ecd95 100644 --- a/files/materials/clouds.shader +++ b/files/materials/clouds.shader @@ -1,11 +1,11 @@ #include "core.h" -#define MRT @shPropertyBool(mrt_output) +#define MRT @shGlobalSettingBool(mrt_output) #ifdef SH_VERTEX_SHADER SH_BEGIN_PROGRAM - shUniform(float4x4 wvp) @shAutoConstant(wvp, worldviewproj_matrix) + shUniform(float4x4, wvp) @shAutoConstant(wvp, worldviewproj_matrix) shInput(float2, uv0) shOutput(float2, UV) shColourInput(float4) @@ -13,7 +13,7 @@ SH_START_PROGRAM { - + colourPassthrough = colour; shOutputPosition = shMatrixMult(wvp, shInputPosition); UV = uv0; } @@ -21,17 +21,28 @@ #else SH_BEGIN_PROGRAM - shSampler2D(diffuseMap) shInput(float2, UV) + shInput(float4, colourPassthrough) #if MRT shDeclareMrtOutput(1) #endif - shUniform(float4 materialDiffuse) @shAutoConstant(materialDiffuse, surface_diffuse_colour) - shUniform(float4 materialEmissive) @shAutoConstant(materialEmissive, surface_emissive_colour) - + + shSampler2D(diffuseMap1) + shSampler2D(diffuseMap2) + + shUniform(float, cloudBlendFactor) @shSharedParameter(cloudBlendFactor) + shUniform(float, cloudAnimationTimer) @shSharedParameter(cloudAnimationTimer) + shUniform(float, cloudOpacity) @shSharedParameter(cloudOpacity) + shUniform(float3, cloudColour) @shSharedParameter(cloudColour) + SH_START_PROGRAM { - shOutputColour(0) = float4(1,1,1,materialDiffuse.a) * float4(materialEmissive.xyz, 1) * shSample(diffuseMap, UV); + // Scroll in y direction + float2 scrolledUV = UV + float2(0,1) * cloudAnimationTimer * 0.003; + + float4 albedo = shSample(diffuseMap1, scrolledUV) * (1-cloudBlendFactor) + shSample(diffuseMap2, scrolledUV) * cloudBlendFactor; + + shOutputColour(0) = colourPassthrough * float4(cloudColour, 1) * albedo * float4(1,1,1, cloudOpacity); #if MRT shOutputColour(1) = float4(1,1,1,1); diff --git a/files/materials/core.h b/files/materials/core.h index b5d784dae..34095f93d 100644 --- a/files/materials/core.h +++ b/files/materials/core.h @@ -9,7 +9,7 @@ #define shMatrixMult(m, v) mul(m, v) - #define shUniform(s) , uniform s + #define shUniform(type, name) , uniform type name #define shInput(type, name) , in type name : TEXCOORD@shCounter(1) #define shOutput(type, name) , out type name : TEXCOORD@shCounter(2) @@ -59,13 +59,13 @@ #define float4 vec4 #define int2 ivec2 #define int3 ivec3 - #define int4 ivec4 + #define int4 ivec4/ #define shTexture2D sampler2D #define shSample(tex, coord) texture(tex, coord) #define shLerp(a, b, t) mix(a, b, t) #define shSaturate(a) clamp(a, 0.0, 1.0) - #define shUniform(s) uniform s; + #define shUniform(type, name) uniform type name; #define shSampler2D(name) uniform sampler2D name; @shUseSampler(name) diff --git a/files/materials/objects.shader b/files/materials/objects.shader index c80a592a3..3b4992f5b 100644 --- a/files/materials/objects.shader +++ b/files/materials/objects.shader @@ -21,7 +21,7 @@ // ------------------------------------- VERTEX --------------------------------------- SH_BEGIN_PROGRAM - shUniform(float4x4 wvp) @shAutoConstant(wvp, worldviewproj_matrix) + shUniform(float4x4, wvp) @shAutoConstant(wvp, worldviewproj_matrix) shInput(float2, uv0) shOutput(float2, UV) shNormalInput(float4) @@ -41,16 +41,16 @@ #if SHADOWS shOutput(float4, lightSpacePos0) - shUniform(float4x4 texViewProjMatrix0) @shAutoConstant(texViewProjMatrix0, texture_viewproj_matrix) - shUniform(float4x4 worldMatrix) @shAutoConstant(worldMatrix, world_matrix) + shUniform(float4x4, texViewProjMatrix0) @shAutoConstant(texViewProjMatrix0, texture_viewproj_matrix) + shUniform(float4x4, worldMatrix) @shAutoConstant(worldMatrix, world_matrix) #endif #if SHADOWS_PSSM @shForeach(3) shOutput(float4, lightSpacePos@shIterator) - shUniform(float4x4 texViewProjMatrix@shIterator) @shAutoConstant(texViewProjMatrix@shIterator, texture_viewproj_matrix, @shIterator) + shUniform(float4x4, texViewProjMatrix@shIterator) @shAutoConstant(texViewProjMatrix@shIterator, texture_viewproj_matrix, @shIterator) @shEndForeach - shUniform(float4x4 worldMatrix) @shAutoConstant(worldMatrix, world_matrix) + shUniform(float4x4, worldMatrix) @shAutoConstant(worldMatrix, world_matrix) #endif SH_START_PROGRAM { @@ -99,27 +99,27 @@ #endif #if MRT - shUniform(float far) @shAutoConstant(far, far_clip_distance) + shUniform(float, far) @shAutoConstant(far, far_clip_distance) #endif #if LIGHTING shInput(float3, normalPassthrough) shInput(float3, objSpacePositionPassthrough) - shUniform(float4 lightAmbient) @shAutoConstant(lightAmbient, ambient_light_colour) - //shUniform(float passIteration) @shAutoConstant(passIteration, pass_iteration_number) - shUniform(float4 materialAmbient) @shAutoConstant(materialAmbient, surface_ambient_colour) - shUniform(float4 materialDiffuse) @shAutoConstant(materialDiffuse, surface_diffuse_colour) - shUniform(float4 materialEmissive) @shAutoConstant(materialEmissive, surface_emissive_colour) + shUniform(float4, lightAmbient) @shAutoConstant(lightAmbient, ambient_light_colour) + //shUniform(float, passIteration) @shAutoConstant(passIteration, pass_iteration_number) + shUniform(float4, materialAmbient) @shAutoConstant(materialAmbient, surface_ambient_colour) + shUniform(float4, materialDiffuse) @shAutoConstant(materialDiffuse, surface_diffuse_colour) + shUniform(float4, materialEmissive) @shAutoConstant(materialEmissive, surface_emissive_colour) @shForeach(8) - 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) + 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 #if FOG - shUniform(float3 fogColor) @shAutoConstant(fogColor, fog_colour) - shUniform(float4 fogParams) @shAutoConstant(fogParams, fog_params) + shUniform(float3, fogColor) @shAutoConstant(fogColor, fog_colour) + shUniform(float4, fogParams) @shAutoConstant(fogParams, fog_params) #endif #ifdef HAS_VERTEXCOLOR @@ -129,19 +129,19 @@ #if SHADOWS shInput(float4, lightSpacePos0) shSampler2D(shadowMap0) - shUniform(float2 invShadowmapSize0) @shAutoConstant(invShadowmapSize0, inverse_texture_size, 1) + 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)) + shUniform(float2, invShadowmapSize@shIterator) @shAutoConstant(invShadowmapSize@shIterator, inverse_texture_size, @shIterator(1)) @shEndForeach - shUniform(float4 pssmSplitPoints) @shSharedParameter(pssmSplitPoints) + shUniform(float3, pssmSplitPoints) @shSharedParameter(pssmSplitPoints) #endif #if SHADOWS || SHADOWS_PSSM - shUniform(float4 shadowFar_fadeStart) @shSharedParameter(shadowFar_fadeStart) + shUniform(float4, shadowFar_fadeStart) @shSharedParameter(shadowFar_fadeStart) #endif SH_START_PROGRAM { diff --git a/files/materials/shadowcaster.shader b/files/materials/shadowcaster.shader index 500207778..a5551509d 100644 --- a/files/materials/shadowcaster.shader +++ b/files/materials/shadowcaster.shader @@ -9,7 +9,7 @@ shInput(float2, uv0) shOutput(float2, UV) #endif - shUniform(float4x4 wvp) @shAutoConstant(wvp, worldviewproj_matrix) + shUniform(float4x4, wvp) @shAutoConstant(wvp, worldviewproj_matrix) shOutput(float2, depth) SH_START_PROGRAM { diff --git a/files/materials/shadows.h b/files/materials/shadows.h index a3518b976..9127d28f7 100644 --- a/files/materials/shadows.h +++ b/files/materials/shadows.h @@ -1,6 +1,4 @@ - - float depthShadowPCF (shTexture2D shadowMap, float4 shadowMapPos, float2 offset) { shadowMapPos /= shadowMapPos.w; @@ -31,7 +29,7 @@ float pssmDepthShadow ( shTexture2D shadowMap2, float depth, - float4 pssmSplitPoints) + float3 pssmSplitPoints) { float shadow; diff --git a/files/materials/sky.mat b/files/materials/sky.mat index 6465476dd..3f52966e8 100644 --- a/files/materials/sky.mat +++ b/files/materials/sky.mat @@ -1,7 +1,6 @@ material openmw_moon { allow_fixed_function false - mrt_output true pass { vertex_program moon_vertex @@ -9,11 +8,6 @@ material openmw_moon polygon_mode_overrideable off - shader_properties - { - mrt_output $mrt_output - } - texture_unit diffuseMap { texture $diffuseMap @@ -25,7 +19,6 @@ material openmw_moon material openmw_clouds { allow_fixed_function false - mrt_output true pass { vertex_program clouds_vertex @@ -36,11 +29,6 @@ material openmw_clouds scene_blend alpha_blend depth_write off - shader_properties - { - mrt_output $mrt_output - } - // second diffuse map is used for weather transitions texture_unit diffuseMap1 { @@ -58,7 +46,6 @@ material openmw_clouds material openmw_atmosphere { allow_fixed_function false - mrt_output true pass { vertex_program atmosphere_vertex @@ -68,33 +55,26 @@ material openmw_atmosphere scene_blend alpha_blend depth_write off - - shader_properties - { - mrt_output $mrt_output - } } } material openmw_stars { allow_fixed_function false - mrt_output true pass { vertex_program stars_vertex fragment_program stars_fragment polygon_mode_overrideable off - - shader_properties - { - mrt_output $mrt_output - } + + depth_check off + depth_write off + scene_blend alpha_blend texture_unit diffuseMap { - diffuseMap $diffuseMap + direct_texture $texture } } } @@ -103,7 +83,6 @@ material openmw_stars material openmw_sun { allow_fixed_function false - mrt_output true pass { vertex_program sun_vertex @@ -111,14 +90,9 @@ material openmw_sun polygon_mode_overrideable off - shader_properties - { - mrt_output $mrt_output - } - - texture unit diffuseMap + texture_unit diffuseMap { - diffuseMap $diffuseMap + direct_texture $texture } } } diff --git a/files/materials/sun.shader b/files/materials/sun.shader index 03ec7665c..4c7926756 100644 --- a/files/materials/sun.shader +++ b/files/materials/sun.shader @@ -1,12 +1,12 @@ #include "core.h" -#define MRT @shPropertyBool(mrt_output) +#define MRT @shGlobalSettingBool(mrt_output) #ifdef SH_VERTEX_SHADER SH_BEGIN_PROGRAM - shUniform(float4x4 wvp) @shAutoConstant(wvp, worldviewproj_matrix) + shUniform(float4x4, wvp) @shAutoConstant(wvp, worldviewproj_matrix) shInput(float2, uv0) shOutput(float2, UV) @@ -24,12 +24,14 @@ #if MRT shDeclareMrtOutput(1) #endif - shUniform(float4 materialDiffuse) @shAutoConstant(materialDiffuse, surface_diffuse_colour) - shUniform(float4 materialEmissive) @shAutoConstant(materialEmissive, surface_emissive_colour) + shUniform(float4, materialDiffuse) @shAutoConstant(materialDiffuse, surface_diffuse_colour) + shUniform(float4, materialEmissive) @shAutoConstant(materialEmissive, surface_emissive_colour) SH_START_PROGRAM { shOutputColour(0) = float4(1,1,1,materialDiffuse.a) * float4(materialEmissive.xyz, 1) * shSample(diffuseMap, UV); + + shOutputColour(0) = shSample(diffuseMap, UV); #if MRT shOutputColour(1) = float4(1,1,1,1);