mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-05-04 02:38:00 +03:00
Use refraction as before but accounting for vertex weight factor
This commit is contained in:
parent
9aec905bae
commit
b93db28f1a
4 changed files with 23 additions and 19 deletions
|
@ -1,6 +1,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <SimpleMath.h>
|
#include <SimpleMath.h>
|
||||||
struct alignas(16) CRoomBuffer {
|
|
||||||
|
struct alignas(16) CRoomBuffer
|
||||||
|
{
|
||||||
DirectX::SimpleMath::Vector4 AmbientColor;
|
DirectX::SimpleMath::Vector4 AmbientColor;
|
||||||
int water;
|
int Water;
|
||||||
};
|
};
|
||||||
|
|
|
@ -3074,7 +3074,7 @@ namespace T5M::Renderer
|
||||||
m_cbMisc.updateData(m_stMisc, m_context.Get());
|
m_cbMisc.updateData(m_stMisc, m_context.Get());
|
||||||
m_context->PSSetConstantBuffers(3, 1, m_cbMisc.get());
|
m_context->PSSetConstantBuffers(3, 1, m_cbMisc.get());
|
||||||
m_stRoom.AmbientColor = room->AmbientLight;
|
m_stRoom.AmbientColor = room->AmbientLight;
|
||||||
m_stRoom.water = (room->Room->flags & ENV_FLAG_WATER) != 0 ? 1 : 0;
|
m_stRoom.Water = (room->Room->flags & ENV_FLAG_WATER) != 0 ? 1 : 0;
|
||||||
m_cbRoom.updateData(m_stRoom, m_context.Get());
|
m_cbRoom.updateData(m_stRoom, m_context.Get());
|
||||||
m_context->VSSetConstantBuffers(5, 1, m_cbRoom.get());
|
m_context->VSSetConstantBuffers(5, 1, m_cbRoom.get());
|
||||||
m_context->PSSetConstantBuffers(5, 1, m_cbRoom.get());
|
m_context->PSSetConstantBuffers(5, 1, m_cbRoom.get());
|
||||||
|
|
|
@ -73,14 +73,19 @@ PixelShaderInput VS(VertexShaderInput input)
|
||||||
|
|
||||||
float2 clipPos = ScreenPos.xy / ScreenPos.w;
|
float2 clipPos = ScreenPos.xy / ScreenPos.w;
|
||||||
|
|
||||||
if (input.Effects.z > 0.0f) // Refraction
|
// Setting effect weight on TE side prevents portal vertices from moving.
|
||||||
|
// Here we just read weight and decide if we should apply refraction or movement effect.
|
||||||
|
|
||||||
|
float weight = input.Effects.z;
|
||||||
|
|
||||||
|
if (input.Effects.y > 0.0f) // Movement FIXME: rewrite this proc to differentiate from refraction!
|
||||||
{
|
{
|
||||||
static const float PI = 3.14159265f;
|
static const float PI = 3.14159265f;
|
||||||
float factor = (Frame + clipPos.x*320);
|
float factor = (Frame + clipPos.x*320);
|
||||||
float xOffset = (sin(factor * PI/20.0f)) * (ScreenPos.z/1024)*5;
|
float xOffset = (sin(factor * PI/20.0f)) * (ScreenPos.z/1024)*5;
|
||||||
float yOffset = (cos(factor*PI/20.0f))*(ScreenPos.z/1024)*5;
|
float yOffset = (cos(factor*PI/20.0f))*(ScreenPos.z/1024)*5;
|
||||||
ScreenPos.x += xOffset * input.Effects.z;
|
ScreenPos.x += xOffset * input.Effects.y * weight;
|
||||||
ScreenPos.y += yOffset * input.Effects.z;
|
ScreenPos.y += yOffset * input.Effects.y * weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
output.Position = ScreenPos;
|
output.Position = ScreenPos;
|
||||||
|
|
|
@ -34,7 +34,7 @@ cbuffer CShadowLightBuffer : register(b4)
|
||||||
cbuffer RoomBuffer : register(b5)
|
cbuffer RoomBuffer : register(b5)
|
||||||
{
|
{
|
||||||
float4 AmbientColor;
|
float4 AmbientColor;
|
||||||
int water; // DEPRECATED
|
int Water;
|
||||||
};
|
};
|
||||||
struct AnimatedFrameUV
|
struct AnimatedFrameUV
|
||||||
{
|
{
|
||||||
|
@ -83,18 +83,19 @@ PixelShaderInput VS(VertexShaderInput input)
|
||||||
float4 screenPos = mul(float4(input.Position, 1.0f), ViewProjection);
|
float4 screenPos = mul(float4(input.Position, 1.0f), ViewProjection);
|
||||||
float2 clipPos = screenPos.xy / screenPos.w;
|
float2 clipPos = screenPos.xy / screenPos.w;
|
||||||
|
|
||||||
float refract = input.Effects.z;
|
// Setting effect weight on TE side prevents portal vertices from moving.
|
||||||
if (CameraUnderwater) // Always refract if underwater
|
// Here we just read weight and decide if we should apply refraction or movement effect.
|
||||||
refract = 1.0f;
|
|
||||||
|
|
||||||
if (refract > 0.0f)
|
float weight = input.Effects.z;
|
||||||
|
|
||||||
|
if (CameraUnderwater != Water)
|
||||||
{
|
{
|
||||||
static const float PI = 3.14159265f;
|
static const float PI = 3.14159265f;
|
||||||
float factor = (Frame + clipPos.x * 320);
|
float factor = (Frame + clipPos.x * 320);
|
||||||
float xOffset = (sin(factor * PI/20.0f)) * (screenPos.z/1024) * 8;
|
float xOffset = (sin(factor * PI/20.0f)) * (screenPos.z/1024) * 4;
|
||||||
float yOffset = (cos(factor * PI/20.0f)) * (screenPos.z/1024) * 8;
|
float yOffset = (cos(factor * PI/20.0f)) * (screenPos.z/1024) * 4;
|
||||||
screenPos.x += xOffset * refract;
|
screenPos.x += xOffset * weight;
|
||||||
screenPos.y += yOffset * refract;
|
screenPos.y += yOffset * weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
output.Position = screenPos;
|
output.Position = screenPos;
|
||||||
|
@ -102,10 +103,6 @@ PixelShaderInput VS(VertexShaderInput input)
|
||||||
output.Color = input.Color;
|
output.Color = input.Color;
|
||||||
|
|
||||||
float glow = input.Effects.x;
|
float glow = input.Effects.x;
|
||||||
if (refract > 0.0f)
|
|
||||||
{
|
|
||||||
glow = refract; // Override glow value with refraction if exists
|
|
||||||
}
|
|
||||||
|
|
||||||
if (glow > 0.0f)
|
if (glow > 0.0f)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue