mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 19:19:56 +00:00
underwater depth effect
This commit is contained in:
parent
456eb95209
commit
c0f991ac0a
7 changed files with 87 additions and 60 deletions
|
@ -59,9 +59,9 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const
|
|||
{
|
||||
CompositorManager::getSingleton().addCompositor(mRendering.getViewport(), "gbuffer");
|
||||
CompositorManager::getSingleton().setCompositorEnabled(mRendering.getViewport(), "gbuffer", true);
|
||||
CompositorManager::getSingleton().addCompositor(mRendering.getViewport(), "Underwater");
|
||||
CompositorManager::getSingleton().addCompositor(mRendering.getViewport(), "gbufferFinalizer");
|
||||
CompositorManager::getSingleton().setCompositorEnabled(mRendering.getViewport(), "gbufferFinalizer", true);
|
||||
CompositorManager::getSingleton().addCompositor(mRendering.getViewport(), "Underwater");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
project(resources)
|
||||
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/water/caustic_0.png "${OpenMW_BINARY_DIR}/resources/water/caustic_0.png" COPYONLY)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/water/GlassFP.cg "${OpenMW_BINARY_DIR}/resources/water/GlassFP.cg" COPYONLY)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/water/GlassVP.cg "${OpenMW_BINARY_DIR}/resources/water/GlassVP.cg" COPYONLY)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/water/underwater.cg "${OpenMW_BINARY_DIR}/resources/water/underwater.cg" COPYONLY)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/water/perlinvolume.dds "${OpenMW_BINARY_DIR}/resources/water/perlinvolume.dds" COPYONLY)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/water/water.compositor "${OpenMW_BINARY_DIR}/resources/water/water.compositor" COPYONLY)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/water/water.material "${OpenMW_BINARY_DIR}/resources/water/water.material" COPYONLY)
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
|
||||
float4 main_ps(float2 iTexCoord : TEXCOORD0,
|
||||
float3 noiseCoord : TEXCOORD1,
|
||||
uniform sampler2D RT : register(s0),
|
||||
uniform sampler2D NormalMap : register(s1),
|
||||
uniform sampler2D CausticMap : register(s2),
|
||||
uniform float4 tintColour) : COLOR
|
||||
{
|
||||
float4 normal = tex2D(NormalMap, noiseCoord) * 2 - 1;
|
||||
|
||||
|
||||
return tex2D(RT, iTexCoord + normal.xy * 0.015) +
|
||||
(tex2D(CausticMap, noiseCoord) / 5) +
|
||||
tintColour ;
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
void glass_vp
|
||||
(
|
||||
in float4 inPos : POSITION,
|
||||
|
||||
out float4 pos : POSITION,
|
||||
out float2 uv0 : TEXCOORD0,
|
||||
out float4 noiseCoord : TEXCOORD1,
|
||||
|
||||
uniform float4x4 worldViewProj,
|
||||
uniform float timeVal,
|
||||
uniform float scale
|
||||
)
|
||||
{
|
||||
// Use standardise transform, so work accord with render system specific (RS depth, requires texture flipping, etc)
|
||||
pos = mul(worldViewProj, inPos);
|
||||
|
||||
// The input positions adjusted by texel offsets, so clean up inaccuracies
|
||||
inPos.xy = sign(inPos.xy);
|
||||
|
||||
// Convert to image-space
|
||||
uv0 = (float2(inPos.x, -inPos.y) + 1.0f) * 0.5f;
|
||||
noiseCoord = (pos + timeVal) * scale;
|
||||
}
|
||||
|
61
files/water/underwater.cg
Normal file
61
files/water/underwater.cg
Normal file
|
@ -0,0 +1,61 @@
|
|||
void main_vp
|
||||
(
|
||||
in float4 inPos : POSITION,
|
||||
|
||||
out float4 pos : POSITION,
|
||||
out float2 uv0 : TEXCOORD0,
|
||||
out float4 noiseCoord : TEXCOORD1,
|
||||
|
||||
uniform float4x4 worldViewProj,
|
||||
uniform float timeVal,
|
||||
uniform float scale
|
||||
)
|
||||
{
|
||||
// Use standardise transform, so work accord with render system specific (RS depth, requires texture flipping, etc)
|
||||
pos = mul(worldViewProj, inPos);
|
||||
|
||||
// The input positions adjusted by texel offsets, so clean up inaccuracies
|
||||
inPos.xy = sign(inPos.xy);
|
||||
|
||||
// Convert to image-space
|
||||
uv0 = (float2(inPos.x, -inPos.y) + 1.0f) * 0.5f;
|
||||
noiseCoord = (pos + timeVal) * scale;
|
||||
}
|
||||
|
||||
|
||||
|
||||
float4 main_fp_nomrt (float2 iTexCoord : TEXCOORD0,
|
||||
float3 noiseCoord : TEXCOORD1,
|
||||
uniform sampler2D RT : register(s0),
|
||||
uniform sampler2D NormalMap : register(s1),
|
||||
uniform sampler2D CausticMap : register(s2),
|
||||
uniform float4 tintColour) : COLOR
|
||||
{
|
||||
float4 normal = tex2D(NormalMap, noiseCoord) * 2 - 1;
|
||||
|
||||
return tex2D(RT, iTexCoord + normal.xy * 0.015) +
|
||||
(tex2D(CausticMap, noiseCoord) / 5) +
|
||||
tintColour ;
|
||||
}
|
||||
|
||||
|
||||
float4 main_fp (float2 iTexCoord : TEXCOORD0,
|
||||
float3 noiseCoord : TEXCOORD1,
|
||||
uniform float far,
|
||||
uniform sampler2D RT : register(s0),
|
||||
uniform sampler2D NormalMap : register(s1),
|
||||
uniform sampler2D CausticMap : register(s2),
|
||||
uniform sampler2D DepthMap : register(s3),
|
||||
uniform float4 tintColour) : COLOR
|
||||
{
|
||||
float4 normal = tex2D(NormalMap, noiseCoord) * 2 - 1;
|
||||
|
||||
float depth = tex2D(DepthMap, iTexCoord).r * far;
|
||||
depth = saturate(depth / 2000.f);
|
||||
|
||||
float4 color = tex2D(RT, iTexCoord + normal.xy * 0.015) +
|
||||
(tex2D(CausticMap, noiseCoord) / 5) +
|
||||
tintColour;
|
||||
|
||||
return lerp(color, float4(0, 0.65, 0.65, 1), depth);
|
||||
}
|
|
@ -98,6 +98,9 @@ void main_fp
|
|||
|
||||
oColor.xyz = lerp(refraction.xyz, reflection.xyz, opacity);
|
||||
|
||||
oColor.xyz += isUnderwater * float3(0, 0.35, 0.35); // underwater tint color
|
||||
oColor.xyz = lerp(oColor.xyz, float3(0, 0.65, 0.65), saturate(isUnderwater * (iDepth / 2000.f))); // underwater fog
|
||||
|
||||
// add fog
|
||||
float fogValue = saturate((iDepth - fogParams.y) * fogParams.w);
|
||||
oColor.xyz = lerp(oColor.xyz, fogColour, fogValue);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
vertex_program Water/GlassVP cg
|
||||
vertex_program UnderwaterEffectVP cg
|
||||
{
|
||||
source GlassVP.cg
|
||||
entry_point glass_vp
|
||||
source underwater.cg
|
||||
entry_point main_vp
|
||||
profiles vs_1_1 arbvp1
|
||||
|
||||
default_params
|
||||
|
@ -11,10 +11,17 @@ vertex_program Water/GlassVP cg
|
|||
}
|
||||
|
||||
|
||||
fragment_program Water/GlassFP cg
|
||||
fragment_program UnderwaterEffectFP_NoMRT cg
|
||||
{
|
||||
source GlassFP.cg
|
||||
entry_point main_ps
|
||||
source underwater.cg
|
||||
entry_point main_fp_nomrt
|
||||
profiles ps_2_0 arbfp1
|
||||
}
|
||||
|
||||
fragment_program UnderwaterEffectFP cg
|
||||
{
|
||||
source underwater.cg
|
||||
entry_point main_fp
|
||||
profiles ps_2_0 arbfp1
|
||||
}
|
||||
|
||||
|
@ -111,13 +118,13 @@ material Water/CompositorNoMRT
|
|||
pass
|
||||
{
|
||||
depth_check off
|
||||
vertex_program_ref Water/GlassVP
|
||||
vertex_program_ref UnderwaterEffectVP
|
||||
{
|
||||
param_named_auto timeVal time 0.25
|
||||
param_named scale float 0.1
|
||||
}
|
||||
|
||||
fragment_program_ref Water/GlassFP
|
||||
fragment_program_ref UnderwaterEffectFP_NoMRT
|
||||
{
|
||||
param_named tintColour float4 0 0.35 0.35 1
|
||||
}
|
||||
|
@ -154,37 +161,33 @@ material Water/Compositor
|
|||
pass
|
||||
{
|
||||
depth_check off
|
||||
vertex_program_ref Water/GlassVP
|
||||
vertex_program_ref UnderwaterEffectVP
|
||||
{
|
||||
param_named_auto timeVal time 0.25
|
||||
param_named scale float 0.1
|
||||
}
|
||||
|
||||
fragment_program_ref Water/GlassFP
|
||||
fragment_program_ref UnderwaterEffectFP
|
||||
{
|
||||
param_named tintColour float4 0 0.35 0.35 1
|
||||
param_named_auto far far_clip_distance
|
||||
}
|
||||
|
||||
texture_unit RT
|
||||
{
|
||||
tex_coord_set 0
|
||||
tex_coord_set 0
|
||||
tex_address_mode clamp
|
||||
filtering linear linear linear
|
||||
}
|
||||
|
||||
texture_unit
|
||||
{
|
||||
texture WaterNormal2.tga 2d
|
||||
tex_coord_set 2
|
||||
//tex_address_mode clamp
|
||||
filtering linear linear linear
|
||||
tex_coord_set 2
|
||||
}
|
||||
texture_unit
|
||||
{
|
||||
texture caustic_0.png 2d
|
||||
tex_coord_set 3
|
||||
//tex_address_mode clamp
|
||||
filtering linear linear linear
|
||||
tex_coord_set 3
|
||||
}
|
||||
|
||||
texture_unit DepthMap
|
||||
|
|
Loading…
Reference in a new issue