mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 18:19:55 +00:00
Transparent water
This commit is contained in:
parent
8798f7dd40
commit
ff2bbc9fc5
8 changed files with 380 additions and 18 deletions
|
@ -310,7 +310,13 @@ void OMW::Engine::go()
|
|||
|
||||
// This has to be added BEFORE MyGUI is initialized, as it needs
|
||||
// to find core.xml here.
|
||||
std::cout << "Before the water\n";
|
||||
|
||||
std::cout << "After the water" << mResDir << "\n";
|
||||
//addResourcesDirectory(mResDir);
|
||||
|
||||
addResourcesDirectory(mResDir / "mygui");
|
||||
addResourcesDirectory(mResDir / "water");
|
||||
|
||||
// Create the window
|
||||
mOgre->createWindow("OpenMW");
|
||||
|
|
|
@ -57,6 +57,7 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const
|
|||
cameraPitchNode->attachObject(rend.getCamera());
|
||||
|
||||
mPlayer = new MWRender::Player (rend.getCamera(), playerNode);
|
||||
mWater = new MWRender::Water(rend.getCamera());
|
||||
|
||||
//std::cout << "Three";
|
||||
}
|
||||
|
@ -220,6 +221,9 @@ void RenderingManager::toggleLight()
|
|||
|
||||
setAmbientMode();
|
||||
}
|
||||
void RenderingManager::checkUnderwater(){
|
||||
mWater->checkUnderwater();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "creatures.hpp"
|
||||
#include "objects.hpp"
|
||||
#include "player.hpp"
|
||||
#include "water.hpp"
|
||||
|
||||
namespace Ogre
|
||||
{
|
||||
|
@ -69,6 +70,7 @@ class RenderingManager: private RenderingInterface {
|
|||
void moveObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& position);
|
||||
void scaleObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& scale);
|
||||
void rotateObject (const MWWorld::Ptr& ptr, const::Ogre::Quaternion& orientation);
|
||||
void checkUnderwater();
|
||||
|
||||
/// \param store Cell the object was in previously (\a ptr has already been updated to the new cell).
|
||||
void moveObjectToCell (const MWWorld::Ptr& ptr, const Ogre::Vector3& position, MWWorld::Ptr::CellStore *store);
|
||||
|
@ -100,6 +102,7 @@ class RenderingManager: private RenderingInterface {
|
|||
Ogre::Camera* camera;
|
||||
MWRender::Npcs npcs;
|
||||
MWRender::Creatures creatures;
|
||||
MWRender::Water *mWater;
|
||||
MWRender::Objects objects;
|
||||
|
||||
// 0 normal, 1 more bright, 2 max
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace MWRender {
|
||||
Water::Water (Ogre::Camera *camera) : mCamera (camera), mViewport (camera->getViewport()), mSceneManager (camera->getSceneManager()) {
|
||||
|
||||
std::cout << "1\n";
|
||||
try {
|
||||
Ogre::CompositorManager::getSingleton().addCompositor(mViewport, "Water", -1);
|
||||
Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Water", false);
|
||||
|
@ -11,26 +11,14 @@ namespace MWRender {
|
|||
mIsUnderwater = false;
|
||||
|
||||
mCamera->addListener(this);
|
||||
|
||||
|
||||
for (unsigned int i = 0; i < 2; i++) {
|
||||
Ogre::TexturePtr tex = Ogre::TextureManager::getSingleton().createManual(i == 0 ? "refraction" : "reflection", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, 512, 512, 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET);
|
||||
|
||||
Ogre::RenderTarget* rtt = tex->getBuffer()->getRenderTarget();
|
||||
rtt->addViewport(mCamera)->setOverlaysEnabled(false);
|
||||
rtt->addListener(this);
|
||||
|
||||
if (i == 0) mRefractionTarget = rtt;
|
||||
else mReflectionTarget = rtt;
|
||||
}
|
||||
|
||||
|
||||
mWaterPlane = Ogre::Plane(Ogre::Vector3::UNIT_Y, 0);
|
||||
Ogre::MeshManager::getSingleton().createPlane("water", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, mWaterPlane, 7000, 7000, 10, 10, true, 1, 3, 5, Ogre::Vector3::UNIT_Z);
|
||||
|
||||
Ogre::MeshManager::getSingleton().createPlane("water", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, mWaterPlane, 7000, 7000, 1, 1, true, 1, 3,5, Ogre::Vector3::UNIT_Z);
|
||||
|
||||
mWater = mSceneManager->createEntity("Water", "water");
|
||||
mWater->setMaterialName("Water/ReflectionRefraction");
|
||||
mWater->setMaterialName("Examples/Water0");
|
||||
|
||||
mWaterNode = mSceneManager->getRootSceneNode()->createChildSceneNode();
|
||||
mWaterNode->attachObject(mWater);
|
||||
|
||||
|
@ -39,8 +27,8 @@ namespace MWRender {
|
|||
|
||||
Water::~Water() {
|
||||
Ogre::MeshManager::getSingleton().remove("water");
|
||||
Ogre::TextureManager::getSingleton().remove("refraction");
|
||||
Ogre::TextureManager::getSingleton().remove("reflection");
|
||||
//Ogre::TextureManager::getSingleton().remove("refraction");
|
||||
//Ogre::TextureManager::getSingleton().remove("reflection");
|
||||
Ogre::CompositorManager::getSingleton().removeCompositorChain(mViewport);
|
||||
}
|
||||
|
||||
|
|
|
@ -525,6 +525,7 @@ namespace MWWorld
|
|||
|
||||
if (ptr==mPlayer->getPlayer())
|
||||
{
|
||||
mRendering.checkUnderwater();
|
||||
Ptr::CellStore *currentCell = mWorldScene->getCurrentCell();
|
||||
if (currentCell)
|
||||
{
|
||||
|
|
321
files/water/Examples-Water.material
Normal file
321
files/water/Examples-Water.material
Normal file
|
@ -0,0 +1,321 @@
|
|||
vertex_program Water/Test cg
|
||||
{
|
||||
source water1.cg
|
||||
entry_point main
|
||||
profiles vs_1_1 arbvp1
|
||||
|
||||
}
|
||||
vertex_program Water/GlassVP cg
|
||||
{
|
||||
source GlassVP.cg
|
||||
entry_point glass_vp
|
||||
profiles vs_1_1 arbvp1
|
||||
|
||||
default_params
|
||||
{
|
||||
param_named_auto worldViewProj worldviewproj_matrix
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fragment_program Water/GlassFP cg
|
||||
{
|
||||
source GlassFP.cg
|
||||
entry_point main_ps
|
||||
profiles ps_2_0 arbfp1
|
||||
}
|
||||
|
||||
material Water/Compositor
|
||||
{
|
||||
technique
|
||||
{
|
||||
pass
|
||||
{
|
||||
depth_check off
|
||||
|
||||
vertex_program_ref Water/GlassVP
|
||||
{
|
||||
param_named_auto timeVal time 0.25
|
||||
param_named scale float 0.1
|
||||
}
|
||||
|
||||
fragment_program_ref Water/GlassFP
|
||||
{
|
||||
param_named tintColour float4 0 0.35 0.35 1
|
||||
}
|
||||
|
||||
texture_unit RT
|
||||
{
|
||||
tex_coord_set 0
|
||||
tex_address_mode clamp
|
||||
filtering linear linear linear
|
||||
}
|
||||
|
||||
texture_unit
|
||||
{
|
||||
texture WaterNormal1.tga 2d
|
||||
tex_coord_set 1
|
||||
//tex_address_mode clamp
|
||||
filtering linear linear linear
|
||||
}
|
||||
texture_unit
|
||||
{
|
||||
texture caustic_0.png 2d
|
||||
tex_coord_set 2
|
||||
//tex_address_mode clamp
|
||||
filtering linear linear linear
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
vertex_program Water/RefractReflectVP cg
|
||||
{
|
||||
source Example_Fresnel.cg
|
||||
entry_point main_vp
|
||||
profiles vs_1_1 arbvp1
|
||||
}
|
||||
vertex_program Water/RefractReflectVPold cg
|
||||
{
|
||||
source Example_Fresnel.cg
|
||||
entry_point main_vp_old
|
||||
profiles vs_1_1 arbvp1
|
||||
}
|
||||
|
||||
fragment_program Water/RefractReflectFP cg
|
||||
{
|
||||
source Example_Fresnel.cg
|
||||
entry_point main_fp
|
||||
// sorry, ps_1_1 and fp20 can't do this
|
||||
profiles ps_2_0 arbfp1
|
||||
}
|
||||
|
||||
fragment_program Water/RefractReflectPS asm
|
||||
{
|
||||
source Example_FresnelPS.asm
|
||||
// sorry, only for ps_1_4 :)
|
||||
syntax ps_1_4
|
||||
|
||||
}
|
||||
material Examples/Water0
|
||||
{
|
||||
|
||||
technique
|
||||
{
|
||||
pass
|
||||
{
|
||||
//
|
||||
|
||||
|
||||
vertex_program_ref Water/RefractReflectVP
|
||||
{
|
||||
param_named_auto worldViewProjMatrix worldviewproj_matrix
|
||||
param_named_auto eyePosition camera_position_object_space
|
||||
param_named_auto timeVal time 0.15
|
||||
param_named scroll float 1
|
||||
param_named scale float 1
|
||||
param_named noise float 1
|
||||
// scroll and noisePos will need updating per frame
|
||||
}
|
||||
fragment_program_ref Water/RefractReflectFP
|
||||
{
|
||||
param_named fresnelBias float -0.1
|
||||
param_named fresnelScale float 0.8
|
||||
param_named fresnelPower float 20
|
||||
param_named tintColour float4 1 1 1 1
|
||||
param_named noiseScale float 0.05
|
||||
}
|
||||
// Water
|
||||
scene_blend alpha_blend
|
||||
texture_unit
|
||||
{
|
||||
|
||||
// Water texture
|
||||
texture Water02.jpg
|
||||
// min / mag filtering, no mip
|
||||
filtering linear linear none
|
||||
colour_op_ex source1 src_manual src_current 0 1 0
|
||||
alpha_op_ex source1 src_manual src_current 0.1
|
||||
|
||||
}
|
||||
// Noise
|
||||
texture_unit
|
||||
{
|
||||
colour_op_ex source1 src_manual src_current 0 1 0
|
||||
alpha_op_ex source1 src_manual src_current 0.1
|
||||
// Perlin noise volume
|
||||
texture waves2.dds
|
||||
// min / mag filtering, no mip
|
||||
filtering linear linear none
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
material Examples/Water1
|
||||
{
|
||||
technique
|
||||
{
|
||||
pass
|
||||
{
|
||||
scene_blend colour_blend
|
||||
depth_write off
|
||||
|
||||
texture_unit
|
||||
{
|
||||
texture BeachStones.jpg
|
||||
scale 0.25 0.25
|
||||
}
|
||||
|
||||
texture_unit
|
||||
{
|
||||
texture Water01.jpg
|
||||
env_map spherical
|
||||
scroll_anim 0.01 0.01
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
material Examples/Water2
|
||||
{
|
||||
technique
|
||||
{
|
||||
pass
|
||||
{
|
||||
scene_blend colour_blend
|
||||
depth_write off
|
||||
|
||||
texture_unit
|
||||
{
|
||||
texture Water01.jpg
|
||||
scroll_anim 0.01 0.01
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
material Examples/Water3
|
||||
{
|
||||
technique
|
||||
{
|
||||
pass
|
||||
{
|
||||
scene_blend colour_blend
|
||||
depth_write off
|
||||
|
||||
texture_unit
|
||||
{
|
||||
texture Water02.jpg
|
||||
env_map spherical
|
||||
scroll_anim 0.01 0.01
|
||||
rotate_anim 0.03
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
material Examples/Water4
|
||||
{
|
||||
technique
|
||||
{
|
||||
pass
|
||||
{
|
||||
cull_hardware none
|
||||
cull_software none
|
||||
|
||||
texture_unit
|
||||
{
|
||||
texture Water02.jpg
|
||||
env_map spherical
|
||||
scroll_anim 0.01 0.01
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
material Examples/Water5
|
||||
{
|
||||
technique
|
||||
{
|
||||
pass
|
||||
{
|
||||
cull_hardware none
|
||||
cull_software none
|
||||
|
||||
texture_unit
|
||||
{
|
||||
texture BeachStones.jpg
|
||||
scale 0.25 0.25
|
||||
}
|
||||
|
||||
texture_unit
|
||||
{
|
||||
texture Water01.jpg
|
||||
env_map spherical
|
||||
scroll_anim 0.01 0.01
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
material Examples/Water6
|
||||
{
|
||||
technique
|
||||
{
|
||||
pass
|
||||
{
|
||||
lighting off
|
||||
|
||||
texture_unit
|
||||
{
|
||||
cubic_texture cubescene.jpg combinedUVW
|
||||
tex_address_mode clamp
|
||||
env_map cubic_reflection
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
material Examples/Water7
|
||||
{
|
||||
technique
|
||||
{
|
||||
pass
|
||||
{
|
||||
cull_hardware none
|
||||
cull_software none
|
||||
|
||||
texture_unit
|
||||
{
|
||||
texture BeachStones.jpg
|
||||
scale 0.25 0.25
|
||||
}
|
||||
|
||||
texture_unit
|
||||
{
|
||||
cubic_texture cubescene.jpg combinedUVW
|
||||
tex_address_mode clamp
|
||||
env_map cubic_reflection
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
material Examples/Water8
|
||||
{
|
||||
technique
|
||||
{
|
||||
pass
|
||||
{
|
||||
lighting off
|
||||
scene_blend add
|
||||
depth_write off
|
||||
cull_hardware none
|
||||
cull_software none
|
||||
|
||||
texture_unit
|
||||
{
|
||||
cubic_texture cubescene.jpg combinedUVW
|
||||
tex_address_mode clamp
|
||||
env_map cubic_reflection
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
BIN
files/water/Water01.jpg
Normal file
BIN
files/water/Water01.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 288 KiB |
39
files/water/water1.cg
Normal file
39
files/water/water1.cg
Normal file
|
@ -0,0 +1,39 @@
|
|||
void main( in float4 fresnel : COLOR0,
|
||||
in float4 inTex0 : TEXCOORD0,
|
||||
in float4 inTex1 : TEXCOORD1,
|
||||
in float4 inTex2 : TEXCOORD2,
|
||||
in float4 inTex3 : TEXCOORD3,
|
||||
in float4 inTex4 : COLOR1,
|
||||
in float4 inTex5 : BCOL1,
|
||||
out float4 outCol : COLOR,
|
||||
uniform float4 matrix,
|
||||
uniform sampler2D offsetTexture : texunit0,
|
||||
uniform sampler2D reflexTexture : texunit1,
|
||||
uniform sampler2D refractTexture : texunit2,
|
||||
uniform sampler2D depthTexture : texunit3)
|
||||
{
|
||||
float4 norm = tex2D(offsetTexture, inTex0.xy);
|
||||
float4 refr = tex2D(depthTexture, inTex3.xy);
|
||||
|
||||
float4 norm2 = tex2D(offsetTexture, inTex0.xy/10.0f);
|
||||
|
||||
float4 projCoord = inTex1 / inTex1.w;
|
||||
projCoord = (projCoord + 1.0) * 0.5;
|
||||
projCoord += norm * 0.02;
|
||||
projCoord = clamp(projCoord, 0.001, 0.999);
|
||||
|
||||
float4 reflexe = tex2D(reflexTexture, projCoord.xy);
|
||||
float4 refrakce = tex2D(refractTexture, projCoord.xy);
|
||||
|
||||
float4 odrazy = reflexe*(0.7+0.3*refr);
|
||||
|
||||
reflexe = (float4(0,0.4,0.4,1.0) + reflexe*0.5);
|
||||
|
||||
outCol = lerp(refrakce, reflexe, fresnel.r)-refr*0.08;
|
||||
|
||||
//outCol = lerp(refrakce, reflexe, fresnel.r);
|
||||
|
||||
// outCol = norm;
|
||||
|
||||
outCol.a = 1;
|
||||
}
|
Loading…
Reference in a new issue