mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-03 10:20:10 +00:00
basic noise
This commit is contained in:
parent
fe63f2b2aa
commit
cc4076d42a
apps/openmw/mwrender
files
@ -185,7 +185,7 @@ void RenderingManager::update (float duration){
|
|||||||
void RenderingManager::waterAdded (MWWorld::Ptr::CellStore *store){
|
void RenderingManager::waterAdded (MWWorld::Ptr::CellStore *store){
|
||||||
if(store->cell->data.flags & store->cell->HasWater){
|
if(store->cell->data.flags & store->cell->HasWater){
|
||||||
if(mWater == 0)
|
if(mWater == 0)
|
||||||
mWater = new MWRender::Water(mRendering.getCamera(), store->cell);
|
mWater = new MWRender::Water(mRendering.getCamera(), mSkyManager, store->cell);
|
||||||
else
|
else
|
||||||
mWater->changeCell(store->cell);
|
mWater->changeCell(store->cell);
|
||||||
mWater->setActive(true);
|
mWater->setActive(true);
|
||||||
|
@ -1,16 +1,19 @@
|
|||||||
#include "water.hpp"
|
#include "water.hpp"
|
||||||
#include <components/settings/settings.hpp>
|
#include <components/settings/settings.hpp>
|
||||||
|
#include "sky.hpp"
|
||||||
|
|
||||||
using namespace Ogre;
|
using namespace Ogre;
|
||||||
|
|
||||||
namespace MWRender
|
namespace MWRender
|
||||||
{
|
{
|
||||||
|
|
||||||
Water::Water (Ogre::Camera *camera, const ESM::Cell* cell) :
|
Water::Water (Ogre::Camera *camera, SkyManager* sky, const ESM::Cell* cell) :
|
||||||
mCamera (camera), mViewport (camera->getViewport()), mSceneManager (camera->getSceneManager()),
|
mCamera (camera), mViewport (camera->getViewport()), mSceneManager (camera->getSceneManager()),
|
||||||
mIsUnderwater(false), mReflectDistance(0), mVisibilityFlags(0), mOldCameraFarClip(0),
|
mIsUnderwater(false), mReflectDistance(0), mVisibilityFlags(0), mOldCameraFarClip(0),
|
||||||
mReflectionTarget(0), mActive(1)
|
mReflectionTarget(0), mActive(1)
|
||||||
{
|
{
|
||||||
|
mSky = sky;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
CompositorManager::getSingleton().addCompositor(mViewport, "Water", -1);
|
CompositorManager::getSingleton().addCompositor(mViewport, "Water", -1);
|
||||||
@ -33,6 +36,7 @@ Water::Water (Ogre::Camera *camera, const ESM::Cell* cell) :
|
|||||||
+ RV_StaticsSmall * Settings::Manager::getBool("reflect small statics", "Water")
|
+ RV_StaticsSmall * Settings::Manager::getBool("reflect small statics", "Water")
|
||||||
+ RV_Actors * Settings::Manager::getBool("reflect actors", "Water")
|
+ RV_Actors * Settings::Manager::getBool("reflect actors", "Water")
|
||||||
+ RV_Misc * Settings::Manager::getBool("reflect misc", "Water");
|
+ RV_Misc * Settings::Manager::getBool("reflect misc", "Water");
|
||||||
|
//+ RV_Sky;
|
||||||
mReflectDistance = Settings::Manager::getInt("reflect distance", "Water");
|
mReflectDistance = Settings::Manager::getInt("reflect distance", "Water");
|
||||||
|
|
||||||
mWaterNode = mSceneManager->getRootSceneNode()->createChildSceneNode();
|
mWaterNode = mSceneManager->getRootSceneNode()->createChildSceneNode();
|
||||||
@ -44,7 +48,7 @@ Water::Water (Ogre::Camera *camera, const ESM::Cell* cell) :
|
|||||||
}
|
}
|
||||||
mWaterNode->attachObject(mWater);
|
mWaterNode->attachObject(mWater);
|
||||||
|
|
||||||
// Create rendertargets for reflection and refraction
|
// Create rendertarget for reflection
|
||||||
int rttsize = Settings::Manager::getInt("rtt size", "Water");
|
int rttsize = Settings::Manager::getInt("rtt size", "Water");
|
||||||
|
|
||||||
if (Settings::Manager::getBool("reflection", "Water"))
|
if (Settings::Manager::getBool("reflection", "Water"))
|
||||||
@ -172,6 +176,10 @@ Ogre::MaterialPtr Water::createMaterial()
|
|||||||
}
|
}
|
||||||
mat->getTechnique(1)->getPass(0)->getTextureUnitState(0)->setAnimatedTextureName(textureNames, 32, 2);
|
mat->getTechnique(1)->getPass(0)->getTextureUnitState(0)->setAnimatedTextureName(textureNames, 32, 2);
|
||||||
|
|
||||||
|
// use technique without shaders if reflection is disabled
|
||||||
|
if (mReflectionTarget == 0)
|
||||||
|
mat->removeTechnique(0);
|
||||||
|
|
||||||
return mat;
|
return mat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
namespace MWRender {
|
namespace MWRender {
|
||||||
|
|
||||||
|
class SkyManager;
|
||||||
|
|
||||||
/// Water rendering
|
/// Water rendering
|
||||||
class Water : Ogre::RenderTargetListener
|
class Water : Ogre::RenderTargetListener
|
||||||
{
|
{
|
||||||
@ -30,6 +32,8 @@ namespace MWRender {
|
|||||||
void preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt);
|
void preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt);
|
||||||
void postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt);
|
void postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt);
|
||||||
|
|
||||||
|
SkyManager* mSky;
|
||||||
|
|
||||||
Ogre::MaterialPtr createMaterial();
|
Ogre::MaterialPtr createMaterial();
|
||||||
|
|
||||||
Ogre::RenderTarget* mReflectionTarget;
|
Ogre::RenderTarget* mReflectionTarget;
|
||||||
@ -39,7 +43,7 @@ namespace MWRender {
|
|||||||
int mOldCameraFarClip;
|
int mOldCameraFarClip;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Water (Ogre::Camera *camera, const ESM::Cell* cell);
|
Water (Ogre::Camera *camera, SkyManager* sky, const ESM::Cell* cell);
|
||||||
~Water();
|
~Water();
|
||||||
|
|
||||||
void setActive(bool active);
|
void setActive(bool active);
|
||||||
|
@ -48,9 +48,6 @@ reflection = false
|
|||||||
|
|
||||||
rtt size = 256
|
rtt size = 256
|
||||||
|
|
||||||
# 0 unlimited
|
|
||||||
reflect distance = 0
|
|
||||||
|
|
||||||
reflect terrain = true
|
reflect terrain = true
|
||||||
|
|
||||||
reflect statics = true
|
reflect statics = true
|
||||||
|
56
files/water/water.cg
Normal file
56
files/water/water.cg
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
void main_vp
|
||||||
|
(
|
||||||
|
in float4 iPos : POSITION
|
||||||
|
, in float2 iUv : TEXCOORD0
|
||||||
|
|
||||||
|
, out float4 oPos : POSITION
|
||||||
|
, out float3 oScreenCoords : TEXCOORD0
|
||||||
|
, out float2 oUv : TEXCOORD1
|
||||||
|
|
||||||
|
, uniform float4x4 wvpMat
|
||||||
|
)
|
||||||
|
{
|
||||||
|
oPos = mul(wvpMat, iPos);
|
||||||
|
|
||||||
|
oUv = iUv * 10; // uv scale
|
||||||
|
|
||||||
|
float4x4 scalemat = float4x4( 0.5, 0, 0, 0.5,
|
||||||
|
0, -0.5, 0, 0.5,
|
||||||
|
0, 0, 0.5, 0.5,
|
||||||
|
0, 0, 0, 1 );
|
||||||
|
float4 texcoordProj = mul(scalemat, oPos);
|
||||||
|
oScreenCoords = float3(texcoordProj.x, texcoordProj.y, texcoordProj.w);
|
||||||
|
}
|
||||||
|
|
||||||
|
void main_fp
|
||||||
|
(
|
||||||
|
out float4 oColor : COLOR
|
||||||
|
|
||||||
|
, in float3 iScreenCoords : TEXCOORD0
|
||||||
|
, in float2 iUv : TEXCOORD1
|
||||||
|
, uniform float renderTargetFlipping
|
||||||
|
|
||||||
|
, uniform sampler2D reflectionMap : register(s0)
|
||||||
|
, uniform sampler2D normalMap : register(s1)
|
||||||
|
, uniform float time
|
||||||
|
)
|
||||||
|
{
|
||||||
|
|
||||||
|
float2 screenCoords = iScreenCoords.xy / iScreenCoords.z;
|
||||||
|
screenCoords.y = (renderTargetFlipping == -1) ? (1-screenCoords.y) : screenCoords.y;
|
||||||
|
|
||||||
|
float2 uv1 = iUv + time * float2(0.5, 0);
|
||||||
|
float2 uv2 = iUv + time * float2(0, 0.5);
|
||||||
|
float2 uv3 = iUv + time * float2(-0.5, 0);
|
||||||
|
float2 uv4 = iUv + time * float2(0, -0.5);
|
||||||
|
|
||||||
|
float4 normal = tex2D(normalMap, uv1) + tex2D(normalMap, uv2) + tex2D(normalMap, uv3) + tex2D(normalMap, uv4);
|
||||||
|
normal = normal / 4.f;
|
||||||
|
normal = 2*normal - 1;
|
||||||
|
screenCoords += normal.yx * 0.05;
|
||||||
|
|
||||||
|
float4 reflection = tex2D(reflectionMap, screenCoords);
|
||||||
|
|
||||||
|
oColor.xyz = reflection.xyz;
|
||||||
|
oColor.a = 0.45;
|
||||||
|
}
|
@ -51,11 +51,17 @@ material Water
|
|||||||
}
|
}
|
||||||
fragment_program_ref Water_FP
|
fragment_program_ref Water_FP
|
||||||
{
|
{
|
||||||
|
param_named_auto time time 0.1
|
||||||
}
|
}
|
||||||
|
|
||||||
texture_unit reflectionMap
|
texture_unit reflectionMap
|
||||||
{
|
{
|
||||||
texture WaterReflection
|
texture WaterReflection
|
||||||
|
tex_address_mode clamp
|
||||||
|
}
|
||||||
|
texture_unit normalMap
|
||||||
|
{
|
||||||
|
texture WaterNormal2.tga
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user