basic noise

actorid
scrawl 13 years ago
parent fe63f2b2aa
commit cc4076d42a

@ -185,7 +185,7 @@ void RenderingManager::update (float duration){
void RenderingManager::waterAdded (MWWorld::Ptr::CellStore *store){
if(store->cell->data.flags & store->cell->HasWater){
if(mWater == 0)
mWater = new MWRender::Water(mRendering.getCamera(), store->cell);
mWater = new MWRender::Water(mRendering.getCamera(), mSkyManager, store->cell);
else
mWater->changeCell(store->cell);
mWater->setActive(true);

@ -1,16 +1,19 @@
#include "water.hpp"
#include <components/settings/settings.hpp>
#include "sky.hpp"
using namespace Ogre;
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()),
mIsUnderwater(false), mReflectDistance(0), mVisibilityFlags(0), mOldCameraFarClip(0),
mReflectionTarget(0), mActive(1)
{
mSky = sky;
try
{
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_Actors * Settings::Manager::getBool("reflect actors", "Water")
+ RV_Misc * Settings::Manager::getBool("reflect misc", "Water");
//+ RV_Sky;
mReflectDistance = Settings::Manager::getInt("reflect distance", "Water");
mWaterNode = mSceneManager->getRootSceneNode()->createChildSceneNode();
@ -44,7 +48,7 @@ Water::Water (Ogre::Camera *camera, const ESM::Cell* cell) :
}
mWaterNode->attachObject(mWater);
// Create rendertargets for reflection and refraction
// Create rendertarget for reflection
int rttsize = Settings::Manager::getInt("rtt size", "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);
// use technique without shaders if reflection is disabled
if (mReflectionTarget == 0)
mat->removeTechnique(0);
return mat;
}

@ -8,6 +8,8 @@
namespace MWRender {
class SkyManager;
/// Water rendering
class Water : Ogre::RenderTargetListener
{
@ -30,6 +32,8 @@ namespace MWRender {
void preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt);
void postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt);
SkyManager* mSky;
Ogre::MaterialPtr createMaterial();
Ogre::RenderTarget* mReflectionTarget;
@ -39,7 +43,7 @@ namespace MWRender {
int mOldCameraFarClip;
public:
Water (Ogre::Camera *camera, const ESM::Cell* cell);
Water (Ogre::Camera *camera, SkyManager* sky, const ESM::Cell* cell);
~Water();
void setActive(bool active);

@ -48,9 +48,6 @@ reflection = false
rtt size = 256
# 0 unlimited
reflect distance = 0
reflect terrain = true
reflect statics = true

@ -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
{
param_named_auto time time 0.1
}
texture_unit reflectionMap
{
texture WaterReflection
tex_address_mode clamp
}
texture_unit normalMap
{
texture WaterNormal2.tga
}
}
}

Loading…
Cancel
Save