From a095572205f2bd153784b7d0cf9930e0247a8667 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 6 Jul 2012 10:31:48 +0200 Subject: [PATCH] fixed some textures, started with sky --- apps/openmw/mwrender/renderingmanager.cpp | 2 - apps/openmw/mwrender/sky.cpp | 41 ++++++++++++-------- components/nifogre/ogre_nif_loader.cpp | 1 + extern/shiny | 2 +- files/materials/atmosphere.shader | 38 +++++++++++++++++++ files/materials/atmosphere.shaderset | 15 ++++++++ files/materials/clouds.shader | 38 +++++++++++++++++++ files/materials/clouds.shaderset | 15 ++++++++ files/materials/objects.mat | 2 +- files/materials/objects.shader | 11 +++++- files/materials/sky.mat | 46 +++++++++++++++++++++++ files/materials/sun.shader | 39 +++++++++++++++++++ files/materials/sun.shaderset | 15 ++++++++ 13 files changed, 244 insertions(+), 21 deletions(-) diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index bfa27e42f..174a9e4f8 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -270,12 +270,10 @@ void RenderingManager::setWaterHeight(const float height) void RenderingManager::skyEnable () { - /* if(mSkyManager) mSkyManager->enable(); mOcclusionQuery->setSunNode(mSkyManager->getSunNode()); - */ } void RenderingManager::skyDisable () diff --git a/apps/openmw/mwrender/sky.cpp b/apps/openmw/mwrender/sky.cpp index e1e8d6a5c..0a866ac7c 100644 --- a/apps/openmw/mwrender/sky.cpp +++ b/apps/openmw/mwrender/sky.cpp @@ -416,7 +416,7 @@ SkyManager::SkyManager (SceneNode* pMwRoot, Camera* pCamera) void SkyManager::create() { /// \todo preload all the textures and meshes that are used for sky rendering -/* + // Create overlay used for thunderstorm MaterialPtr material = MaterialManager::getSingleton().create( "ThunderMaterial", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME ); Pass* pass = material->getTechnique(0)->getPass(0); @@ -517,6 +517,7 @@ void SkyManager::create() 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(); @@ -531,6 +532,7 @@ void SkyManager::create() mp->getTechnique(0)->getPass(0)->setPolygonModeOverrideable(false); mStarsMaterials[i] = mp; } + */ // Atmosphere (day) mesh = NifOgre::NIFLoader::load("meshes\\sky_atmosphere.nif"); @@ -543,8 +545,9 @@ void SkyManager::create() atmosphere_ent->setVisibilityFlags(RV_Sky); mAtmosphereDay = mRootNode->createChildSceneNode(); mAtmosphereDay->attachObject(atmosphere_ent); - mAtmosphereMaterial = atmosphere_ent->getSubEntity(0)->getMaterial(); - mAtmosphereMaterial->getTechnique(0)->getPass(0)->setPolygonModeOverrideable(false); + atmosphere_ent->getSubEntity (0)->setMaterialName ("openmw_atmosphere"); + //mAtmosphereMaterial = atmosphere_ent->getSubEntity(0)->getMaterial(); + //mAtmosphereMaterial->getTechnique(0)->getPass(0)->setPolygonModeOverrideable(false); // Atmosphere shader HighLevelGpuProgramPtr vshader = mgr.createProgram("Atmosphere_VP", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, @@ -570,7 +573,7 @@ void SkyManager::create() vshader->load(); vshader->getDefaultParameters()->setNamedAutoConstant("worldViewProj", GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX); - mAtmosphereMaterial->getTechnique(0)->getPass(0)->setVertexProgram(vshader->getName()); + //mAtmosphereMaterial->getTechnique(0)->getPass(0)->setVertexProgram(vshader->getName()); HighLevelGpuProgramPtr fshader = mgr.createProgram("Atmosphere_FP", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "cg", GPT_FRAGMENT_PROGRAM); @@ -598,7 +601,7 @@ void SkyManager::create() fshader->load(); fshader->getDefaultParameters()->setNamedAutoConstant("emissive", GpuProgramParameters::ACT_SURFACE_EMISSIVE_COLOUR); - mAtmosphereMaterial->getTechnique(0)->getPass(0)->setFragmentProgram(fshader->getName()); + // mAtmosphereMaterial->getTechnique(0)->getPass(0)->setFragmentProgram(fshader->getName()); // Clouds NifOgre::NIFLoader::load("meshes\\sky_clouds_01.nif"); @@ -607,8 +610,9 @@ 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(); - mCloudMaterial->getTechnique(0)->getPass(0)->setPolygonModeOverrideable(false); + //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 @@ -635,7 +639,7 @@ void SkyManager::create() vshader2->setSource(outStream3.str()); vshader2->load(); vshader2->getDefaultParameters()->setNamedAutoConstant("worldViewProj", GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX); - mCloudMaterial->getTechnique(0)->getPass(0)->setVertexProgram(vshader2->getName()); + //mCloudMaterial->getTechnique(0)->getPass(0)->setVertexProgram(vshader2->getName()); // Clouds fragment shader mCloudFragmentShader = mgr.createProgram("Clouds_FP", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, @@ -670,17 +674,19 @@ void SkyManager::create() mCloudFragmentShader->setSource(outStream2.str()); mCloudFragmentShader->load(); mCloudFragmentShader->getDefaultParameters()->setNamedAutoConstant("emissive", GpuProgramParameters::ACT_SURFACE_EMISSIVE_COLOUR); - mCloudMaterial->getTechnique(0)->getPass(0)->setFragmentProgram(mCloudFragmentShader->getName()); + //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); - mAtmosphereMaterial = mAtmosphereMaterial->clone("Atmosphere"); - atmosphere_ent->getSubEntity(0)->setMaterial(mAtmosphereMaterial); + //mCloudMaterial = mCloudMaterial->clone("Clouds"); + //clouds_ent->getSubEntity(0)->setMaterial(mCloudMaterial); + //mAtmosphereMaterial = mAtmosphereMaterial->clone("Atmosphere"); + //atmosphere_ent->getSubEntity(0)->setMaterial(mAtmosphereMaterial); + + /* mAtmosphereMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(1.0, 1.0, 1.0); mAtmosphereMaterial->getTechnique(0)->getPass(0)->setDiffuse(0.0, 0.0, 0.0, 0.0); @@ -694,9 +700,9 @@ void SkyManager::create() 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; - */ } SkyManager::~SkyManager() @@ -724,7 +730,7 @@ 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); + //mCloudMaterial->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstantFromTime("time", MWBase::Environment::get().getWorld()->getTimeScaleFactor()/30.f); /// \todo improve this mMasser->setPhase( static_cast( (int) ((mDay % 32)/4.f)) ); @@ -791,12 +797,14 @@ void SkyManager::setMoonColour (bool red) void SkyManager::setCloudsOpacity(float opacity) { if (!mCreated) return; - mCloudMaterial->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("opacity", Real(opacity)); + //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); @@ -857,6 +865,7 @@ void SkyManager::setWeather(const MWWorld::WeatherResult& weather) mStarsOpacity = weather.mNightFade; } } + */ float strength; float timeofday_angle = std::abs(mSunGlare->getPosition().z/mSunGlare->getPosition().length()); diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 164b51daf..76562256f 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -34,6 +34,7 @@ #include #include +#include #include diff --git a/extern/shiny b/extern/shiny index ccaaefa59..1d689a23f 160000 --- a/extern/shiny +++ b/extern/shiny @@ -1 +1 @@ -Subproject commit ccaaefa59c0500cf790a1f3114c8b5593489afeb +Subproject commit 1d689a23fa685ab680351219c32953a3bed7ac0c diff --git a/files/materials/atmosphere.shader b/files/materials/atmosphere.shader index e69de29bb..a772e3c5e 100644 --- a/files/materials/atmosphere.shader +++ b/files/materials/atmosphere.shader @@ -0,0 +1,38 @@ +#include "core.h" + +#define MRT @shPropertyBool(mrt_output) + +#ifdef SH_VERTEX_SHADER + + SH_BEGIN_PROGRAM + shUniform(float4x4 wvp) @shAutoConstant(wvp, worldviewproj_matrix) + shInput(float2, uv0) + shOutput(float2, UV) + + SH_START_PROGRAM + { + shOutputPosition = shMatrixMult(wvp, shInputPosition); + UV = uv0; + } + +#else + + SH_BEGIN_PROGRAM + shSampler2D(diffuseMap) + shInput(float2, UV) +#if MRT + shDeclareMrtOutput(1) +#endif + shUniform(float4 materialDiffuse) @shAutoConstant(materialDiffuse, surface_diffuse_colour) + shUniform(float4 materialEmissive) @shAutoConstant(materialEmissive, surface_emissive_colour) + + SH_START_PROGRAM + { + shOutputColor(0) = float4(1,1,1,materialDiffuse.a) * float4(materialEmissive.xyz, 1) * shSample(diffuseMap, UV); + +#if MRT + shOutputColor(1) = float4(1,1,1,1); +#endif + } + +#endif diff --git a/files/materials/atmosphere.shaderset b/files/materials/atmosphere.shaderset index e69de29bb..54108dbba 100644 --- a/files/materials/atmosphere.shaderset +++ b/files/materials/atmosphere.shaderset @@ -0,0 +1,15 @@ +shader_set atmosphere_vertex +{ + source atmosphere.shader + type vertex + profiles_cg vs_2_0 arbvp1 + profiles_hlsl vs_2_0 +} + +shader_set atmosphere_fragment +{ + source atmosphere.shader + type fragment + profiles_cg ps_2_x ps_2_0 ps arbfp1 + profiles_hlsl ps_2_0 +} diff --git a/files/materials/clouds.shader b/files/materials/clouds.shader index e69de29bb..a772e3c5e 100644 --- a/files/materials/clouds.shader +++ b/files/materials/clouds.shader @@ -0,0 +1,38 @@ +#include "core.h" + +#define MRT @shPropertyBool(mrt_output) + +#ifdef SH_VERTEX_SHADER + + SH_BEGIN_PROGRAM + shUniform(float4x4 wvp) @shAutoConstant(wvp, worldviewproj_matrix) + shInput(float2, uv0) + shOutput(float2, UV) + + SH_START_PROGRAM + { + shOutputPosition = shMatrixMult(wvp, shInputPosition); + UV = uv0; + } + +#else + + SH_BEGIN_PROGRAM + shSampler2D(diffuseMap) + shInput(float2, UV) +#if MRT + shDeclareMrtOutput(1) +#endif + shUniform(float4 materialDiffuse) @shAutoConstant(materialDiffuse, surface_diffuse_colour) + shUniform(float4 materialEmissive) @shAutoConstant(materialEmissive, surface_emissive_colour) + + SH_START_PROGRAM + { + shOutputColor(0) = float4(1,1,1,materialDiffuse.a) * float4(materialEmissive.xyz, 1) * shSample(diffuseMap, UV); + +#if MRT + shOutputColor(1) = float4(1,1,1,1); +#endif + } + +#endif diff --git a/files/materials/clouds.shaderset b/files/materials/clouds.shaderset index e69de29bb..5fffb5658 100644 --- a/files/materials/clouds.shaderset +++ b/files/materials/clouds.shaderset @@ -0,0 +1,15 @@ +shader_set clouds_vertex +{ + source clouds.shader + type vertex + profiles_cg vs_2_0 arbvp1 + profiles_hlsl vs_2_0 +} + +shader_set clouds_fragment +{ + source clouds.shader + type fragment + profiles_cg ps_2_x ps_2_0 ps arbfp1 + profiles_hlsl ps_2_0 +} diff --git a/files/materials/objects.mat b/files/materials/objects.mat index fc23b947a..6dfe9db7c 100644 --- a/files/materials/objects.mat +++ b/files/materials/objects.mat @@ -39,7 +39,7 @@ material openmw_objects_base texture_unit diffuseMap { - texture $diffuseMap + direct_texture $diffuseMap create_in_ffp true } } diff --git a/files/materials/objects.shader b/files/materials/objects.shader index 6dd05442c..e066b43cc 100644 --- a/files/materials/objects.shader +++ b/files/materials/objects.shader @@ -64,7 +64,9 @@ shInput(float, depthPassthrough) #endif +#if MRT shUniform(float far) @shAutoConstant(far, far_clip_distance) +#endif #if LIGHTING shInput(float3, normalPassthrough) @@ -109,12 +111,16 @@ 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); @shEndForeach + +#if HAS_VERTEXCOLOR + ambient *= colorPassthrough.xyz; +#endif shOutputColor(0).xyz *= (ambient + diffuse + materialEmissive.xyz); #endif -#if HAS_VERTEXCOLOR +#if HAS_VERTEXCOLOR && !LIGHTING shOutputColor(0).xyz *= colorPassthrough.xyz; #endif @@ -123,6 +129,9 @@ shOutputColor(0).xyz = shLerp (shOutputColor(0).xyz, fogColor, fogValue); #endif + // prevent negative color output (for example with negative lights) + shOutputColor(0).xyz = max(shOutputColor(0).xyz, float3(0,0,0)); + #if MRT shOutputColor(1) = float4(depthPassthrough / far,1,1,1); #endif diff --git a/files/materials/sky.mat b/files/materials/sky.mat index a82816438..25c9185b7 100644 --- a/files/materials/sky.mat +++ b/files/materials/sky.mat @@ -1,10 +1,18 @@ material openmw_moon { + mrt_output true pass { vertex_program moon_vertex fragment_program moon_fragment + polygon_mode_overrideable off + + shader_properties + { + mrt_output $mrt_output + } + texture_unit diffuseMap { texture $diffuseMap @@ -15,10 +23,21 @@ material openmw_moon material openmw_clouds { + mrt_output true pass { vertex_program clouds_vertex fragment_program clouds_fragment + + polygon_mode_overrideable off + + scene_blend alpha_blend + depth_write off + + shader_properties + { + mrt_output $mrt_output + } // second diffuse map is used for weather transitions texture_unit diffuseMap1 @@ -36,19 +55,38 @@ material openmw_clouds material openmw_atmosphere { + mrt_output true pass { vertex_program atmosphere_vertex fragment_program atmosphere_fragment + + polygon_mode_overrideable off + + scene_blend alpha_blend + depth_write off + + shader_properties + { + mrt_output $mrt_output + } } } material openmw_stars { + mrt_output true pass { vertex_program stars_vertex fragment_program stars_fragment + + polygon_mode_overrideable off + + shader_properties + { + mrt_output $mrt_output + } texture_unit diffuseMap { @@ -60,10 +98,18 @@ material openmw_stars // used for both sun and sun glare material openmw_sun { + mrt_output true pass { vertex_program sun_vertex fragment_program sun_fragment + + polygon_mode_overrideable off + + shader_properties + { + mrt_output $mrt_output + } texture unit diffuseMap { diff --git a/files/materials/sun.shader b/files/materials/sun.shader index e69de29bb..811d45031 100644 --- a/files/materials/sun.shader +++ b/files/materials/sun.shader @@ -0,0 +1,39 @@ +#include "core.h" + +#define MRT @shPropertyBool(mrt_output) + + +#ifdef SH_VERTEX_SHADER + + SH_BEGIN_PROGRAM + shUniform(float4x4 wvp) @shAutoConstant(wvp, worldviewproj_matrix) + shInput(float2, uv0) + shOutput(float2, UV) + + SH_START_PROGRAM + { + shOutputPosition = shMatrixMult(wvp, shInputPosition); + UV = uv0; + } + +#else + + SH_BEGIN_PROGRAM + shSampler2D(diffuseMap) + shInput(float2, UV) +#if MRT + shDeclareMrtOutput(1) +#endif + shUniform(float4 materialDiffuse) @shAutoConstant(materialDiffuse, surface_diffuse_colour) + shUniform(float4 materialEmissive) @shAutoConstant(materialEmissive, surface_emissive_colour) + + SH_START_PROGRAM + { + shOutputColor(0) = float4(1,1,1,materialDiffuse.a) * float4(materialEmissive.xyz, 1) * shSample(diffuseMap, UV); + +#if MRT + shOutputColor(1) = float4(1,1,1,1); +#endif + } + +#endif diff --git a/files/materials/sun.shaderset b/files/materials/sun.shaderset index e69de29bb..1b9e92a43 100644 --- a/files/materials/sun.shaderset +++ b/files/materials/sun.shaderset @@ -0,0 +1,15 @@ +shader_set sun_vertex +{ + source sun.shader + type vertex + profiles_cg vs_2_0 arbvp1 + profiles_hlsl vs_2_0 +} + +shader_set sun_fragment +{ + source sun.shader + type fragment + profiles_cg ps_2_x ps_2_0 ps arbfp1 + profiles_hlsl ps_2_0 +}