mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-05-11 04:56:49 +03:00
Update shaders
This commit is contained in:
parent
95bd4f7466
commit
fce029ae69
2 changed files with 49 additions and 39 deletions
|
@ -61,7 +61,6 @@ PixelShaderInput VS(VertexShaderInput input)
|
||||||
float3 Normal = (mul(float4(input.Normal, 0.0f), world).xyz);
|
float3 Normal = (mul(float4(input.Normal, 0.0f), world).xyz);
|
||||||
float3 WorldPosition = (mul(float4(input.Position, 1.0f), world));
|
float3 WorldPosition = (mul(float4(input.Position, 1.0f), world));
|
||||||
float3 ReflectionVector = reflect(normalize(-CamDirectionWS.xyz), normalize(Normal));
|
float3 ReflectionVector = reflect(normalize(-CamDirectionWS.xyz), normalize(Normal));
|
||||||
float4 ScreenPos = mul(mul(float4(input.Position, 1.0f), world), ViewProjection);
|
|
||||||
output.Normal = Normal;
|
output.Normal = Normal;
|
||||||
output.UV = input.UV;
|
output.UV = input.UV;
|
||||||
output.WorldPosition = WorldPosition;
|
output.WorldPosition = WorldPosition;
|
||||||
|
@ -71,35 +70,35 @@ PixelShaderInput VS(VertexShaderInput input)
|
||||||
float3x3 TBN = float3x3(Tangent, Bitangent, Normal);
|
float3x3 TBN = float3x3(Tangent, Bitangent, Normal);
|
||||||
output.TBN = transpose(TBN);
|
output.TBN = transpose(TBN);
|
||||||
|
|
||||||
float2 clipPos = ScreenPos.xy / ScreenPos.w;
|
float3 pos = input.Position;
|
||||||
|
float4 col = input.Color;
|
||||||
|
|
||||||
// Setting effect weight on TE side prevents portal vertices from moving.
|
// 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.
|
// Here we just read weight and decide if we should apply refraction or movement effect.
|
||||||
|
|
||||||
float weight = input.Effects.z;
|
float weight = input.Effects.z;
|
||||||
|
|
||||||
if (input.Effects.y > 0.0f) // Movement FIXME: rewrite this proc to differentiate from refraction!
|
// Wibble effect returns different value depending on vertex hash and frame number.
|
||||||
|
// In theory, hash could be affected by WaterScheme value from room.
|
||||||
|
|
||||||
|
static const float PI = 3.14159265f;
|
||||||
|
float wibble = sin((((Frame + input.Hash) % 64) / 64.0) * (PI*2)); // sin from -1 to 1 with a period of 64 frames
|
||||||
|
|
||||||
|
// Glow
|
||||||
|
|
||||||
|
if (input.Effects.x > 0.0f)
|
||||||
{
|
{
|
||||||
static const float PI = 3.14159265f;
|
float intensity = input.Effects.x * lerp(-0.5f, 1.0f, wibble * 0.5f + 0.5f);
|
||||||
float factor = (Frame + clipPos.x*320);
|
col = saturate(col + float4(intensity, intensity, intensity, 0));
|
||||||
float xOffset = (sin(factor * PI/20.0f)) * (ScreenPos.z/1024)*5;
|
|
||||||
float yOffset = (cos(factor*PI/20.0f))*(ScreenPos.z/1024)*5;
|
|
||||||
ScreenPos.x += xOffset * input.Effects.y * weight;
|
|
||||||
ScreenPos.y += yOffset * input.Effects.y * weight;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
output.Position = ScreenPos;
|
// Movement
|
||||||
output.Color = input.Color;
|
|
||||||
|
|
||||||
if (input.Effects.x > 0.0f) // Glow
|
if (input.Effects.y > 0.0f)
|
||||||
{
|
pos.y += wibble * input.Effects.y * weight * 128.0f; // 128 units offset to top and bottom (256 total)
|
||||||
static const float PI = 3.14159265f;
|
|
||||||
int offset = input.Hash;
|
output.Position = mul(mul(float4(pos, 1.0f), world), ViewProjection);
|
||||||
float wibble = sin((((Frame + offset) % 64) / 64.0) * PI) * 0.5f + 0.5f;
|
output.Color = col;
|
||||||
wibble *= input.Effects.x;
|
|
||||||
wibble = lerp(0.1f, 1.0f, wibble);
|
|
||||||
output.Color *= wibble;
|
|
||||||
}
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,39 +80,49 @@ float hash(float3 n)
|
||||||
PixelShaderInput VS(VertexShaderInput input)
|
PixelShaderInput VS(VertexShaderInput input)
|
||||||
{
|
{
|
||||||
PixelShaderInput output;
|
PixelShaderInput output;
|
||||||
float4 screenPos = mul(float4(input.Position, 1.0f), ViewProjection);
|
float3 pos = input.Position;
|
||||||
float2 clipPos = screenPos.xy / screenPos.w;
|
float4 col = input.Color;
|
||||||
|
|
||||||
// Setting effect weight on TE side prevents portal vertices from moving.
|
// 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.
|
// Here we just read weight and decide if we should apply refraction or movement effect.
|
||||||
|
|
||||||
float weight = input.Effects.z;
|
float weight = input.Effects.z;
|
||||||
|
|
||||||
|
// Wibble effect returns different value depending on vertex hash and frame number.
|
||||||
|
// In theory, hash could be affected by WaterScheme value from room.
|
||||||
|
|
||||||
|
static const float PI = 3.14159265f;
|
||||||
|
float wibble = sin((((Frame + input.Hash) % 64) / 64.0) * (PI*2)); // sin from -1 to 1 with a period of 64 frames
|
||||||
|
|
||||||
|
// Glow
|
||||||
|
|
||||||
|
if (input.Effects.x > 0.0f)
|
||||||
|
{
|
||||||
|
float intensity = input.Effects.x * lerp(-0.5f, 1.0f, wibble * 0.5f + 0.5f);
|
||||||
|
col = saturate(col + float4(intensity, intensity, intensity, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Movement
|
||||||
|
|
||||||
|
if (input.Effects.y > 0.0f)
|
||||||
|
pos.y += wibble * input.Effects.y * weight * 128.0f; // 128 units offset to top and bottom (256 total)
|
||||||
|
|
||||||
|
// Refraction
|
||||||
|
|
||||||
|
float4 screenPos = mul(float4(pos, 1.0f), ViewProjection);
|
||||||
|
float2 clipPos = screenPos.xy / screenPos.w;
|
||||||
if (CameraUnderwater != Water)
|
if (CameraUnderwater != Water)
|
||||||
{
|
{
|
||||||
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) * 4;
|
float xOffset = (sin(factor * PI / 20.0f)) * (screenPos.z/1024) * 4;
|
||||||
float yOffset = (cos(factor * PI/20.0f)) * (screenPos.z/1024) * 4;
|
float yOffset = (cos(factor * PI / 20.0f)) * (screenPos.z/1024) * 4;
|
||||||
screenPos.x += xOffset * weight;
|
screenPos.x += xOffset * weight;
|
||||||
screenPos.y += yOffset * weight;
|
screenPos.y += yOffset * weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
output.Position = screenPos;
|
output.Position = screenPos;
|
||||||
output.Normal = input.Normal;
|
output.Normal = input.Normal;
|
||||||
output.Color = input.Color;
|
output.Color = col;
|
||||||
|
|
||||||
float glow = input.Effects.x;
|
|
||||||
|
|
||||||
if (glow > 0.0f)
|
|
||||||
{
|
|
||||||
static const float PI = 3.14159265f;
|
|
||||||
int offset = input.Hash;
|
|
||||||
float wibble = sin((((Frame + offset) % 64) / 64.0) * PI) * 0.5f + 0.5f;
|
|
||||||
wibble *= glow;
|
|
||||||
wibble = lerp(0.1f, 1.0f, wibble);
|
|
||||||
output.Color *= wibble;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef ANIMATED
|
#ifdef ANIMATED
|
||||||
int frame = (Frame / 2) % numAnimFrames;
|
int frame = (Frame / 2) % numAnimFrames;
|
||||||
|
@ -134,8 +144,9 @@ PixelShaderInput VS(VertexShaderInput input)
|
||||||
output.UV = input.UV;
|
output.UV = input.UV;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
output.WorldPosition = input.Position.xyz;
|
output.WorldPosition = input.Position.xyz;
|
||||||
|
|
||||||
output.LightPosition = mul(float4(input.Position, 1.0f), LightViewProjection);
|
output.LightPosition = mul(float4(input.Position, 1.0f), LightViewProjection);
|
||||||
float3x3 TBN = float3x3(input.Tangent, input.Bitangent, input.Normal);
|
float3x3 TBN = float3x3(input.Tangent, input.Bitangent, input.Normal);
|
||||||
output.TBN = TBN;
|
output.TBN = TBN;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue