forked from aya/aya
Initial commit
This commit is contained in:
249
client/common/shaders/source/adorn.hlsl
Normal file
249
client/common/shaders/source/adorn.hlsl
Normal file
@@ -0,0 +1,249 @@
|
||||
#include "common.h"
|
||||
|
||||
struct Appdata
|
||||
{
|
||||
float4 Position : POSITION;
|
||||
float2 Uv : TEXCOORD0;
|
||||
float3 Normal : NORMAL0;
|
||||
};
|
||||
|
||||
struct VertexOutput
|
||||
{
|
||||
float4 HPosition : POSITION;
|
||||
|
||||
float2 Uv : TEXCOORD0;
|
||||
float4 Color : COLOR0;
|
||||
|
||||
float FogFactor : TEXCOORD1;
|
||||
};
|
||||
|
||||
struct AALineVertexOutput
|
||||
{
|
||||
float4 HPosition : POSITION;
|
||||
|
||||
float4 Position : TEXCOORD1;
|
||||
float4 Color : COLOR0;
|
||||
|
||||
float FogFactor : COLOR1;
|
||||
float4 Start : TEXCOORD2;
|
||||
float4 End : TEXCOORD3;
|
||||
};
|
||||
|
||||
struct OutlineVertexOutput
|
||||
{
|
||||
float4 HPosition : POSITION;
|
||||
|
||||
float4 Color : COLOR0;
|
||||
float4 Position : TEXCOORD0;
|
||||
|
||||
float4 CenterRadius : TEXCOORD1;
|
||||
};
|
||||
|
||||
WORLD_MATRIX(WorldMatrix);
|
||||
|
||||
uniform float4 Color;
|
||||
// pixel info is for AA line
|
||||
// x -> Fov * 0.5f / screenSize.y;
|
||||
// y -> ScreenWidth
|
||||
// z -> ScreenWidth / ScreenHeight
|
||||
// w -> Line thickness
|
||||
uniform float4 PixelInfo;
|
||||
|
||||
|
||||
VertexOutput AdornSelfLitVSGeneric(Appdata IN, float ambient)
|
||||
{
|
||||
VertexOutput OUT = (VertexOutput)0;
|
||||
|
||||
float4 position = mul(WorldMatrix, IN.Position);
|
||||
float3 normal = normalize(mul((float3x3)WorldMatrix, IN.Normal));
|
||||
|
||||
float3 light = normalize(G(CameraPosition).xyz - position.xyz);
|
||||
float ndotl = saturate(dot(normal, light));
|
||||
|
||||
float lighting = ambient + (1 - ambient) * ndotl;
|
||||
float specular = pow(ndotl, 64.0);
|
||||
|
||||
OUT.HPosition = mul(G(ViewProjection), mul(WorldMatrix, IN.Position));
|
||||
OUT.Uv = IN.Uv;
|
||||
OUT.Color = float4(Color.rgb * lighting + specular, Color.a);
|
||||
|
||||
OUT.FogFactor = (G(FogParams).z - OUT.HPosition.w) * G(FogParams).w;
|
||||
|
||||
return OUT;
|
||||
}
|
||||
|
||||
VertexOutput AdornSelfLitVS(Appdata IN)
|
||||
{
|
||||
return AdornSelfLitVSGeneric(IN, 0.5f);
|
||||
}
|
||||
|
||||
VertexOutput AdornSelfLitHighlightVS(Appdata IN)
|
||||
{
|
||||
return AdornSelfLitVSGeneric(IN, 0.75f);
|
||||
}
|
||||
|
||||
VertexOutput AdornVS(Appdata IN)
|
||||
{
|
||||
VertexOutput OUT = (VertexOutput)0;
|
||||
|
||||
float4 position = mul(WorldMatrix, IN.Position);
|
||||
|
||||
#ifdef PIN_LIGHTING
|
||||
float3 normal = normalize(mul((float3x3)WorldMatrix, IN.Normal));
|
||||
float ndotl = dot(normal, -G(Lamp0Dir));
|
||||
float3 lighting = G(AmbientColor) + saturate(ndotl) * G(Lamp0Color) + saturate(-ndotl) * G(Lamp1Color);
|
||||
#else
|
||||
float3 lighting = 1;
|
||||
#endif
|
||||
|
||||
OUT.HPosition = mul(G(ViewProjection), position);
|
||||
OUT.Uv = IN.Uv;
|
||||
OUT.Color = float4(Color.rgb * lighting, Color.a);
|
||||
|
||||
OUT.FogFactor = (G(FogParams).z - OUT.HPosition.w) * G(FogParams).w;
|
||||
|
||||
return OUT;
|
||||
}
|
||||
|
||||
TEX_DECLARE2D(DiffuseMap, 0);
|
||||
|
||||
float4 AdornPS(VertexOutput IN): COLOR0
|
||||
{
|
||||
float4 result = tex2D(DiffuseMap, IN.Uv) * IN.Color;
|
||||
|
||||
result.rgb = lerp(G(FogColor), result.rgb, saturate(IN.FogFactor));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
AALineVertexOutput AdornAALineVS(Appdata IN)
|
||||
{
|
||||
AALineVertexOutput OUT = (AALineVertexOutput)0;
|
||||
|
||||
float4 position = mul(WorldMatrix, IN.Position);
|
||||
float3 normal = normalize(mul((float3x3)WorldMatrix, IN.Normal));
|
||||
|
||||
// line start and end position in world space
|
||||
float4 startPosW = mul(WorldMatrix, float4(1, 0, 0, 1));
|
||||
float4 endPosW = mul(WorldMatrix, float4(-1, 0, 0, 1));
|
||||
|
||||
// Compute view-space w
|
||||
float w = dot(G(ViewProjection)[3], float4(position.xyz, 1.0f));
|
||||
|
||||
// radius in pixels + constant because line has to be little bit bigget to perform anti aliasing
|
||||
float radius = PixelInfo.w + 2;
|
||||
|
||||
// scale the way that line has same size on screen
|
||||
if (length(position - startPosW) < length(position - endPosW))
|
||||
{
|
||||
float w = dot(G(ViewProjection)[3], float4(startPosW.xyz, 1.0f));
|
||||
float pixel_radius = radius * w * PixelInfo.x;
|
||||
position.xyz = startPosW.xyz + normal * pixel_radius;
|
||||
}
|
||||
else
|
||||
{
|
||||
float w = dot(G(ViewProjection)[3], float4(endPosW.xyz, 1.0f));
|
||||
float pixel_radius = radius * w * PixelInfo.x;
|
||||
position.xyz = endPosW.xyz + normal * pixel_radius;
|
||||
}
|
||||
|
||||
// output for PS
|
||||
OUT.HPosition = mul(G(ViewProjection), position);
|
||||
OUT.Position = OUT.HPosition;
|
||||
OUT.Start = mul(G(ViewProjection), startPosW);
|
||||
OUT.End = mul(G(ViewProjection), endPosW);
|
||||
OUT.FogFactor = (G(FogParams).z - OUT.HPosition.w) * G(FogParams).w;
|
||||
|
||||
// screen ratio
|
||||
OUT.Position.y *= PixelInfo.z;
|
||||
OUT.Start.y *= PixelInfo.z;
|
||||
OUT.End.y *= PixelInfo.z;
|
||||
|
||||
return OUT;
|
||||
}
|
||||
|
||||
float4 AdornAALinePS(AALineVertexOutput IN): COLOR0
|
||||
{
|
||||
IN.Position /= IN.Position.w ;
|
||||
IN.Start /= IN.Start.w;
|
||||
IN.End /= IN.End.w;
|
||||
|
||||
float4 result = 1;
|
||||
|
||||
float2 lineDir = normalize(IN.End.xy - IN.Start.xy);
|
||||
float2 fragToPoint = IN.Position.xy - IN.Start.xy;
|
||||
|
||||
// tips of the line are not Anti-Aliesed, they are just cut
|
||||
// discard as soon as we can
|
||||
float startDist = dot(lineDir, fragToPoint);
|
||||
float endDist = dot(lineDir, -IN.Position.xy + IN.End.xy);
|
||||
|
||||
if (startDist < 0)
|
||||
discard;
|
||||
|
||||
if (endDist < 0)
|
||||
discard;
|
||||
|
||||
float2 perpLineDir = float2(lineDir.y, -lineDir.x);
|
||||
|
||||
float dist = abs(dot(perpLineDir, fragToPoint));
|
||||
|
||||
// high point serves to compute the function which is described bellow.
|
||||
float highPoint = 1 + (PixelInfo.w - 1) * 0.5;
|
||||
|
||||
// this is function that has this shape /¯¯¯\, it is symetric, centered around 0 on X axis
|
||||
// slope parts are +- 45 degree and are 1px thick. Area of the shape sums to line thickness in pixels
|
||||
// funtion for 1px would be /\, func for 2px is /¯\ and so on...
|
||||
result.a = saturate(highPoint - (dist * 0.5 * PixelInfo.y));
|
||||
|
||||
result *= Color;
|
||||
|
||||
// convert to sRGB, its not perfect for non-black backgrounds, but its the best we can get
|
||||
result.a = pow( saturate(1 - result.a), 1/2.2);
|
||||
result.a = 1 - result.a;
|
||||
|
||||
result.rgb = lerp(G(FogColor), result.rgb, saturate(IN.FogFactor));
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
OutlineVertexOutput AdornOutlineVS(Appdata IN)
|
||||
{
|
||||
OutlineVertexOutput OUT = (OutlineVertexOutput)0;
|
||||
|
||||
float4 position = mul(WorldMatrix, IN.Position);
|
||||
|
||||
OUT.HPosition = mul(G(ViewProjection), position);
|
||||
|
||||
OUT.Color = Color;
|
||||
OUT.Position = position;
|
||||
|
||||
OUT.CenterRadius = float4(mul(WorldMatrix, float4(0, 0, 0, 1)).xyz, length(mul(WorldMatrix, float4(1, 0, 0, 0))));
|
||||
|
||||
return OUT;
|
||||
}
|
||||
|
||||
float4 AdornOutlinePS(OutlineVertexOutput IN): COLOR0
|
||||
{
|
||||
float3 rayO = IN.Position.xyz - IN.CenterRadius.xyz;
|
||||
float3 rayD = normalize(IN.Position.xyz - G(CameraPosition));
|
||||
|
||||
// magnitude(rayO + t * rayD) = radius
|
||||
// t^2 + bt + c = radius
|
||||
float thickness = 1;
|
||||
|
||||
float r0 = IN.CenterRadius.w;
|
||||
float r1 = max(0, IN.CenterRadius.w - thickness);
|
||||
|
||||
float b = 2 * dot(rayO, rayD);
|
||||
float c0 = dot(rayO, rayO) - r0 * r0;
|
||||
float c1 = dot(rayO, rayO) - r1 * r1;
|
||||
|
||||
if (b * b < 4 * c0)
|
||||
discard;
|
||||
|
||||
if (b * b > 4 * c1)
|
||||
discard;
|
||||
|
||||
return IN.Color;
|
||||
}
|
||||
87
client/common/shaders/source/aluminum.hlsl
Normal file
87
client/common/shaders/source/aluminum.hlsl
Normal file
@@ -0,0 +1,87 @@
|
||||
#ifdef CLASSIC
|
||||
#define PIN_SURFACE
|
||||
#define ALREADY_HAS_PS
|
||||
#include "default.hlsl"
|
||||
|
||||
#define SPEC_EXPON 25
|
||||
#define KS .9
|
||||
#define KR .42
|
||||
|
||||
#define FADE_DIST 250//133.33 fix!!!!!!!!!!
|
||||
#define FADE_DIST_START 20
|
||||
|
||||
void DefaultPS(VertexOutput IN,
|
||||
#ifdef PIN_GBUFFER
|
||||
out float4 oColor1: COLOR1,
|
||||
#endif
|
||||
out float4 oColor0: COLOR0)
|
||||
{
|
||||
float fade = saturate(1 - (IN.View_Depth.w - FADE_DIST_START) / FADE_DIST);
|
||||
float3 nn = normalize(IN.Normal.xyz);
|
||||
|
||||
float3x3 normalMatrix = {
|
||||
IN.Tangent.xyz,
|
||||
cross(nn, IN.Tangent.xyz),
|
||||
nn
|
||||
};
|
||||
|
||||
float3 albedo = IN.Color.xyz;
|
||||
float2 uv = IN.Uv.xy * 2;
|
||||
float3 tn = tex2D(NormalMap, uv);
|
||||
float3 tn2 = tex2D(NormalMap, uv * .4);
|
||||
tn = lerp(tn, tn2, .5);
|
||||
tn2 = tex2D(NormalMap, uv * .1);
|
||||
tn = lerp(tn, tn2, .3) -.5;
|
||||
tn = lerp(float3(0, 0, .5), tn, fade);
|
||||
|
||||
float tNormSum = 0.4 + 0.6 * (tn.x + tn.y + tn.z);
|
||||
albedo *= ((1-fade) + (fade*tNormSum));
|
||||
|
||||
tn = CalcBevel(IN.EdgeDistances, tn, IN.View_Depth.w);
|
||||
|
||||
nn = mul(tn, normalMatrix);
|
||||
|
||||
float3 vn = normalize(IN.View_Depth.xyz);
|
||||
float4 light = lgridSample(TEXTURE(LightMap), TEXTURE(LightMapLookup), IN.LightPosition_Fog.xyz);
|
||||
light.a = shadowSample(TEXTURE(ShadowMap), IN.PosLightSpace.xyz, light.a);
|
||||
|
||||
float3 diffuse;
|
||||
float3 specular;
|
||||
Shade(albedo, nn, vn, KS, SPEC_EXPON, light, diffuse, specular);
|
||||
float3 enviroment = texCUBE(EnvironmentMap, reflect(-vn, nn)) * KR -.1;
|
||||
|
||||
oColor0 = float4(diffuse + specular + enviroment, IN.Color.w);
|
||||
//subtract .1 because thats what dumbass roblox did for whatever reason
|
||||
|
||||
float fogAlpha = saturate((G(FogParams).z - length(IN.View_Depth.xyz)) * G(FogParams).w);
|
||||
oColor0.xyz = lerp(G(FogColor), oColor0.rgb, fogAlpha);
|
||||
|
||||
#ifdef PIN_GBUFFER
|
||||
oColor1 = gbufferPack(IN.View_Depth.w, diffuse.rgb, specular.rgb, fogAlpha);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
#define CFG_TEXTURE_TILING 1
|
||||
|
||||
#define CFG_DIFFUSE_SCALE 1
|
||||
#define CFG_SPECULAR_SCALE 1
|
||||
#define CFG_GLOSS_SCALE 256
|
||||
#define CFG_REFLECTION_SCALE 0.6
|
||||
|
||||
#define CFG_NORMAL_SHADOW_SCALE 0
|
||||
|
||||
#define CFG_SPECULAR_LOD 0.94
|
||||
#define CFG_GLOSS_LOD 240
|
||||
|
||||
#define CFG_NORMAL_DETAIL_TILING 0
|
||||
#define CFG_NORMAL_DETAIL_SCALE 0
|
||||
|
||||
#define CFG_FAR_TILING 0.25
|
||||
#define CFG_FAR_DIFFUSE_CUTOFF 0
|
||||
#define CFG_FAR_NORMAL_CUTOFF 0.75
|
||||
#define CFG_FAR_SPECULAR_CUTOFF 0
|
||||
|
||||
#define CFG_OPT_DIFFUSE_CONST
|
||||
|
||||
#include "material.hlsl"
|
||||
#endif
|
||||
27
client/common/shaders/source/brick.hlsl
Normal file
27
client/common/shaders/source/brick.hlsl
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifdef CLASSIC
|
||||
#include "slate.hlsl"
|
||||
#else
|
||||
#define CFG_TEXTURE_TILING 1
|
||||
|
||||
#define CFG_DIFFUSE_SCALE 1
|
||||
#define CFG_SPECULAR_SCALE 1.3
|
||||
#define CFG_GLOSS_SCALE 64
|
||||
#define CFG_REFLECTION_SCALE 0
|
||||
|
||||
#define CFG_NORMAL_SHADOW_SCALE 0.1
|
||||
|
||||
#define CFG_SPECULAR_LOD 0.13
|
||||
#define CFG_GLOSS_LOD 44
|
||||
|
||||
#define CFG_NORMAL_DETAIL_TILING 0
|
||||
#define CFG_NORMAL_DETAIL_SCALE 0
|
||||
|
||||
#define CFG_FAR_TILING 0
|
||||
#define CFG_FAR_DIFFUSE_CUTOFF 0
|
||||
#define CFG_FAR_NORMAL_CUTOFF 0
|
||||
#define CFG_FAR_SPECULAR_CUTOFF 0
|
||||
|
||||
#define CFG_OPT_BLEND_COLOR
|
||||
|
||||
#include "material.hlsl"
|
||||
#endif
|
||||
26
client/common/shaders/source/cobblestone.hlsl
Normal file
26
client/common/shaders/source/cobblestone.hlsl
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifdef CLASSIC
|
||||
#include "slate.hlsl"
|
||||
#else
|
||||
#define CFG_TEXTURE_TILING 1
|
||||
|
||||
#define CFG_DIFFUSE_SCALE 1
|
||||
#define CFG_SPECULAR_SCALE 3
|
||||
#define CFG_GLOSS_SCALE 256
|
||||
#define CFG_REFLECTION_SCALE 0
|
||||
|
||||
#define CFG_NORMAL_SHADOW_SCALE 0.3
|
||||
|
||||
#define CFG_SPECULAR_LOD 0.21
|
||||
#define CFG_GLOSS_LOD 22
|
||||
|
||||
#define CFG_NORMAL_DETAIL_TILING 0
|
||||
#define CFG_NORMAL_DETAIL_SCALE 0
|
||||
|
||||
#define CFG_OPT_BLEND_COLOR
|
||||
|
||||
#define CFG_WANG_TILES
|
||||
#define CFG_WANG_TILES_SCALE 1
|
||||
|
||||
|
||||
#include "material.hlsl"
|
||||
#endif
|
||||
282
client/common/shaders/source/common.h
Normal file
282
client/common/shaders/source/common.h
Normal file
@@ -0,0 +1,282 @@
|
||||
#include "globals.h"
|
||||
|
||||
// GLSLES has limited number of vertex shader registers so we have to use less bones
|
||||
#if defined(GLSLES) && !defined(GL3)
|
||||
#define MAX_BONE_COUNT 32
|
||||
#else
|
||||
#define MAX_BONE_COUNT 72
|
||||
#endif
|
||||
|
||||
// PowerVR saturate() is compiled to min/max pair
|
||||
// These are cross-platform specialized saturates that are free on PC and only cost 1 cycle on PowerVR
|
||||
#ifdef GLSLES
|
||||
float saturate0(float v)
|
||||
{
|
||||
return max(v, 0);
|
||||
}
|
||||
float saturate1(float v)
|
||||
{
|
||||
return min(v, 1);
|
||||
}
|
||||
#define WANG_SUBSET_SCALE 2
|
||||
#else
|
||||
float saturate0(float v)
|
||||
{
|
||||
return saturate(v);
|
||||
}
|
||||
float saturate1(float v)
|
||||
{
|
||||
return saturate(v);
|
||||
}
|
||||
#define WANG_SUBSET_SCALE 1
|
||||
#endif
|
||||
|
||||
#define GBUFFER_MAX_DEPTH 500.0f
|
||||
|
||||
|
||||
#ifndef DX11
|
||||
#define TEX_DECLARE2D(name, reg) sampler2D name : register(s##reg)
|
||||
#define TEX_DECLARE3D(name, reg) sampler3D name : register(s##reg)
|
||||
#define TEX_DECLARECUBE(name, reg) samplerCUBE name : register(s##reg)
|
||||
|
||||
#define TEXTURE(name) name
|
||||
#define TEXTURE_IN_2D(name) sampler2D name
|
||||
#define TEXTURE_IN_3D(name) sampler3D name
|
||||
#define TEXTURE_IN_CUBE(name) samplerCUBE name
|
||||
|
||||
#define WORLD_MATRIX(name) uniform float4x4 name;
|
||||
#define WORLD_MATRIX_ARRAY(name, count) uniform float4 name[count];
|
||||
|
||||
#ifdef GLSL
|
||||
#define ATTR_INT4 float4
|
||||
#define ATTR_INT3 float3
|
||||
#define ATTR_INT2 float2
|
||||
#define ATTR_INT float
|
||||
#else
|
||||
#define ATTR_INT4 int4
|
||||
#define ATTR_INT3 int3
|
||||
#define ATTR_INT2 int2
|
||||
#define ATTR_INT int
|
||||
#endif
|
||||
#else
|
||||
#define TEX_DECLARE2D(name, reg) \
|
||||
SamplerState name##Sampler : register(s##reg); \
|
||||
Texture2D<float4> name##Texture : register(t##reg)
|
||||
#define TEX_DECLARE3D(name, reg) \
|
||||
SamplerState name##Sampler : register(s##reg); \
|
||||
Texture3D<float4> name##Texture : register(t##reg)
|
||||
#define TEX_DECLARECUBE(name, reg) \
|
||||
SamplerState name##Sampler : register(s##reg); \
|
||||
TextureCube<float4> name##Texture : register(t##reg)
|
||||
|
||||
#define tex2D(tex, uv) tex##Texture.Sample(tex##Sampler, uv)
|
||||
#define tex3D(tex, uv) tex##Texture.Sample(tex##Sampler, uv)
|
||||
#define texCUBE(tex, uv) tex##Texture.Sample(tex##Sampler, uv)
|
||||
#define tex2Dgrad(tex, uv, DDX, DDY) tex##Texture.SampleGrad(tex##Sampler, uv, DDX, DDY)
|
||||
#define tex2Dbias(tex, uv) tex##Texture.SampleBias(tex##Sampler, uv.xy, uv.w)
|
||||
#define texCUBEbias(tex, uv) tex##Texture.SampleBias(tex##Sampler, uv.xyz, uv.w)
|
||||
|
||||
#define TEXTURE(name) name##Sampler, name##Texture
|
||||
#define TEXTURE_IN_2D(name) SamplerState name##Sampler, Texture2D name##Texture
|
||||
#define TEXTURE_IN_3D(name) SamplerState name##Sampler, Texture3D name##Texture
|
||||
#define TEXTURE_IN_CUBE(name) SamplerState name##Sampler, TextureCube name##Texture
|
||||
|
||||
#define WORLD_MATRIX(name) \
|
||||
cbuffer WorldMatrixCB : register(b1) \
|
||||
{ \
|
||||
float4x4 name; \
|
||||
}
|
||||
#define WORLD_MATRIX_ARRAY(name, count) \
|
||||
cbuffer WorldMatrixCB : register(b1) \
|
||||
{ \
|
||||
float4 name[count]; \
|
||||
}
|
||||
|
||||
#define ATTR_INT4 int4
|
||||
#define ATTR_INT3 int3
|
||||
#define ATTR_INT2 int2
|
||||
#define ATTR_INT int
|
||||
#endif
|
||||
|
||||
#if defined(GLSLES) || defined(PIN_WANG_FALLBACK)
|
||||
#define TEXTURE_WANG(name) 0
|
||||
void getWang(float unused, float2 uv, float tiling, out float2 wangUv, out float4 wangUVDerivatives)
|
||||
{
|
||||
wangUv = uv * WANG_SUBSET_SCALE;
|
||||
wangUVDerivatives = float4(0, 0, 0, 0); // not used in this mode
|
||||
}
|
||||
float4 sampleWang(TEXTURE_IN_2D(s), float2 uv, float4 wangUVDerivatives)
|
||||
{
|
||||
return tex2D(s, uv);
|
||||
}
|
||||
#else
|
||||
#define TEXTURE_WANG(name) TEXTURE(name)
|
||||
void getWang(TEXTURE_IN_2D(s), float2 uv, float tiling, out float2 wangUv, out float4 wangUVDerivatives)
|
||||
{
|
||||
#ifndef WIN_MOBILE
|
||||
float idxTexSize = 128;
|
||||
#else
|
||||
float idxTexSize = 32;
|
||||
#endif
|
||||
|
||||
float2 wangBase = uv * tiling * 4;
|
||||
|
||||
#if defined(DX11) && !defined(WIN_MOBILE)
|
||||
// compensate the precision problem of Point Sampling on some cards. (We do it just at DX11 for performance reasons)
|
||||
float2 wangUV = (floor(wangBase) + 0.5) / idxTexSize;
|
||||
#else
|
||||
float2 wangUV = wangBase / idxTexSize;
|
||||
#endif
|
||||
|
||||
#if defined(DX11) || defined(GL3)
|
||||
float2 wang = tex2D(s, wangUV).rg;
|
||||
#else
|
||||
float2 wang = tex2D(s, wangUV).ba;
|
||||
#endif
|
||||
|
||||
wangUVDerivatives = float4(ddx(wangBase * 0.25), ddy(wangBase * 0.25));
|
||||
|
||||
wang *= 255.0 / 256.0;
|
||||
wangUv = wang + frac(wangBase) * 0.25;
|
||||
}
|
||||
float4 sampleWang(TEXTURE_IN_2D(s), float2 uv, float4 derivates)
|
||||
{
|
||||
return tex2Dgrad(s, uv, derivates.xy, derivates.zw);
|
||||
}
|
||||
#endif
|
||||
|
||||
float4 gbufferPack(float depth, float3 diffuse, float3 specular, float fog)
|
||||
{
|
||||
depth = saturate(depth / GBUFFER_MAX_DEPTH);
|
||||
|
||||
const float3 bitSh = float3(255 * 255, 255, 1);
|
||||
const float3 lumVec = float3(0.299, 0.587, 0.114);
|
||||
|
||||
float2 comp;
|
||||
comp = depth * float2(255, 255 * 256);
|
||||
comp = frac(comp);
|
||||
comp = float2(depth, comp.x * 256 / 255) - float2(comp.x, comp.y) / 255;
|
||||
|
||||
float4 result;
|
||||
|
||||
result.r = lerp(1, dot(specular, lumVec), saturate(3 * fog));
|
||||
result.g = lerp(0, dot(diffuse, lumVec), saturate(3 * fog));
|
||||
result.ba = comp.yx;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
float3 lgridOffset(float3 v, float3 n)
|
||||
{
|
||||
// cells are 4 studs in size
|
||||
// offset in normal direction to prevent self-occlusion
|
||||
// the offset has to be 1.5 cells in order to fully eliminate the influence of the source cell with trilinear filtering
|
||||
// (i.e. 1 cell is enough for point filtering, but is not enough for trilinear filtering)
|
||||
return v + n * (1.5f * 4.f);
|
||||
}
|
||||
|
||||
float3 lgridPrepareSample(float3 c)
|
||||
{
|
||||
// yxz swizzle is necessary for GLSLES sampling to work efficiently
|
||||
// (having .y as the first component allows to do the LUT lookup as a non-dependent texture fetch)
|
||||
return c.yxz * G(LightConfig0).xyz + G(LightConfig1).xyz;
|
||||
}
|
||||
|
||||
#if defined(GLSLES) && !defined(GL3)
|
||||
#define LGRID_SAMPLER(name, register) TEX_DECLARE2D(name, register)
|
||||
|
||||
float4 lgridSample(TEXTURE_IN_2D(t), TEXTURE_IN_2D(lut), float3 data)
|
||||
{
|
||||
float4 offsets = tex2D(lut, data.xy);
|
||||
|
||||
// texture is 64 pixels high
|
||||
// let's compute slice lerp coeff
|
||||
float slicef = frac(data.x * 64);
|
||||
|
||||
// texture has 64 slices with 8x8 atlas setup
|
||||
float2 base = saturate(data.yz) * 0.125;
|
||||
|
||||
float4 s0 = tex2D(t, base + offsets.xy);
|
||||
float4 s1 = tex2D(t, base + offsets.zw);
|
||||
|
||||
return lerp(s0, s1, slicef);
|
||||
}
|
||||
#else
|
||||
#define LGRID_SAMPLER(name, register) TEX_DECLARE3D(name, register)
|
||||
|
||||
float4 lgridSample(TEXTURE_IN_3D(t), TEXTURE_IN_2D(lut), float3 data)
|
||||
{
|
||||
float3 edge = step(G(LightConfig3).xyz, abs(data - G(LightConfig2).xyz));
|
||||
float edgef = saturate1(dot(edge, 1));
|
||||
|
||||
// replace data with 0 on edges to minimize texture cache misses
|
||||
float4 light = tex3D(t, data.yzx - data.yzx * edgef);
|
||||
|
||||
return lerp(light, G(LightBorder), edgef);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef GLSLES
|
||||
float3 nmapUnpack(float4 value)
|
||||
{
|
||||
return value.rgb * 2 - 1;
|
||||
}
|
||||
#else
|
||||
float3 nmapUnpack(float4 value)
|
||||
{
|
||||
float2 xy = value.ag * 2 - 1;
|
||||
|
||||
return float3(xy, sqrt(saturate(1 + dot(-xy, xy))));
|
||||
}
|
||||
#endif
|
||||
|
||||
float3 terrainNormal(float4 tnp0, float4 tnp1, float4 tnp2, float3 w, float3 normal, float3 tsel)
|
||||
{
|
||||
// Inspired by "Voxel-Based Terrain for Real-Time Virtual Simulations" [Lengyel2010] 5.5.2
|
||||
float3 tangentTop = float3(normal.y, -normal.x, 0);
|
||||
float3 tangentSide = float3(normal.z, 0, -normal.x);
|
||||
|
||||
float3 bitangentTop = float3(0, -normal.z, normal.y);
|
||||
float3 bitangentSide = float3(0, -1, 0);
|
||||
|
||||
// Blend pre-unpack to save cycles
|
||||
float3 tn = nmapUnpack(tnp0 * w.x + tnp1 * w.y + tnp2 * w.z);
|
||||
|
||||
// We blend all tangent frames together as a faster approximation to the correct world normal blend
|
||||
float tselw = dot(tsel, w);
|
||||
|
||||
float3 tangent = lerp(tangentSide, tangentTop, tselw);
|
||||
float3 bitangent = lerp(bitangentSide, bitangentTop, tselw);
|
||||
|
||||
return normalize(tangent * tn.x + bitangent * tn.y + normal * tn.z);
|
||||
}
|
||||
|
||||
float3 shadowPrepareSample(float3 p)
|
||||
{
|
||||
float4 c = float4(p, 1);
|
||||
|
||||
return float3(dot(G(ShadowMatrix0), c), dot(G(ShadowMatrix1), c), dot(G(ShadowMatrix2), c));
|
||||
}
|
||||
|
||||
float shadowDepth(float3 lpos)
|
||||
{
|
||||
return lpos.z;
|
||||
}
|
||||
|
||||
float shadowStep(float d, float z)
|
||||
{
|
||||
// saturate returns 1 for z in [0.1..0.9]; it fades to 0 as z approaches 0 or 1
|
||||
return step(d, z) * saturate(9 - 20 * abs(z - 0.5));
|
||||
}
|
||||
|
||||
float shadowSample(TEXTURE_IN_2D(map), float3 lpos, float lightShadow)
|
||||
{
|
||||
#ifdef CLASSIC
|
||||
return lightShadow;
|
||||
#else
|
||||
float2 smDepth = tex2D(map, lpos.xy).rg;
|
||||
float smShadow = shadowStep(smDepth.x, shadowDepth(lpos));
|
||||
|
||||
return (1 - smShadow * smDepth.y * G(OutlineBrightness_ShadowInfo).w) * lightShadow;
|
||||
#endif
|
||||
}
|
||||
73
client/common/shaders/source/concrete.hlsl
Normal file
73
client/common/shaders/source/concrete.hlsl
Normal file
@@ -0,0 +1,73 @@
|
||||
#ifdef CLASSIC
|
||||
#define ALREADY_HAS_PS
|
||||
#include "default.hlsl"
|
||||
|
||||
#define SPEC_EXPON 81
|
||||
#define KS .75
|
||||
|
||||
|
||||
void DefaultPS(VertexOutput IN,
|
||||
#ifdef PIN_GBUFFER
|
||||
out float4 oColor1: COLOR1,
|
||||
#endif
|
||||
out float4 oColor0: COLOR0)
|
||||
{
|
||||
float3 nn = normalize(IN.Normal);
|
||||
|
||||
float3x3 normalMatrix = {
|
||||
IN.Tangent.xyz,
|
||||
cross(nn, IN.Tangent.xyz),
|
||||
nn
|
||||
};
|
||||
|
||||
nn = CalcBevel(IN.EdgeDistances, float3(0,0,.5), IN.View_Depth.w);
|
||||
nn = mul(nn, normalMatrix);
|
||||
|
||||
float2 uv = IN.Uv.xy;
|
||||
float3 concrete = .5 * (tex2D(DiffuseMap, uv).xyz * 2 - 1);
|
||||
|
||||
float3 albedo = IN.Color.xyz;
|
||||
float3 vn = normalize(IN.View_Depth.xyz);
|
||||
float4 light = lgridSample(TEXTURE(LightMap), TEXTURE(LightMapLookup), IN.LightPosition_Fog.xyz);
|
||||
|
||||
float3 diffuse;
|
||||
float3 specular;
|
||||
albedo += concrete;
|
||||
|
||||
Shade(albedo, nn, vn, KS, SPEC_EXPON, light, diffuse, specular);
|
||||
//diffuse += concrete; //this is accurate but stupid dont know if i should keep
|
||||
|
||||
oColor0 = float4(diffuse, IN.Color.w);
|
||||
|
||||
float fogAlpha = saturate((G(FogParams).z - length(IN.View_Depth.xyz)) * G(FogParams).w);
|
||||
oColor0.xyz = lerp(G(FogColor), oColor0.rgb, fogAlpha);
|
||||
|
||||
#ifdef PIN_GBUFFER
|
||||
oColor1 = gbufferPack(IN.View_Depth.w, diffuse.rgb, float3(0,0,0), fogAlpha);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
#define CFG_TEXTURE_TILING 1
|
||||
|
||||
#define CFG_DIFFUSE_SCALE 1
|
||||
#define CFG_SPECULAR_SCALE 1.3
|
||||
#define CFG_GLOSS_SCALE 128
|
||||
#define CFG_REFLECTION_SCALE 0
|
||||
|
||||
#define CFG_NORMAL_SHADOW_SCALE 0
|
||||
|
||||
#define CFG_SPECULAR_LOD 0.07
|
||||
#define CFG_GLOSS_LOD 22
|
||||
|
||||
#define CFG_NORMAL_DETAIL_TILING 10
|
||||
#define CFG_NORMAL_DETAIL_SCALE 1
|
||||
|
||||
#define CFG_FAR_TILING 0.25
|
||||
#define CFG_FAR_DIFFUSE_CUTOFF 0.75
|
||||
#define CFG_FAR_NORMAL_CUTOFF 0
|
||||
#define CFG_FAR_SPECULAR_CUTOFF 0
|
||||
|
||||
#define CFG_OPT_NORMAL_CONST
|
||||
|
||||
#include "material.hlsl"
|
||||
#endif
|
||||
672
client/common/shaders/source/default.hlsl
Normal file
672
client/common/shaders/source/default.hlsl
Normal file
@@ -0,0 +1,672 @@
|
||||
#ifdef CLASSIC
|
||||
#include "common.h"
|
||||
|
||||
#define LQMAT_FADE_FACTOR (1.0f/300.0f)
|
||||
#define BEVEL_WIDTH .06
|
||||
#define PI 3.14159265359
|
||||
|
||||
#define BEVEL_FADE_DIST 120
|
||||
#define BEVEL_FADE_DIST_START 0
|
||||
|
||||
struct Appdata
|
||||
{
|
||||
float4 Position : POSITION;
|
||||
float3 Normal : NORMAL;
|
||||
float2 Uv : TEXCOORD0;
|
||||
float2 UvStuds : TEXCOORD1;
|
||||
|
||||
float4 Color : COLOR0;
|
||||
ATTR_INT4 Extra : COLOR1;
|
||||
|
||||
float3 Tangent : TEXCOORD2;
|
||||
|
||||
float4 EdgeDistances : TEXCOORD3;
|
||||
};
|
||||
|
||||
struct VertexOutput
|
||||
{
|
||||
float2 Uv : TEXCOORD0;
|
||||
float2 UvStuds : TEXCOORD1;
|
||||
|
||||
float4 Color : COLOR0;
|
||||
float3 Normal : TEXCOORD2;
|
||||
float3 Tangent : TEXCOORD3;
|
||||
float3 Pos : TEXCOORD4;
|
||||
float3 WorldPos : TEXCOORD5;
|
||||
float4 LightPosition_Fog : TEXCOORD6;
|
||||
|
||||
float4 View_Depth : TEXCOORD7;
|
||||
|
||||
float3 PosLightSpace : TEXCOORD8;
|
||||
|
||||
float4 EdgeDistances : TEXCOORD9;
|
||||
float Reflection : TEXCOORD10;
|
||||
#ifdef CLASSIC_GOURAUD
|
||||
float3 Diffuse : TEXCOORD11;
|
||||
float3 Specular : TEXCOORD12;
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef PIN_SKINNED
|
||||
WORLD_MATRIX_ARRAY(WorldMatrixArray, MAX_BONE_COUNT * 3);
|
||||
#endif
|
||||
|
||||
#ifdef PIN_DEBUG
|
||||
uniform float4 DebugColor;
|
||||
#endif
|
||||
|
||||
void Shade(float3 albedo, float3 nn, float3 vn, float ks, float specExpon, float4 light, out float3 diffuse, out float3 specular)
|
||||
{
|
||||
float3 ln = normalize(-G(Lamp0Dir));
|
||||
float3 hn = normalize(ln + vn);
|
||||
float ndl = dot(nn, ln);
|
||||
float ndh = dot(nn, hn);
|
||||
|
||||
float2 lit0 = lit(ndl, ndh, specExpon).yz;
|
||||
float3 lampColor = G(Lamp0Color);
|
||||
diffuse = (light.a * (lampColor * lit0.x) + G(AmbientColor) + light.xyz);
|
||||
//diffuse += light.a * max(-ndl, 0) * G(Lamp1Color); //the bitch ass light that shines on the backfacing normals remove for less ugly but less robloxeses accuracy
|
||||
diffuse *= albedo;
|
||||
specular = (lampColor * lit0.y) * ks * light.a;
|
||||
}
|
||||
|
||||
float3 CalcBevel(float4 edgeDistances, float3 normal, float viewDepth)
|
||||
{
|
||||
float4 bevelMultiplier = saturate(BEVEL_WIDTH - edgeDistances) / BEVEL_WIDTH;
|
||||
float fade = saturate(1 - (viewDepth - BEVEL_FADE_DIST_START) / BEVEL_FADE_DIST);
|
||||
bevelMultiplier *= fade;
|
||||
|
||||
normal += bevelMultiplier.x * float3(.5,0,0);
|
||||
normal += bevelMultiplier.y * float3(-.5,0,0);
|
||||
normal += bevelMultiplier.z * float3(0,.5,0);
|
||||
normal += bevelMultiplier.w * float3(0,-.5,0);
|
||||
|
||||
return normalize(normal);
|
||||
}
|
||||
|
||||
float3 DisplaceCoord(float3 pos) //theres a fourth component but later idk
|
||||
{
|
||||
float cfactor = 0.980066578; //cos(0.2);
|
||||
float sfactor = 0.198669331; //sin(0.2);
|
||||
float cfactor2 = 0.955336489; //cos(0.3);
|
||||
float sfactor2 = 0.295520207; //sin(0.3);
|
||||
float cfactor3 = 0.921060994; //cos(0.4);
|
||||
float sfactor3 = 0.389418342; //sin(0.4);
|
||||
float3 p = pos.xyz;
|
||||
float3 shiftPos = p;
|
||||
|
||||
shiftPos.x += p.x * cfactor + p.z * sfactor;
|
||||
shiftPos.z += p.x * -sfactor + p.z * cfactor;
|
||||
|
||||
shiftPos.x += p.x * cfactor2 - p.y * sfactor2;
|
||||
shiftPos.y += p.x * sfactor2 + p.y * cfactor2;
|
||||
|
||||
shiftPos.y += p.y * cfactor3 - p.z * sfactor3;
|
||||
shiftPos.z += p.y * sfactor3 + p.z * cfactor3;
|
||||
|
||||
return shiftPos; //return float4(shiftPos,IN.TexPos3D.w);
|
||||
}
|
||||
|
||||
TEX_DECLARE2D(StudsMap, 0);
|
||||
|
||||
LGRID_SAMPLER(LightMap, 1);
|
||||
TEX_DECLARE2D(LightMapLookup, 2);
|
||||
|
||||
TEX_DECLARE2D(ShadowMap, 3);
|
||||
|
||||
TEX_DECLARECUBE(EnvironmentMap, 4);
|
||||
|
||||
TEX_DECLARE2D(DiffuseMap, 5);
|
||||
TEX_DECLARE2D(NormalMap, 6);
|
||||
TEX_DECLARE3D(SpecularMap, 7);
|
||||
|
||||
#ifndef GLSLES
|
||||
TEX_DECLARE2D(NormalDetailMap, 8);
|
||||
#endif
|
||||
|
||||
VertexOutput DefaultVS(Appdata IN, out float4 HPosition: POSITION)
|
||||
{
|
||||
VertexOutput OUT = (VertexOutput)0;
|
||||
|
||||
// Transform position and normal to world space
|
||||
#ifdef PIN_SKINNED
|
||||
int boneIndex = IN.Extra.r;
|
||||
|
||||
float4 worldRow0 = WorldMatrixArray[boneIndex * 3];
|
||||
float4 worldRow1 = WorldMatrixArray[boneIndex * 3 + 1];
|
||||
float4 worldRow2 = WorldMatrixArray[boneIndex * 3 + 2];
|
||||
|
||||
float3 posWorld = float3(dot(worldRow0, IN.Position), dot(worldRow1, IN.Position), dot(worldRow2, IN.Position));
|
||||
float3 normalWorld = float3(dot(worldRow0.xyz, IN.Normal), dot(worldRow1.xyz, IN.Normal), dot(worldRow2.xyz, IN.Normal));
|
||||
OUT.Tangent = float3(dot(worldRow0.xyz, IN.Tangent), dot(worldRow1.xyz, IN.Tangent), dot(worldRow2.xyz, IN.Tangent));
|
||||
#else
|
||||
//OUT.Pos = mul(transpose(worldMatrix), IN.Position).xyz; // IN.position
|
||||
float3 posWorld = IN.Position.xyz;
|
||||
float3 normalWorld = IN.Normal;
|
||||
OUT.Tangent = IN.Tangent;
|
||||
#endif
|
||||
OUT.Pos = IN.Position.xyz;
|
||||
OUT.WorldPos = posWorld;
|
||||
|
||||
//posWorld.xy += sin(posWorld.yx * .05) * 5;
|
||||
//float scale = 6;
|
||||
//posWorld.y *= 6;
|
||||
//posWorld.y -= G(CameraPosition).y * (scale - 1);
|
||||
float4 color = IN.Color;
|
||||
|
||||
HPosition = mul(G(ViewProjection), float4(posWorld, 1));
|
||||
OUT.Normal = normalWorld;
|
||||
OUT.Uv = IN.Uv;
|
||||
OUT.UvStuds.xy = IN.UvStuds;
|
||||
|
||||
OUT.Color = color;
|
||||
OUT.LightPosition_Fog = float4(lgridPrepareSample(lgridOffset(posWorld, normalWorld)), (G(FogParams).z - HPosition.w) * G(FogParams).w);
|
||||
|
||||
OUT.View_Depth = float4(G(CameraPosition).xyz - posWorld, HPosition.w);
|
||||
|
||||
#ifdef CLASSIC_GOURAUD
|
||||
float4 albedo = color;
|
||||
|
||||
float4 light = lgridSample(TEXTURE(LightMap), TEXTURE(LightMapLookup), OUT.LightPosition_Fog.xyz);
|
||||
Shade(float3(1,1,1), normalize(OUT.Normal), normalize(OUT.View_Depth.xyz), .71, 81, light, OUT.Diffuse, OUT.Specular);
|
||||
#endif
|
||||
#if defined(PIN_HQ) || defined(PIN_REFLECTION)
|
||||
//float4 edgeDistances = IN.EdgeDistances*G(FadeDistance_GlowFactor).z + 0.5 * OUT.View_Depth.w * G(FadeDistance_GlowFactor).y;
|
||||
|
||||
OUT.Reflection = IN.Extra.a / 255.f;
|
||||
OUT.EdgeDistances = IN.EdgeDistances;
|
||||
#endif
|
||||
|
||||
OUT.PosLightSpace.xyz = shadowPrepareSample(posWorld);
|
||||
|
||||
return OUT;
|
||||
}
|
||||
|
||||
#ifdef PIN_SURFACE
|
||||
struct SurfaceInput
|
||||
{
|
||||
float4 Color;
|
||||
float2 Uv;
|
||||
float2 UvStuds;
|
||||
|
||||
#ifdef PIN_REFLECTION
|
||||
float Reflectance;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct Surface
|
||||
{
|
||||
float3 albedo;
|
||||
float3 normal;
|
||||
float specular;
|
||||
float gloss;
|
||||
float reflectance;
|
||||
};
|
||||
|
||||
Surface surfaceShader(SurfaceInput IN, float2 fade);
|
||||
|
||||
Surface surfaceShaderExec(VertexOutput IN)
|
||||
{
|
||||
SurfaceInput SIN;
|
||||
SIN.Color = IN.Color;
|
||||
SIN.Uv = IN.Uv.xy;
|
||||
SIN.UvStuds = IN.UvStuds.xy;
|
||||
|
||||
#ifdef PIN_REFLECTION
|
||||
SIN.Reflectance = IN.Reflection;
|
||||
#endif
|
||||
|
||||
float2 fade;
|
||||
fade.x = saturate0(1 - IN.View_Depth.w * LQMAT_FADE_FACTOR );
|
||||
fade.y = saturate0(1 - IN.View_Depth.w * G(FadeDistance_GlowFactor).y );
|
||||
|
||||
return surfaceShader(SIN, fade);
|
||||
}
|
||||
#endif
|
||||
|
||||
uniform float4 LqmatFarTilingFactor; // material tiling factor for low-quality shader, must be the same as CFG_FAR_TILING
|
||||
|
||||
|
||||
float4 sampleFar1(TEXTURE_IN_2D(s), float2 uv, float fade, float cutoff)
|
||||
{
|
||||
#ifdef GLSLES
|
||||
return tex2D(s, uv);
|
||||
#else
|
||||
if (cutoff == 0)
|
||||
return tex2D(s, uv);
|
||||
else
|
||||
{
|
||||
float cscale = 1 / (1 - cutoff);
|
||||
|
||||
return lerp(tex2D(s, uv * (LqmatFarTilingFactor.xy) ), tex2D(s, uv ), saturate0(fade * cscale - cutoff * cscale));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//#if defined(PIN_WANG) || defined(PIN_WANG_FALLBACK)
|
||||
float4 sampleWangSimple(TEXTURE_IN_2D(s), float2 uv)
|
||||
{
|
||||
float2 wangUv;
|
||||
float4 wangUVDerivatives;
|
||||
getWang(TEXTURE_WANG(NormalDetailMap), uv, 1, wangUv, wangUVDerivatives);
|
||||
return sampleWang(TEXTURE(s), wangUv, wangUVDerivatives);
|
||||
}
|
||||
//#endif
|
||||
|
||||
|
||||
#ifndef ALREADY_HAS_PS
|
||||
|
||||
#define SPEC_EXPON 81 //81
|
||||
#define KS .75
|
||||
|
||||
#define FADE_DIST 500
|
||||
#define FADE_DIST_START 0
|
||||
|
||||
void DefaultPS(VertexOutput IN,
|
||||
#ifdef PIN_GBUFFER
|
||||
out float4 oColor1: COLOR1,
|
||||
#endif
|
||||
out float4 oColor0: COLOR0)
|
||||
{
|
||||
float normalStrength = .4;
|
||||
float fade = saturate(normalStrength - (IN.View_Depth.w - FADE_DIST_START) / FADE_DIST);
|
||||
float3 nn = normalize(IN.Normal);
|
||||
float4 edgeDistances = IN.EdgeDistances;
|
||||
|
||||
float4 albedo = IN.Color;
|
||||
float2 uv;
|
||||
|
||||
#ifndef PIN_MESH
|
||||
uv = IN.Uv;
|
||||
|
||||
float3x3 normalMatrix = {
|
||||
IN.Tangent.xyz,
|
||||
cross(nn, IN.Tangent.xyz),
|
||||
nn
|
||||
};
|
||||
//tn = tex2D(NormalMap, uv) - .5;//studs normal
|
||||
float3 tn = float3(0,0,.5);
|
||||
tn = lerp(float3(0, 0, .5), tn, fade);
|
||||
tn = CalcBevel(edgeDistances, tn, IN.View_Depth.w);
|
||||
nn = mul(tn, normalMatrix);
|
||||
|
||||
float4 colorTex = tex2D(DiffuseMap, uv);
|
||||
albedo *= colorTex;
|
||||
|
||||
//albedo = lerp(albedo, colorTex.xyz, colorTex.w);//studs normal
|
||||
//albedo += (colorTex.x * 2 - 1) * .07;//studs normal
|
||||
#else
|
||||
uv = IN.Uv;
|
||||
float4 colorTex = tex2D(DiffuseMap, uv);
|
||||
albedo *= colorTex;
|
||||
#endif
|
||||
|
||||
float3 vn = normalize(IN.View_Depth.xyz);
|
||||
float4 light = lgridSample(TEXTURE(LightMap), TEXTURE(LightMapLookup), IN.LightPosition_Fog.xyz);
|
||||
|
||||
float3 diffusePhong;
|
||||
float3 diffuse;
|
||||
float3 specularPhong;
|
||||
float3 specular;
|
||||
#ifdef CLASSIC_GOURAUD
|
||||
diffuse = lerp(diffusePhong, IN.Diffuse * albedo.rgb, 1.0);
|
||||
specular = lerp(specularPhong, IN.Specular, 1.0);
|
||||
#else
|
||||
Shade(albedo.rgb, nn, vn, KS, SPEC_EXPON, light, diffusePhong, specularPhong);
|
||||
diffuse = diffusePhong;
|
||||
specular = specularPhong;
|
||||
#endif
|
||||
|
||||
#ifndef PIN_MESH
|
||||
//diffuse = lerp(diffuse, colorTex.xyz, colorTex.w);
|
||||
#endif
|
||||
|
||||
float3 result = diffuse + specular;
|
||||
|
||||
#ifdef PIN_REFLECTION
|
||||
float3 reflection = texCUBE(EnvironmentMap, reflect(-vn, nn)).rgb;
|
||||
result = lerp(result, reflection, IN.Reflection);
|
||||
#endif
|
||||
|
||||
float fogAlpha = saturate((G(FogParams).z - length(IN.View_Depth.xyz)) * G(FogParams).w);
|
||||
result = lerp(G(FogColor), result, fogAlpha);
|
||||
|
||||
oColor0 = float4(result, albedo.a);
|
||||
|
||||
#ifdef PIN_GBUFFER
|
||||
oColor1 = gbufferPack(IN.View_Depth.w, diffuse.rgb, specular.rgb, fogAlpha);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
#else
|
||||
#include "common.h"
|
||||
|
||||
#define LQMAT_FADE_FACTOR (1.0f/300.0f)
|
||||
|
||||
struct Appdata
|
||||
{
|
||||
float4 Position : POSITION;
|
||||
float3 Normal : NORMAL;
|
||||
float2 Uv : TEXCOORD0;
|
||||
float2 UvStuds : TEXCOORD1;
|
||||
|
||||
float4 Color : COLOR0;
|
||||
ATTR_INT4 Extra : COLOR1;
|
||||
|
||||
#ifdef PIN_SURFACE
|
||||
float3 Tangent : TEXCOORD2;
|
||||
#endif
|
||||
float4 EdgeDistances : TEXCOORD3;
|
||||
};
|
||||
|
||||
struct VertexOutput
|
||||
{
|
||||
float4 Uv_EdgeDistance1 : TEXCOORD0;
|
||||
float4 UvStuds_EdgeDistance2 : TEXCOORD1;
|
||||
|
||||
float4 Color : COLOR0;
|
||||
float4 LightPosition_Fog : TEXCOORD2;
|
||||
|
||||
float4 View_Depth : TEXCOORD3;
|
||||
#if defined(PIN_HQ) || defined(PIN_REFLECTION)
|
||||
float4 Normal_SpecPower : TEXCOORD4;
|
||||
#endif
|
||||
|
||||
#ifdef PIN_SURFACE
|
||||
float3 Tangent : TEXCOORD5;
|
||||
#else
|
||||
float4 Diffuse_Specular : COLOR1;
|
||||
#endif
|
||||
|
||||
float4 PosLightSpace_Reflectance: TEXCOORD6;
|
||||
};
|
||||
|
||||
#ifdef PIN_SKINNED
|
||||
WORLD_MATRIX_ARRAY(WorldMatrixArray, MAX_BONE_COUNT * 3);
|
||||
#endif
|
||||
|
||||
#ifdef PIN_DEBUG
|
||||
uniform float4 DebugColor;
|
||||
#endif
|
||||
|
||||
VertexOutput DefaultVS(Appdata IN, out float4 HPosition: POSITION)
|
||||
{
|
||||
VertexOutput OUT = (VertexOutput)0;
|
||||
|
||||
// Transform position and normal to world space
|
||||
#ifdef PIN_SKINNED
|
||||
int boneIndex = IN.Extra.r;
|
||||
|
||||
float4 worldRow0 = WorldMatrixArray[boneIndex * 3 + 0];
|
||||
float4 worldRow1 = WorldMatrixArray[boneIndex * 3 + 1];
|
||||
float4 worldRow2 = WorldMatrixArray[boneIndex * 3 + 2];
|
||||
|
||||
float3 posWorld = float3(dot(worldRow0, IN.Position), dot(worldRow1, IN.Position), dot(worldRow2, IN.Position));
|
||||
float3 normalWorld = float3(dot(worldRow0.xyz, IN.Normal), dot(worldRow1.xyz, IN.Normal), dot(worldRow2.xyz, IN.Normal));
|
||||
#else
|
||||
float3 posWorld = IN.Position.xyz;
|
||||
float3 normalWorld = IN.Normal;
|
||||
#endif
|
||||
|
||||
// Decode diffuse/specular parameters; encoding depends on the skinned flag due to vertex declaration differences
|
||||
#if defined(PIN_DEBUG)
|
||||
float4 color = DebugColor;
|
||||
#else
|
||||
float4 color = IN.Color;
|
||||
#endif
|
||||
|
||||
float specularIntensity = IN.Extra.g / 255.f;
|
||||
float specularPower = IN.Extra.b;
|
||||
|
||||
float ndotl = dot(normalWorld, -G(Lamp0Dir));
|
||||
|
||||
#ifdef PIN_HQ
|
||||
// We'll calculate specular in pixel shader
|
||||
float2 lt = float2(saturate(ndotl), (ndotl > 0));
|
||||
#else
|
||||
// Using lit here improves performance on software vertex shader implementations
|
||||
float2 lt = lit(ndotl, dot(normalize(-G(Lamp0Dir) + normalize(G(CameraPosition).xyz - posWorld.xyz)), normalWorld), specularPower).yz;
|
||||
#endif
|
||||
|
||||
HPosition = mul(G(ViewProjection), float4(posWorld, 1));
|
||||
|
||||
OUT.Uv_EdgeDistance1.xy = IN.Uv;
|
||||
OUT.UvStuds_EdgeDistance2.xy = IN.UvStuds;
|
||||
|
||||
OUT.Color = color;
|
||||
OUT.LightPosition_Fog = float4(lgridPrepareSample(lgridOffset(posWorld, normalWorld)), (G(FogParams).z - HPosition.w) * G(FogParams).w);
|
||||
|
||||
OUT.View_Depth = float4(G(CameraPosition).xyz - posWorld, HPosition.w);
|
||||
|
||||
#if defined(PIN_HQ) || defined(PIN_REFLECTION)
|
||||
float4 edgeDistances = IN.EdgeDistances*G(FadeDistance_GlowFactor).z + 0.5 * OUT.View_Depth.w * G(FadeDistance_GlowFactor).y;
|
||||
|
||||
OUT.Uv_EdgeDistance1.zw = edgeDistances.xy;
|
||||
OUT.UvStuds_EdgeDistance2.zw = edgeDistances.zw;
|
||||
OUT.Normal_SpecPower = float4(normalWorld, specularPower);
|
||||
OUT.PosLightSpace_Reflectance.w = IN.Extra.a / 255.f;
|
||||
#endif
|
||||
|
||||
#ifdef PIN_SURFACE
|
||||
#ifdef PIN_SKINNED
|
||||
float3 tangent = float3(dot(worldRow0.xyz, IN.Tangent), dot(worldRow1.xyz, IN.Tangent), dot(worldRow2.xyz, IN.Tangent));
|
||||
#else
|
||||
float3 tangent = IN.Tangent;
|
||||
#endif
|
||||
|
||||
OUT.Tangent = tangent;
|
||||
#else
|
||||
float3 diffuse = lt.x * G(Lamp0Color) + max(-ndotl, 0) * G(Lamp1Color);
|
||||
|
||||
OUT.Diffuse_Specular = float4(diffuse, lt.y * specularIntensity);
|
||||
#endif
|
||||
|
||||
OUT.PosLightSpace_Reflectance.xyz = shadowPrepareSample(posWorld);
|
||||
|
||||
return OUT;
|
||||
}
|
||||
|
||||
#ifdef PIN_SURFACE
|
||||
struct SurfaceInput
|
||||
{
|
||||
float4 Color;
|
||||
float2 Uv;
|
||||
float2 UvStuds;
|
||||
|
||||
#ifdef PIN_REFLECTION
|
||||
float Reflectance;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct Surface
|
||||
{
|
||||
float3 albedo;
|
||||
float3 normal;
|
||||
float specular;
|
||||
float gloss;
|
||||
float reflectance;
|
||||
};
|
||||
|
||||
Surface surfaceShader(SurfaceInput IN, float2 fade);
|
||||
|
||||
Surface surfaceShaderExec(VertexOutput IN)
|
||||
{
|
||||
SurfaceInput SIN;
|
||||
SIN.Color = IN.Color;
|
||||
SIN.Uv = IN.Uv_EdgeDistance1.xy;
|
||||
SIN.UvStuds = IN.UvStuds_EdgeDistance2.xy;
|
||||
|
||||
#ifdef PIN_REFLECTION
|
||||
SIN.Reflectance = IN.PosLightSpace_Reflectance.w;
|
||||
#endif
|
||||
|
||||
float2 fade;
|
||||
fade.x = saturate0(1 - IN.View_Depth.w * LQMAT_FADE_FACTOR );
|
||||
fade.y = saturate0(1 - IN.View_Depth.w * G(FadeDistance_GlowFactor).y );
|
||||
|
||||
return surfaceShader(SIN, fade);
|
||||
}
|
||||
#endif
|
||||
|
||||
TEX_DECLARE2D(StudsMap, 0);
|
||||
|
||||
LGRID_SAMPLER(LightMap, 1);
|
||||
TEX_DECLARE2D(LightMapLookup, 2);
|
||||
|
||||
TEX_DECLARE2D(ShadowMap, 3);
|
||||
|
||||
TEX_DECLARECUBE(EnvironmentMap, 4);
|
||||
|
||||
TEX_DECLARE2D(DiffuseMap, 5);
|
||||
TEX_DECLARE2D(NormalMap, 6);
|
||||
TEX_DECLARE2D(SpecularMap, 7);
|
||||
|
||||
#ifndef GLSLES
|
||||
TEX_DECLARE2D(NormalDetailMap, 8);
|
||||
#endif
|
||||
|
||||
uniform float4 LqmatFarTilingFactor; // material tiling factor for low-quality shader, must be the same as CFG_FAR_TILING
|
||||
|
||||
|
||||
float4 sampleFar1(TEXTURE_IN_2D(s), float2 uv, float fade, float cutoff)
|
||||
{
|
||||
#ifdef GLSLES
|
||||
return tex2D(s, uv);
|
||||
#else
|
||||
if (cutoff == 0)
|
||||
return tex2D(s, uv);
|
||||
else
|
||||
{
|
||||
float cscale = 1 / (1 - cutoff);
|
||||
|
||||
return lerp(tex2D(s, uv * (LqmatFarTilingFactor.xy) ), tex2D(s, uv ), saturate0(fade * cscale - cutoff * cscale));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(PIN_WANG) || defined(PIN_WANG_FALLBACK)
|
||||
float4 sampleWangSimple(TEXTURE_IN_2D(s), float2 uv)
|
||||
{
|
||||
float2 wangUv;
|
||||
float4 wangUVDerivatives;
|
||||
getWang(TEXTURE_WANG(NormalDetailMap), uv, 1, wangUv, wangUVDerivatives);
|
||||
return sampleWang(TEXTURE(s), wangUv, wangUVDerivatives);
|
||||
}
|
||||
#endif
|
||||
|
||||
void DefaultPS(VertexOutput IN,
|
||||
#ifdef PIN_GBUFFER
|
||||
out float4 oColor1: COLOR1,
|
||||
#endif
|
||||
out float4 oColor0: COLOR0)
|
||||
{
|
||||
// Compute albedo term
|
||||
#ifdef PIN_SURFACE
|
||||
Surface surface = surfaceShaderExec(IN);
|
||||
|
||||
float4 albedo = float4(surface.albedo, IN.Color.a);
|
||||
|
||||
float3 bitangent = cross(IN.Normal_SpecPower.xyz, IN.Tangent.xyz);
|
||||
float3 normal = normalize(surface.normal.x * IN.Tangent.xyz + surface.normal.y * bitangent + surface.normal.z * IN.Normal_SpecPower.xyz);
|
||||
|
||||
float ndotl = dot(normal, -G(Lamp0Dir));
|
||||
|
||||
float3 diffuseIntensity = saturate0(ndotl) * G(Lamp0Color) + max(-ndotl, 0) * G(Lamp1Color);
|
||||
float specularIntensity = step(0, ndotl) * surface.specular;
|
||||
float specularPower = surface.gloss;
|
||||
|
||||
float reflectance = surface.reflectance;
|
||||
#elif PIN_LOWQMAT
|
||||
|
||||
#ifndef CFG_FAR_DIFFUSE_CUTOFF
|
||||
#define CFG_FAR_DIFFUSE_CUTOFF (0.6f)
|
||||
#endif
|
||||
|
||||
#if defined(PIN_WANG) || defined(PIN_WANG_FALLBACK)
|
||||
float4 albedo = sampleWangSimple(TEXTURE(DiffuseMap), IN.Uv_EdgeDistance1.xy);
|
||||
#else
|
||||
float fade = saturate0(1 - IN.View_Depth.w * LQMAT_FADE_FACTOR);
|
||||
float4 albedo = sampleFar1(TEXTURE(DiffuseMap), IN.Uv_EdgeDistance1.xy, fade, CFG_FAR_DIFFUSE_CUTOFF);
|
||||
#endif
|
||||
|
||||
albedo.rgb = lerp(float3(1, 1, 1), IN.Color.rgb, albedo.a ) * albedo.rgb;
|
||||
albedo.a = IN.Color.a;
|
||||
|
||||
float3 diffuseIntensity = IN.Diffuse_Specular.xyz;
|
||||
float specularIntensity = IN.Diffuse_Specular.w;
|
||||
float reflectance = 0;
|
||||
|
||||
#else
|
||||
#ifdef PIN_PLASTIC
|
||||
float4 studs = tex2D(StudsMap, IN.UvStuds_EdgeDistance2.xy);
|
||||
float4 albedo = float4(IN.Color.rgb * (studs.r * 2), IN.Color.a);
|
||||
#else
|
||||
float4 albedo = tex2D(DiffuseMap, IN.Uv_EdgeDistance1.xy) * IN.Color;
|
||||
#endif
|
||||
|
||||
#ifdef PIN_HQ
|
||||
float3 normal = normalize(IN.Normal_SpecPower.xyz);
|
||||
float specularPower = IN.Normal_SpecPower.w;
|
||||
#elif defined(PIN_REFLECTION)
|
||||
float3 normal = IN.Normal_SpecPower.xyz;
|
||||
#endif
|
||||
|
||||
float3 diffuseIntensity = IN.Diffuse_Specular.xyz;
|
||||
float specularIntensity = IN.Diffuse_Specular.w;
|
||||
|
||||
#ifdef PIN_REFLECTION
|
||||
float reflectance = IN.PosLightSpace_Reflectance.w;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
float4 light = lgridSample(TEXTURE(LightMap), TEXTURE(LightMapLookup), IN.LightPosition_Fog.xyz);
|
||||
float shadow = shadowSample(TEXTURE(ShadowMap), IN.PosLightSpace_Reflectance.xyz, light.a);
|
||||
|
||||
// Compute reflection term
|
||||
#if defined(PIN_SURFACE) || defined(PIN_REFLECTION)
|
||||
float3 reflection = texCUBE(EnvironmentMap, reflect(-IN.View_Depth.xyz, normal)).rgb;
|
||||
|
||||
albedo.rgb = lerp(albedo.rgb, reflection.rgb, reflectance);
|
||||
#endif
|
||||
|
||||
// Compute diffuse term
|
||||
float3 diffuse = (G(AmbientColor) + diffuseIntensity * shadow + light.rgb) * albedo.rgb;
|
||||
|
||||
// Compute specular term
|
||||
#ifdef PIN_HQ
|
||||
float3 specular = G(Lamp0Color) * (specularIntensity * shadow * (float)(half)pow(saturate(dot(normal, normalize(-G(Lamp0Dir) + normalize(IN.View_Depth.xyz)))), specularPower));
|
||||
#else
|
||||
float3 specular = G(Lamp0Color) * (specularIntensity * shadow);
|
||||
#endif
|
||||
|
||||
// Combine
|
||||
oColor0.rgb = diffuse.rgb + specular.rgb;
|
||||
oColor0.a = albedo.a;
|
||||
|
||||
#ifdef PIN_HQ
|
||||
float ViewDepthMul = IN.View_Depth.w * G(FadeDistance_GlowFactor).y;
|
||||
float outlineFade = saturate1( ViewDepthMul * G(OutlineBrightness_ShadowInfo).x + G(OutlineBrightness_ShadowInfo).y);
|
||||
float2 minIntermediate = min(IN.Uv_EdgeDistance1.wz, IN.UvStuds_EdgeDistance2.wz);
|
||||
float minEdgesPlus = min(minIntermediate.x, minIntermediate.y) / ViewDepthMul;
|
||||
oColor0.rgb *= saturate1(outlineFade *(1.5 - minEdgesPlus) + minEdgesPlus);
|
||||
#endif
|
||||
|
||||
float fogAlpha = saturate(IN.LightPosition_Fog.w);
|
||||
|
||||
#ifdef PIN_NEON
|
||||
oColor0.rgb = IN.Color.rgb * G(FadeDistance_GlowFactor).w;
|
||||
oColor0.a = 1 - fogAlpha * IN.Color.a;
|
||||
diffuse.rgb = 0;
|
||||
specular.rgb = 0;
|
||||
#endif
|
||||
|
||||
oColor0.rgb = lerp(G(FogColor), oColor0.rgb, fogAlpha);
|
||||
|
||||
#ifdef PIN_GBUFFER
|
||||
oColor1 = gbufferPack(IN.View_Depth.w, diffuse.rgb, specular.rgb, fogAlpha);
|
||||
#endif
|
||||
|
||||
}
|
||||
#endif
|
||||
73
client/common/shaders/source/diamondplate.hlsl
Normal file
73
client/common/shaders/source/diamondplate.hlsl
Normal file
@@ -0,0 +1,73 @@
|
||||
#ifdef CLASSIC
|
||||
#define PIN_SURFACE
|
||||
#define ALREADY_HAS_PS
|
||||
#include "default.hlsl"
|
||||
|
||||
#define SPEC_EXPON 25
|
||||
#define KS .9
|
||||
#define MIN_BACKLIGHT .9
|
||||
|
||||
void DefaultPS(VertexOutput IN,
|
||||
#ifdef PIN_GBUFFER
|
||||
out float4 oColor1: COLOR1,
|
||||
#endif
|
||||
out float4 oColor0: COLOR0)
|
||||
{
|
||||
float3 normal = normalize(IN.Normal);
|
||||
|
||||
float3x3 normalMatrix = {
|
||||
IN.Tangent.xyz,
|
||||
cross(normal, IN.Tangent.xyz),
|
||||
normal
|
||||
};
|
||||
|
||||
float2 uv = IN.Uv.xy * 6; // * 5 * 1.2
|
||||
|
||||
float3 tn = tex2D(NormalMap, uv).yxz - .5;
|
||||
|
||||
tn = lerp(tn, float3(0,0,.5), .7);
|
||||
|
||||
tn = CalcBevel(IN.EdgeDistances, tn, IN.View_Depth.w);
|
||||
|
||||
float3 nn = normalize(mul(tn, normalMatrix));
|
||||
|
||||
float3 vn = normalize(IN.View_Depth.xyz);
|
||||
float4 light = lgridSample(TEXTURE(LightMap), TEXTURE(LightMapLookup), IN.LightPosition_Fog.xyz);
|
||||
light.a = shadowSample(TEXTURE(ShadowMap), IN.PosLightSpace.xyz, light.a);
|
||||
|
||||
float3 diffuse;
|
||||
float3 specular;
|
||||
Shade(IN.Color.xyz, nn, vn, KS, SPEC_EXPON, light, diffuse, specular);
|
||||
|
||||
oColor0 = float4(diffuse + specular, IN.Color.w);
|
||||
|
||||
float fogAlpha = saturate((G(FogParams).z - length(IN.View_Depth.xyz)) * G(FogParams).w);
|
||||
oColor0.xyz = lerp(G(FogColor), oColor0.rgb, fogAlpha);
|
||||
|
||||
#ifdef PIN_GBUFFER
|
||||
oColor1 = gbufferPack(IN.View_Depth.w, diffuse.rgb, specular.rgb, fogAlpha);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
#define CFG_TEXTURE_TILING 1
|
||||
|
||||
#define CFG_DIFFUSE_SCALE 1
|
||||
#define CFG_SPECULAR_SCALE 2.7
|
||||
#define CFG_GLOSS_SCALE 256
|
||||
#define CFG_REFLECTION_SCALE 0
|
||||
|
||||
#define CFG_NORMAL_SHADOW_SCALE 0.5
|
||||
|
||||
#define CFG_SPECULAR_LOD 0.9
|
||||
#define CFG_GLOSS_LOD 160
|
||||
|
||||
#define CFG_NORMAL_DETAIL_TILING 0
|
||||
#define CFG_NORMAL_DETAIL_SCALE 0
|
||||
|
||||
#define CFG_FAR_TILING 0
|
||||
#define CFG_FAR_DIFFUSE_CUTOFF 0
|
||||
#define CFG_FAR_NORMAL_CUTOFF 0
|
||||
#define CFG_FAR_SPECULAR_CUTOFF 0
|
||||
|
||||
#include "material.hlsl"
|
||||
#endif
|
||||
27
client/common/shaders/source/fabric.hlsl
Normal file
27
client/common/shaders/source/fabric.hlsl
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifdef CLASSIC
|
||||
#include "concrete.hlsl"
|
||||
#else
|
||||
#define CFG_TEXTURE_TILING 1
|
||||
|
||||
#define CFG_DIFFUSE_SCALE 1
|
||||
#define CFG_SPECULAR_SCALE 0.2
|
||||
#define CFG_GLOSS_SCALE 128
|
||||
#define CFG_REFLECTION_SCALE 0
|
||||
|
||||
#define CFG_NORMAL_SHADOW_SCALE 0.2
|
||||
|
||||
#define CFG_SPECULAR_LOD 0.03
|
||||
#define CFG_GLOSS_LOD 16
|
||||
|
||||
#define CFG_NORMAL_DETAIL_TILING 0
|
||||
#define CFG_NORMAL_DETAIL_SCALE 0
|
||||
|
||||
#define CFG_FAR_TILING 0
|
||||
#define CFG_FAR_DIFFUSE_CUTOFF 0
|
||||
#define CFG_FAR_NORMAL_CUTOFF 0
|
||||
#define CFG_FAR_SPECULAR_CUTOFF 0
|
||||
|
||||
#define CFG_OPT_BLEND_COLOR
|
||||
|
||||
#include "material.hlsl"
|
||||
#endif
|
||||
50
client/common/shaders/source/gbuffer.hlsl
Normal file
50
client/common/shaders/source/gbuffer.hlsl
Normal file
@@ -0,0 +1,50 @@
|
||||
#include "common.h"
|
||||
|
||||
// .xy = gbuffer width/height, .zw = inverse gbuffer width/height
|
||||
uniform float4 TextureSize;
|
||||
|
||||
TEX_DECLARE2D(tex, 0);
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 pos : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
#if defined(GLSL) || defined(DX11)
|
||||
float4 convertPosition(float4 p)
|
||||
{
|
||||
return p;
|
||||
}
|
||||
#else
|
||||
float4 convertPosition(float4 p)
|
||||
{
|
||||
// half-pixel offset
|
||||
return p + float4(-TextureSize.z, TextureSize.w, 0, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(GLSL)
|
||||
float2 convertUv(float4 p)
|
||||
{
|
||||
return p.xy * 0.5 + 0.5;
|
||||
}
|
||||
#else
|
||||
float2 convertUv(float4 p)
|
||||
{
|
||||
return p.xy * float2(0.5, -0.5) + 0.5;
|
||||
}
|
||||
#endif
|
||||
|
||||
v2f gbufferVS( in float4 pos : POSITION )
|
||||
{
|
||||
v2f o;
|
||||
o.pos = convertPosition(pos);
|
||||
o.uv = convertUv(pos);
|
||||
return o;
|
||||
}
|
||||
|
||||
float4 gbufferPS( v2f i ) : COLOR0
|
||||
{
|
||||
return tex2D( tex, i.uv );
|
||||
}
|
||||
47
client/common/shaders/source/globals.h
Normal file
47
client/common/shaders/source/globals.h
Normal file
@@ -0,0 +1,47 @@
|
||||
#ifndef GLSL
|
||||
struct Globals
|
||||
{
|
||||
#endif
|
||||
float4x4 ViewProjection;
|
||||
|
||||
float4 ViewRight;
|
||||
float4 ViewUp;
|
||||
float4 ViewDir;
|
||||
float3 CameraPosition;
|
||||
|
||||
float3 AmbientColor;
|
||||
float3 Lamp0Color;
|
||||
float3 Lamp0Dir;
|
||||
float3 Lamp1Color;
|
||||
|
||||
float3 FogColor;
|
||||
float4 FogParams;
|
||||
|
||||
float4 LightBorder;
|
||||
float4 LightConfig0;
|
||||
float4 LightConfig1;
|
||||
float4 LightConfig2;
|
||||
float4 LightConfig3;
|
||||
|
||||
float4 FadeDistance_GlowFactor;
|
||||
float4 OutlineBrightness_ShadowInfo;
|
||||
|
||||
float4 ShadowMatrix0;
|
||||
float4 ShadowMatrix1;
|
||||
float4 ShadowMatrix2;
|
||||
#ifndef GLSL
|
||||
};
|
||||
|
||||
#ifdef DX11
|
||||
cbuffer Globals : register(b0)
|
||||
{
|
||||
Globals _G;
|
||||
};
|
||||
#else
|
||||
uniform Globals _G : register(c0);
|
||||
#endif
|
||||
|
||||
#define G(x) _G.x
|
||||
#else
|
||||
#define G(x) x
|
||||
#endif
|
||||
27
client/common/shaders/source/granite.hlsl
Normal file
27
client/common/shaders/source/granite.hlsl
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifdef CLASSIC
|
||||
#include "ice.hlsl"
|
||||
#else
|
||||
#define CFG_TEXTURE_TILING 1
|
||||
|
||||
#define CFG_DIFFUSE_SCALE 1
|
||||
#define CFG_SPECULAR_SCALE 0.5
|
||||
#define CFG_GLOSS_SCALE 128
|
||||
#define CFG_REFLECTION_SCALE 0.2
|
||||
|
||||
#define CFG_NORMAL_SHADOW_SCALE 0.1
|
||||
|
||||
#define CFG_SPECULAR_LOD 0.19
|
||||
#define CFG_GLOSS_LOD 24
|
||||
|
||||
#define CFG_NORMAL_DETAIL_TILING 0
|
||||
#define CFG_NORMAL_DETAIL_SCALE 0
|
||||
|
||||
#define CFG_FAR_TILING 0.25
|
||||
#define CFG_FAR_DIFFUSE_CUTOFF 0.6
|
||||
#define CFG_FAR_NORMAL_CUTOFF 0
|
||||
#define CFG_FAR_SPECULAR_CUTOFF 0
|
||||
|
||||
#define CFG_OPT_NORMAL_CONST
|
||||
|
||||
#include "material.hlsl"
|
||||
#endif
|
||||
98
client/common/shaders/source/grass.hlsl
Normal file
98
client/common/shaders/source/grass.hlsl
Normal file
@@ -0,0 +1,98 @@
|
||||
#ifdef CLASSIC
|
||||
#define PIN_SURFACE
|
||||
#define ALREADY_HAS_PS
|
||||
#include "default.hlsl"
|
||||
|
||||
#define SPEC_EXPON 50
|
||||
#define KS .1
|
||||
|
||||
#define NOISE_SCALE float3(0.09, 0.02, 0.004);
|
||||
#define SPREAD .3
|
||||
#define GRASS_THRESHOLD .95
|
||||
|
||||
#define FADE_DIST 300//133.33 fix!!!!!!!!!!
|
||||
#define FADE_DIST_START 20
|
||||
|
||||
void DefaultPS(VertexOutput IN,
|
||||
#ifdef PIN_GBUFFER
|
||||
out float4 oColor1: COLOR1,
|
||||
#endif
|
||||
out float4 oColor0: COLOR0)
|
||||
{
|
||||
float3 nn = normalize(IN.Normal);
|
||||
|
||||
float3x3 normalMatrix = {
|
||||
IN.Tangent.xyz,
|
||||
cross(nn, IN.Tangent.xyz),
|
||||
nn
|
||||
};
|
||||
|
||||
float fade = saturate(1 - (IN.View_Depth.w - FADE_DIST_START) / FADE_DIST);
|
||||
|
||||
float2 uv = IN.Uv.xy;
|
||||
|
||||
float3 shiftPos = DisplaceCoord(IN.Pos.xyz);
|
||||
float3 ns = NOISE_SCALE;
|
||||
float noiseval2 = tex3D(SpecularMap,shiftPos.xyz*ns.x).x * 0.4;
|
||||
float noiseval = tex3D(SpecularMap,shiftPos.zyx*ns.y).x * 0.6;
|
||||
noiseval -= noiseval2;
|
||||
float noiseval3 = tex3D(SpecularMap,shiftPos.xyz*ns.z).x * 0.3;
|
||||
noiseval += noiseval3;
|
||||
|
||||
float interp = (noiseval - GRASS_THRESHOLD + SPREAD)/2/SPREAD+0.5;
|
||||
interp = clamp(interp,0,1);
|
||||
|
||||
float3 grassColor = tex2D(DiffuseMap, uv).xyz;
|
||||
float3 dirt = tex2D(NormalMap,uv).xyz;
|
||||
|
||||
float3 albedo = IN.Color.xyz;
|
||||
albedo = lerp(grassColor + IN.Color.xyz - float3(0.31,0.43,0.146), dirt, interp * fade);
|
||||
|
||||
float3 grassNorm = tex2D(StudsMap,uv).xyz;
|
||||
float3 dirtNorm = float3(0.5,0.5,1);
|
||||
float3 tn = lerp(grassNorm, dirtNorm, interp) - 0.5;
|
||||
tn = CalcBevel(IN.EdgeDistances, tn, IN.View_Depth.w);
|
||||
nn = mul(tn, normalMatrix);
|
||||
|
||||
float3 vn = normalize(IN.View_Depth.xyz);
|
||||
float4 light = lgridSample(TEXTURE(LightMap), TEXTURE(LightMapLookup), IN.LightPosition_Fog.xyz);
|
||||
light.a = shadowSample(TEXTURE(ShadowMap), IN.PosLightSpace.xyz, light.a);
|
||||
|
||||
float3 diffuse;
|
||||
float3 specular;
|
||||
Shade(albedo, nn, vn, KS, SPEC_EXPON, light, diffuse, specular);
|
||||
|
||||
oColor0 = float4(diffuse + specular, IN.Color.w);
|
||||
|
||||
float fogAlpha = saturate((G(FogParams).z - length(IN.View_Depth.xyz)) * G(FogParams).w);
|
||||
oColor0.xyz = lerp(G(FogColor), oColor0.rgb, fogAlpha);
|
||||
|
||||
#ifdef PIN_GBUFFER
|
||||
oColor1 = gbufferPack(IN.View_Depth.w, diffuse.rgb, specular.rgb, fogAlpha);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
#define CFG_TEXTURE_TILING 1
|
||||
|
||||
#define CFG_DIFFUSE_SCALE 1
|
||||
#define CFG_SPECULAR_SCALE 1
|
||||
#define CFG_GLOSS_SCALE 256
|
||||
#define CFG_REFLECTION_SCALE 0
|
||||
|
||||
#define CFG_NORMAL_SHADOW_SCALE 0.5
|
||||
|
||||
#define CFG_SPECULAR_LOD 0.17
|
||||
#define CFG_GLOSS_LOD 18
|
||||
|
||||
#define CFG_NORMAL_DETAIL_TILING 0
|
||||
#define CFG_NORMAL_DETAIL_SCALE 0
|
||||
|
||||
#define CFG_FAR_TILING 0.25
|
||||
#define CFG_FAR_DIFFUSE_CUTOFF 0.6
|
||||
#define CFG_FAR_NORMAL_CUTOFF 0
|
||||
#define CFG_FAR_SPECULAR_CUTOFF 0
|
||||
|
||||
#define CFG_OPT_BLEND_COLOR
|
||||
|
||||
#include "material.hlsl"
|
||||
#endif
|
||||
96
client/common/shaders/source/ice.hlsl
Normal file
96
client/common/shaders/source/ice.hlsl
Normal file
@@ -0,0 +1,96 @@
|
||||
#ifdef CLASSIC
|
||||
#define PIN_SURFACE
|
||||
#define ALREADY_HAS_PS
|
||||
#include "default.hlsl"
|
||||
|
||||
#define SPEC_EXPON 25
|
||||
#define KS .4
|
||||
#define KR .275
|
||||
|
||||
#define NOISE_SCALE 7
|
||||
#define SPREAD .3
|
||||
#define GRASS_THRESHOLD .95
|
||||
|
||||
#define FADE_DIST 260
|
||||
#define FADE_DIST_START 0
|
||||
|
||||
void DefaultPS(VertexOutput IN,
|
||||
#ifdef PIN_GBUFFER
|
||||
out float4 oColor1: COLOR1,
|
||||
#endif
|
||||
out float4 oColor0: COLOR0)
|
||||
{
|
||||
float3 normal = normalize(IN.Normal);
|
||||
|
||||
float3x3 normalMatrix = {
|
||||
IN.Tangent.xyz,
|
||||
cross(normal, IN.Tangent.xyz),
|
||||
normal
|
||||
};
|
||||
|
||||
float fade = saturate(1 - (IN.View_Depth.w - FADE_DIST_START) / FADE_DIST);
|
||||
|
||||
float2 uv = IN.Uv.xy * .1;
|
||||
|
||||
float3 shiftPos = DisplaceCoord(IN.Pos.xyz);
|
||||
|
||||
float noiseval = tex3D(SpecularMap,shiftPos.xyz/NOISE_SCALE*0.1).x;
|
||||
float noiseval2 = tex3D(SpecularMap,shiftPos.xyz/NOISE_SCALE*0.5).x * 0.7 + 0.5;
|
||||
noiseval *= noiseval2;
|
||||
noiseval = 0.3 + noiseval * 0.7;
|
||||
|
||||
float3 albedo = IN.Color.xyz + fade*(noiseval*.2);
|
||||
|
||||
float3 tn = tex2D(NormalMap,uv).xyz - .5;
|
||||
float tNormSum = 0.85 + 0.15 * (tn.x + tn.y + tn.z); //do the thing!!!!!!!!!
|
||||
tn = lerp(float3(0,0,.5), tn, 0.15 * fade);
|
||||
albedo *= ((1-fade) + (fade*tNormSum));
|
||||
|
||||
tn = CalcBevel(IN.EdgeDistances, tn, IN.View_Depth.w);
|
||||
float3 nn = mul(tn, normalMatrix);
|
||||
//nn *= fade;
|
||||
//KS *= fade; //ks is a constant and idk if this dumb shit is worth keeping anyways
|
||||
|
||||
float3 vn = normalize(IN.View_Depth.xyz);
|
||||
float4 light = lgridSample(TEXTURE(LightMap), TEXTURE(LightMapLookup), IN.LightPosition_Fog.xyz);
|
||||
light.a = shadowSample(TEXTURE(ShadowMap), IN.PosLightSpace.xyz, light.a);
|
||||
|
||||
float3 diffuse;
|
||||
float3 specular;
|
||||
Shade(albedo, nn, vn, KS, SPEC_EXPON, light, diffuse, specular);
|
||||
float3 enviroment = texCUBE(EnvironmentMap, reflect(-vn, nn)) * KR;
|
||||
|
||||
oColor0 = float4(diffuse + specular + enviroment, IN.Color.w);
|
||||
|
||||
float fogAlpha = saturate((G(FogParams).z - length(IN.View_Depth.xyz)) * G(FogParams).w);
|
||||
oColor0.xyz = lerp(G(FogColor), oColor0.rgb, fogAlpha);
|
||||
|
||||
#ifdef PIN_GBUFFER
|
||||
oColor1 = gbufferPack(IN.View_Depth.w, diffuse.rgb, specular.rgb, fogAlpha);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
#define CFG_TEXTURE_TILING 1
|
||||
|
||||
#define CFG_DIFFUSE_SCALE 1.0
|
||||
#define CFG_SPECULAR_SCALE 1.2
|
||||
#define CFG_GLOSS_SCALE 256
|
||||
#define CFG_REFLECTION_SCALE 0.3
|
||||
|
||||
#define CFG_NORMAL_SHADOW_SCALE 0
|
||||
|
||||
#define CFG_SPECULAR_LOD 1
|
||||
#define CFG_GLOSS_LOD 190
|
||||
|
||||
#define CFG_NORMAL_DETAIL_TILING 0
|
||||
#define CFG_NORMAL_DETAIL_SCALE 0
|
||||
|
||||
#define CFG_FAR_TILING 0.25
|
||||
#define CFG_FAR_DIFFUSE_CUTOFF 0
|
||||
#define CFG_FAR_NORMAL_CUTOFF 0
|
||||
#define CFG_FAR_SPECULAR_CUTOFF 0.75
|
||||
|
||||
#define CFG_OPT_DIFFUSE_CONST
|
||||
|
||||
#include "material.hlsl"
|
||||
#endif
|
||||
27
client/common/shaders/source/marble.hlsl
Normal file
27
client/common/shaders/source/marble.hlsl
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifdef CLASSIC
|
||||
#include "slate.hlsl"
|
||||
#else
|
||||
#define CFG_TEXTURE_TILING 1
|
||||
|
||||
#define CFG_DIFFUSE_SCALE 1
|
||||
#define CFG_SPECULAR_SCALE 1.0
|
||||
#define CFG_GLOSS_SCALE 128
|
||||
#define CFG_REFLECTION_SCALE 0.2
|
||||
|
||||
#define CFG_NORMAL_SHADOW_SCALE 0.1
|
||||
|
||||
#define CFG_SPECULAR_LOD 0.7
|
||||
#define CFG_GLOSS_LOD 54
|
||||
|
||||
#define CFG_NORMAL_DETAIL_TILING 0
|
||||
#define CFG_NORMAL_DETAIL_SCALE 0
|
||||
|
||||
#define CFG_FAR_TILING 0
|
||||
#define CFG_FAR_DIFFUSE_CUTOFF 0
|
||||
#define CFG_FAR_NORMAL_CUTOFF 0
|
||||
#define CFG_FAR_SPECULAR_CUTOFF 0
|
||||
|
||||
#define CFG_OPT_NORMAL_CONST
|
||||
|
||||
#include "material.hlsl"
|
||||
#endif
|
||||
100
client/common/shaders/source/material.hlsl
Normal file
100
client/common/shaders/source/material.hlsl
Normal file
@@ -0,0 +1,100 @@
|
||||
#define PIN_SURFACE
|
||||
#include "default.hlsl"
|
||||
|
||||
#ifndef CFG_WANG_TILES
|
||||
float4 sampleFar(TEXTURE_IN_2D(s), float2 uv, float fade, float cutoff)
|
||||
{
|
||||
#ifdef GLSLES
|
||||
return tex2D(s, uv);
|
||||
#else
|
||||
if (cutoff == 0)
|
||||
return tex2D(s, uv);
|
||||
else
|
||||
{
|
||||
float cscale = 1 / (1 - cutoff);
|
||||
|
||||
return lerp(tex2D(s, uv * (CFG_FAR_TILING) ), tex2D(s, uv ), saturate0(fade * cscale - cutoff * cscale));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
Surface surfaceShader(SurfaceInput IN, float2 fade2)
|
||||
{
|
||||
#ifdef CFG_WANG_TILES
|
||||
float2 wangUv;
|
||||
float4 wangUVDerivatives;
|
||||
getWang(TEXTURE_WANG(NormalDetailMap), IN.Uv, CFG_TEXTURE_TILING, wangUv, wangUVDerivatives);
|
||||
#endif
|
||||
|
||||
float2 uv = IN.Uv * (CFG_TEXTURE_TILING);
|
||||
|
||||
float fadeDiffuse = fade2.x;
|
||||
float fade = fade2.y;
|
||||
|
||||
#ifdef CFG_OPT_DIFFUSE_CONST
|
||||
float4 diffuse = 1;
|
||||
#else
|
||||
|
||||
#ifdef CFG_WANG_TILES
|
||||
float4 diffuse = sampleWang(TEXTURE(DiffuseMap), wangUv, wangUVDerivatives);
|
||||
#else
|
||||
float4 diffuse = sampleFar(TEXTURE(DiffuseMap), uv, fadeDiffuse, CFG_FAR_DIFFUSE_CUTOFF);
|
||||
#endif
|
||||
|
||||
diffuse.rgba = diffuse.rgba * (CFG_DIFFUSE_SCALE);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef CFG_OPT_NORMAL_CONST
|
||||
float3 normal = float3(0, 0, 1);
|
||||
#else
|
||||
#ifdef CFG_WANG_TILES
|
||||
float3 normal = nmapUnpack(sampleWang(TEXTURE(NormalMap), wangUv, wangUVDerivatives));
|
||||
#else
|
||||
float3 normal = nmapUnpack(sampleFar(TEXTURE(NormalMap), uv, fade, CFG_FAR_NORMAL_CUTOFF));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef GLSLES
|
||||
#ifndef CFG_WANG_TILES // normal detail unavailable when running wang tiles
|
||||
float3 normalDetail = nmapUnpack(tex2D(NormalDetailMap, uv * (CFG_NORMAL_DETAIL_TILING)));
|
||||
normal.xy += normalDetail.xy * (CFG_NORMAL_DETAIL_SCALE);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
normal.xy *= fade;
|
||||
|
||||
float shadowFactor = 1 + normal.x * (CFG_NORMAL_SHADOW_SCALE);
|
||||
|
||||
#ifdef CFG_OPT_BLEND_COLOR
|
||||
float3 albedo = lerp(float3(1, 1, 1), IN.Color.rgb, diffuse.a) * diffuse.rgb * shadowFactor;
|
||||
#else
|
||||
float3 albedo = IN.Color.rgb * diffuse.rgb * shadowFactor;
|
||||
#endif
|
||||
|
||||
#ifndef GLSLES
|
||||
float4 studs = tex2D(StudsMap, IN.UvStuds);
|
||||
|
||||
albedo *= studs.r * 2;
|
||||
#endif
|
||||
|
||||
#ifdef CFG_WANG_TILES
|
||||
float2 specular = sampleWang(TEXTURE(SpecularMap), wangUv, wangUVDerivatives).rg;
|
||||
#else
|
||||
float2 specular = sampleFar(TEXTURE(SpecularMap), uv, fade, CFG_FAR_SPECULAR_CUTOFF).rg;
|
||||
#endif
|
||||
|
||||
// make sure glossiness is never 0 to avoid fp specials
|
||||
float2 specbase = specular * float2(CFG_SPECULAR_SCALE, CFG_GLOSS_SCALE) + float2(0, 0.01);
|
||||
float2 specfade = lerp(float2(CFG_SPECULAR_LOD, CFG_GLOSS_LOD), specbase, fade);
|
||||
|
||||
Surface surface = (Surface)0;
|
||||
surface.albedo = albedo;
|
||||
surface.normal = normal;
|
||||
surface.specular = specfade.r;
|
||||
surface.gloss = specfade.g;
|
||||
surface.reflectance = specular.g * fade * (CFG_REFLECTION_SCALE);
|
||||
|
||||
return surface;
|
||||
}
|
||||
158
client/common/shaders/source/megacluster.hlsl
Normal file
158
client/common/shaders/source/megacluster.hlsl
Normal file
@@ -0,0 +1,158 @@
|
||||
#include "common.h"
|
||||
|
||||
struct Appdata
|
||||
{
|
||||
ATTR_INT4 Position : POSITION;
|
||||
ATTR_INT3 Normal : NORMAL;
|
||||
ATTR_INT4 Uv : TEXCOORD0;
|
||||
#ifdef PIN_HQ
|
||||
ATTR_INT4 EdgeDistances : TEXCOORD1;
|
||||
ATTR_INT3 Tangent : TEXCOORD2;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct VertexOutput
|
||||
{
|
||||
float4 HPosition : POSITION;
|
||||
|
||||
float4 UvHigh_EdgeDistance1 : TEXCOORD0;
|
||||
float4 UvLow_EdgeDistance2 : TEXCOORD1;
|
||||
|
||||
float4 LightPosition_Fog : TEXCOORD2;
|
||||
|
||||
#ifdef PIN_HQ
|
||||
float4 View_Depth : TEXCOORD3;
|
||||
float4 Normal_Blend : TEXCOORD4;
|
||||
float3 Tangent : TEXCOORD5;
|
||||
#else
|
||||
float4 Diffuse_Blend : COLOR0;
|
||||
#endif
|
||||
|
||||
float3 PosLightSpace : TEXCOORD7;
|
||||
};
|
||||
|
||||
WORLD_MATRIX(WorldMatrix);
|
||||
|
||||
VertexOutput MegaClusterVS(Appdata IN)
|
||||
{
|
||||
VertexOutput OUT = (VertexOutput)0;
|
||||
|
||||
// Decode vertex data
|
||||
float3 Normal = (IN.Normal - 127.0) / 127.0;
|
||||
float4 UV = IN.Uv / 2048.0;
|
||||
|
||||
// Transform position and normal to world space
|
||||
// Note: world matrix does not contain rotation/scale for static geometry so we can avoid transforming normal
|
||||
float3 posWorld = mul(WorldMatrix, IN.Position).xyz;
|
||||
float3 normalWorld = Normal;
|
||||
|
||||
OUT.HPosition = mul(G(ViewProjection), float4(posWorld, 1));
|
||||
|
||||
float blend = OUT.HPosition.w / 200;
|
||||
|
||||
OUT.LightPosition_Fog = float4(lgridPrepareSample(lgridOffset(posWorld, normalWorld)), (G(FogParams).z - OUT.HPosition.w) * G(FogParams).w);
|
||||
|
||||
OUT.UvHigh_EdgeDistance1.xy = UV.xy;
|
||||
OUT.UvLow_EdgeDistance2.xy = UV.zw;
|
||||
|
||||
#ifdef PIN_HQ
|
||||
OUT.View_Depth = float4(posWorld, OUT.HPosition.w * G(FadeDistance_GlowFactor).y);
|
||||
float4 edgeDistances = IN.EdgeDistances*G(FadeDistance_GlowFactor).z + 0.5 * OUT.View_Depth.w;
|
||||
|
||||
OUT.UvHigh_EdgeDistance1.zw = edgeDistances.xy;
|
||||
OUT.UvLow_EdgeDistance2.zw = edgeDistances.zw;
|
||||
|
||||
OUT.View_Depth.xyz = G(CameraPosition).xyz - posWorld;
|
||||
OUT.Normal_Blend = float4(Normal, blend);
|
||||
// decode tangent
|
||||
OUT.Tangent = (IN.Tangent - 127.0) / 127.0;
|
||||
#else
|
||||
// IF LQ shading is performed in VS
|
||||
float ndotl = dot(normalWorld, -G(Lamp0Dir));
|
||||
float3 diffuse = saturate(ndotl) * G(Lamp0Color) + max(-ndotl, 0) * G(Lamp1Color);
|
||||
|
||||
OUT.Diffuse_Blend = float4(diffuse, blend);
|
||||
#endif
|
||||
|
||||
OUT.PosLightSpace = shadowPrepareSample(posWorld);
|
||||
|
||||
return OUT;
|
||||
}
|
||||
|
||||
TEX_DECLARE2D(DiffuseHighMap, 0);
|
||||
TEX_DECLARE2D(DiffuseLowMap, 1);
|
||||
TEX_DECLARE2D(NormalMap, 2);
|
||||
TEX_DECLARE2D(SpecularMap, 3);
|
||||
LGRID_SAMPLER(LightMap, 4);
|
||||
TEX_DECLARE2D(LightMapLookup, 5);
|
||||
TEX_DECLARE2D(ShadowMap, 6);
|
||||
|
||||
void MegaClusterPS(VertexOutput IN,
|
||||
#ifdef PIN_GBUFFER
|
||||
out float4 oColor1: COLOR1,
|
||||
#endif
|
||||
out float4 oColor0: COLOR0)
|
||||
{
|
||||
float4 high = tex2D(DiffuseHighMap, IN.UvHigh_EdgeDistance1.xy);
|
||||
float4 low = tex2D(DiffuseLowMap, IN.UvLow_EdgeDistance2.xy);
|
||||
|
||||
float4 light = lgridSample(TEXTURE(LightMap), TEXTURE(LightMapLookup), IN.LightPosition_Fog.xyz);
|
||||
float shadow = shadowSample(TEXTURE(ShadowMap), IN.PosLightSpace, light.a);
|
||||
|
||||
#ifdef PIN_HQ
|
||||
float3 albedo = lerp(high.rgb, low.rgb, saturate1(IN.Normal_Blend.a));
|
||||
|
||||
// sample normal map and specular map
|
||||
float4 normalMapSample = tex2D(NormalMap, IN.UvHigh_EdgeDistance1.xy);
|
||||
float4 specularMapSample = tex2D(SpecularMap, IN.UvHigh_EdgeDistance1.xy);
|
||||
|
||||
// compute bitangent and world space normal
|
||||
float3 bitangent = cross(IN.Normal_Blend.xyz, IN.Tangent.xyz);
|
||||
#ifdef CLASSIC
|
||||
float3 nmap = float3(0,0,.5);
|
||||
#else
|
||||
float3 nmap = nmapUnpack(normalMapSample);
|
||||
#endif
|
||||
float3 normal = normalize(nmap.x * IN.Tangent.xyz + nmap.y * bitangent + nmap.z * IN.Normal_Blend.xyz);
|
||||
|
||||
float ndotl = dot(normal, -G(Lamp0Dir));
|
||||
float3 diffuseIntensity = saturate0(ndotl) * G(Lamp0Color) + max(-ndotl, 0) * G(Lamp1Color);
|
||||
float specularIntensity = step(0, ndotl) * specularMapSample.r;
|
||||
float specularPower = specularMapSample.g * 255 + 0.01;
|
||||
|
||||
// Compute diffuse and specular and combine them
|
||||
float3 diffuse = (G(AmbientColor) + diffuseIntensity * shadow + light.rgb) * albedo.rgb;
|
||||
float3 specular = G(Lamp0Color) * (specularIntensity * shadow * (float)(half)pow(saturate(dot(normal, normalize(-G(Lamp0Dir) + normalize(IN.View_Depth.xyz)))), specularPower));
|
||||
oColor0.rgb = diffuse + specular;
|
||||
|
||||
// apply outlines
|
||||
float outlineFade = saturate1(IN.View_Depth.w * G(OutlineBrightness_ShadowInfo).x + G(OutlineBrightness_ShadowInfo).y);
|
||||
float2 minIntermediate = min(IN.UvHigh_EdgeDistance1.wz, IN.UvLow_EdgeDistance2.wz);
|
||||
float minEdgesPlus = min(minIntermediate.x, minIntermediate.y) / IN.View_Depth.w;
|
||||
oColor0.rgb *= saturate1(outlineFade * (1.5 - minEdgesPlus) + minEdgesPlus);
|
||||
|
||||
oColor0.a = 1;
|
||||
|
||||
#else
|
||||
float3 albedo = lerp(high.rgb, low.rgb, saturate1(IN.Diffuse_Blend.a));
|
||||
|
||||
// Compute diffuse term
|
||||
float3 diffuse = (G(AmbientColor) + IN.Diffuse_Blend.rgb * shadow + light.rgb) * albedo.rgb;
|
||||
|
||||
// Combine
|
||||
oColor0.rgb = diffuse;
|
||||
oColor0.a = 1;
|
||||
|
||||
#endif
|
||||
|
||||
float fogAlpha = saturate(IN.LightPosition_Fog.w);
|
||||
|
||||
oColor0.rgb = lerp(G(FogColor), oColor0.rgb, fogAlpha);
|
||||
#ifdef CLASSIC
|
||||
oColor0.rgb = IN.UvHigh_EdgeDistance1.xyy;
|
||||
oColor0.rgb = G(OutlineBrightness_ShadowInfo).xxx;
|
||||
#endif
|
||||
#ifdef PIN_GBUFFER
|
||||
oColor1 = gbufferPack(IN.View_Depth.w*G(FadeDistance_GlowFactor).x, diffuse.rgb, 0, fogAlpha);
|
||||
#endif
|
||||
}
|
||||
25
client/common/shaders/source/metal.hlsl
Normal file
25
client/common/shaders/source/metal.hlsl
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifdef CLASSIC
|
||||
#include "smoothplastic.hlsl"
|
||||
#else
|
||||
#define CFG_TEXTURE_TILING 1
|
||||
|
||||
#define CFG_DIFFUSE_SCALE 1
|
||||
#define CFG_SPECULAR_SCALE 2
|
||||
#define CFG_GLOSS_SCALE 256
|
||||
#define CFG_REFLECTION_SCALE 0
|
||||
|
||||
#define CFG_NORMAL_SHADOW_SCALE 0.3
|
||||
|
||||
#define CFG_SPECULAR_LOD 0.8
|
||||
#define CFG_GLOSS_LOD 120
|
||||
|
||||
#define CFG_NORMAL_DETAIL_TILING 0
|
||||
#define CFG_NORMAL_DETAIL_SCALE 0
|
||||
|
||||
#define CFG_FAR_TILING 0.25
|
||||
#define CFG_FAR_DIFFUSE_CUTOFF 0
|
||||
#define CFG_FAR_NORMAL_CUTOFF 0
|
||||
#define CFG_FAR_SPECULAR_CUTOFF 0.75
|
||||
|
||||
#include "material.hlsl"
|
||||
#endif
|
||||
3
client/common/shaders/source/neon.hlsl
Normal file
3
client/common/shaders/source/neon.hlsl
Normal file
@@ -0,0 +1,3 @@
|
||||
#define PIN_PLASTIC
|
||||
#define PIN_NEON
|
||||
#include "default.hlsl"
|
||||
240
client/common/shaders/source/particle.hlsl
Normal file
240
client/common/shaders/source/particle.hlsl
Normal file
@@ -0,0 +1,240 @@
|
||||
#include "common.h"
|
||||
|
||||
TEX_DECLARE2D(tex, 0);
|
||||
TEX_DECLARE2D(cstrip, 1);
|
||||
TEX_DECLARE2D(astrip, 2);
|
||||
|
||||
uniform float4 throttleFactor; // .x = alpha cutoff, .y = alpha boost (clamp), .w - additive/alpha ratio for Crazy shaders
|
||||
uniform float4 modulateColor;
|
||||
uniform float4 zOffset;
|
||||
|
||||
struct VS_INPUT
|
||||
{
|
||||
float4 pos : POSITION;
|
||||
ATTR_INT4 scaleRotLife : TEXCOORD0; // transform matrix
|
||||
ATTR_INT2 disp : TEXCOORD1; // .xy = corner, either (0,0), (1,0), (0,1), or (1,1)
|
||||
ATTR_INT2 cline: TEXCOORD2; // .x = color line [0...32767]
|
||||
};
|
||||
|
||||
struct VS_OUTPUT
|
||||
{
|
||||
float4 pos : POSITION;
|
||||
float3 uvFog : TEXCOORD0;
|
||||
float2 colorLookup : TEXCOORD1;
|
||||
};
|
||||
|
||||
float4 rotScale( float4 scaleRotLife )
|
||||
{
|
||||
float cr = cos( scaleRotLife.z );
|
||||
float sr = sin( scaleRotLife.z );
|
||||
|
||||
float4 r;
|
||||
r.x = cr * scaleRotLife.x;
|
||||
r.y = -sr * scaleRotLife.x;
|
||||
r.z = sr * scaleRotLife.y;
|
||||
r.w = cr * scaleRotLife.y;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
float4 mulq( float4 a, float4 b )
|
||||
{
|
||||
float3 i = cross( a.xyz, b.xyz ) + a.w * b.xyz + b.w * a.xyz;
|
||||
float r = a.w * b.w - dot( a.xyz, b.xyz );
|
||||
return float4( i, r );
|
||||
}
|
||||
|
||||
float4 conj( float4 a ) { return float4( -a.xyz, a.w ); }
|
||||
|
||||
float4 rotate( float4 v, float4 q )
|
||||
{
|
||||
return mulq( mulq( q, v ), conj( q ) );
|
||||
}
|
||||
|
||||
float4 axis_angle( float3 axis, float angle )
|
||||
{
|
||||
return float4( sin(angle/2) * axis, cos(angle/2) );
|
||||
}
|
||||
|
||||
VS_OUTPUT vs( VS_INPUT input )
|
||||
{
|
||||
VS_OUTPUT o;
|
||||
|
||||
float4 pos = float4( input.pos.xyz, 1 );
|
||||
float2 disp = input.disp.xy * 2 - 1; // -1..1
|
||||
|
||||
float4 scaleRotLifeFlt = (float4)input.scaleRotLife * float4( 1.0f/256.0f, 1.0f/256.0f, 2.0 * 3.1415926f / 32767.0f, 1.0f / 32767.0f );
|
||||
scaleRotLifeFlt.xy += 127.0f;
|
||||
|
||||
float4 rs = rotScale( scaleRotLifeFlt );
|
||||
|
||||
pos += G(ViewRight) * dot( disp, rs.xy );
|
||||
pos += G(ViewUp) * dot( disp, rs.zw );
|
||||
|
||||
float4 pos2 = pos + G(ViewDir)*zOffset.x; // Z-offset position in world space
|
||||
|
||||
o.pos = mul( G(ViewProjection), pos );
|
||||
|
||||
o.uvFog.xy = input.disp.xy;
|
||||
o.uvFog.y = 1 - o.uvFog.y;
|
||||
o.uvFog.z = (G(FogParams).z - o.pos.w) * G(FogParams).w;
|
||||
|
||||
o.colorLookup.x = 1 - max( 0, min(1, scaleRotLifeFlt.w ) );
|
||||
o.colorLookup.y = (float)input.cline.x * (1.0 / 32767.0f);
|
||||
|
||||
|
||||
pos2 = mul( G(ViewProjection), pos2 ); // Z-offset position in clip space
|
||||
o.pos.z = pos2.z * o.pos.w/pos2.w; // Only need z
|
||||
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
float4 psAdd( VS_OUTPUT input ) : COLOR0 // #0
|
||||
{
|
||||
float4 texcolor = tex2D( tex, input.uvFog.xy );
|
||||
float4 vcolor = tex2D( cstrip, input.colorLookup.xy );
|
||||
vcolor.a = tex2D( astrip, input.colorLookup.xy ).r;
|
||||
|
||||
float4 result;
|
||||
|
||||
result.rgb = (texcolor.rgb + vcolor.rgb) * modulateColor.rgb;
|
||||
result.a = texcolor.a * vcolor.a;
|
||||
result.rgb *= result.a;
|
||||
|
||||
result.rgb = lerp( 0.0f.xxx, result.rgb, saturate( input.uvFog.zzz ) );
|
||||
return result;
|
||||
}
|
||||
|
||||
float4 psModulate( VS_OUTPUT input ) : COLOR0 // #1
|
||||
{
|
||||
|
||||
float4 texcolor = tex2D( tex, input.uvFog.xy );
|
||||
float4 vcolor = tex2D( cstrip, input.colorLookup.xy ) * modulateColor;
|
||||
vcolor.a = tex2D( astrip, input.colorLookup.xy ).r * modulateColor.a;
|
||||
|
||||
float4 result;
|
||||
|
||||
result.rgb = texcolor.rgb * vcolor.rgb;
|
||||
result.a = texcolor.a * vcolor.a;
|
||||
|
||||
result.rgb = lerp( G(FogColor).rgb, result.rgb, saturate( input.uvFog.zzz ) );
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// - this shader is crazy
|
||||
// - used instead of additive particles to help see bright particles (e.g. fire) on top of extremely bright backgrounds
|
||||
// - requires ONE | INVSRCALPHA blend mode, useless otherwise
|
||||
// - does not use color strip texture
|
||||
// - outputs a blend between additive blend and alpha blend in fragment alpha
|
||||
// - ratio multiplier is in throttleFactor.w
|
||||
float4 psCrazy( VS_OUTPUT input ) : COLOR0
|
||||
{
|
||||
float4 texcolor = tex2D( tex, input.uvFog.xy );
|
||||
float4 vcolor = float4(1,0,0,0); //tex2D( cstrip, input.colorLookup.xy ); // not actually used
|
||||
vcolor.a = tex2D( astrip, input.colorLookup.xy ).r;
|
||||
float blendRatio = throttleFactor.w; // yeah yeah
|
||||
|
||||
float4 result;
|
||||
|
||||
result.rgb = (texcolor.rgb ) * modulateColor.rgb * vcolor.a * texcolor.a;
|
||||
result.a = blendRatio * texcolor.a * vcolor.a;
|
||||
|
||||
result = lerp( 0.0f.xxxx, result, saturate( input.uvFog.zzzz ) );
|
||||
return result;
|
||||
}
|
||||
|
||||
float4 psCrazySparkles( VS_OUTPUT input ) : COLOR0
|
||||
{
|
||||
float4 texcolor = tex2D( tex, input.uvFog.xy );
|
||||
float4 vcolor = tex2D( cstrip, input.colorLookup.xy );
|
||||
vcolor.a = tex2D( astrip, input.colorLookup.xy ).r;
|
||||
float blendRatio = throttleFactor.w;
|
||||
|
||||
float4 result;
|
||||
|
||||
if( texcolor.a < 0.5f )
|
||||
{
|
||||
result.rgb = vcolor.rgb * modulateColor.rgb * (2 * texcolor.a);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.rgb = lerp( vcolor.rgb * modulateColor.rgb, texcolor.rgb, 2*texcolor.a-1 );
|
||||
}
|
||||
|
||||
//vcolor.a *= modulateColor.a;
|
||||
result.rgb *= vcolor.a;
|
||||
result.a = blendRatio * texcolor.a * vcolor.a;
|
||||
|
||||
result = lerp( 0.0f.xxxx, result, saturate( input.uvFog.zzzz ) );
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct VS_INPUT2
|
||||
{
|
||||
float4 pos : POSITION;
|
||||
ATTR_INT4 scaleRotLife : TEXCOORD0; // transform matrix
|
||||
ATTR_INT2 disp : TEXCOORD1; // .xy = corner, either (0,0), (1,0), (0,1), or (1,1)
|
||||
ATTR_INT2 cline: TEXCOORD2; // .x = color line [0...32767]
|
||||
ATTR_INT4 color: TEXCOORD3; // .xyzw
|
||||
};
|
||||
|
||||
struct VS_OUTPUT2
|
||||
{
|
||||
float4 pos : POSITION;
|
||||
float3 uvFog : TEXCOORD0;
|
||||
float4 color : TEXCOORD1;
|
||||
};
|
||||
|
||||
VS_OUTPUT2 vsCustom( VS_INPUT2 input )
|
||||
{
|
||||
VS_OUTPUT2 o;
|
||||
|
||||
float4 pos = input.pos;
|
||||
float2 disp = input.disp.xy * 2 - 1; // -1..1
|
||||
|
||||
float4 scaleRotLifeFlt = (float4)input.scaleRotLife * float4( 1.0/256.0f, 1.0/256.0f, 2.0 * 3.1415926f / 32767.0, 1.0 / 32767.0f );
|
||||
scaleRotLifeFlt.xy += 127.0f;
|
||||
|
||||
float4 rs = rotScale( scaleRotLifeFlt );
|
||||
|
||||
pos += G(ViewRight) * dot( disp, rs.xy );
|
||||
pos += G(ViewUp) * dot( disp, rs.zw );
|
||||
|
||||
float4 pos2 = pos + G(ViewDir)*zOffset.x; // Z-offset position in world space
|
||||
|
||||
o.pos = mul( G(ViewProjection), pos );
|
||||
|
||||
o.uvFog.xy = input.disp.xy;
|
||||
o.uvFog.y = 1 - o.uvFog.y;
|
||||
o.uvFog.z = (G(FogParams).z - o.pos.w) * G(FogParams).w;
|
||||
|
||||
o.color = input.color * (1/255.0f);
|
||||
|
||||
pos2 = mul( G(ViewProjection), pos2 ); // Z-offset position in clip space
|
||||
o.pos.z = pos2.z * o.pos.w/pos2.w; // Only need z
|
||||
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
float4 psCustom( VS_OUTPUT2 input ) : COLOR0 // #1
|
||||
{
|
||||
float4 texcolor = tex2D( tex, input.uvFog.xy );
|
||||
float4 vcolor = input.color;
|
||||
|
||||
float blendRatio = throttleFactor.w; // yeah yeah
|
||||
|
||||
float4 result;
|
||||
|
||||
result.rgb = texcolor.rgb * vcolor.rgb * vcolor.a * texcolor.a;
|
||||
result.a = blendRatio * texcolor.a * vcolor.a;
|
||||
|
||||
result = lerp( 0.0f.xxxx, result, saturate( input.uvFog.zzzz ) );
|
||||
return result;
|
||||
}
|
||||
25
client/common/shaders/source/pebble.hlsl
Normal file
25
client/common/shaders/source/pebble.hlsl
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifdef CLASSIC
|
||||
#include "slate.hlsl"
|
||||
#else
|
||||
#define CFG_TEXTURE_TILING 1
|
||||
|
||||
#define CFG_DIFFUSE_SCALE 1
|
||||
#define CFG_SPECULAR_SCALE 2.5
|
||||
#define CFG_GLOSS_SCALE 128
|
||||
#define CFG_REFLECTION_SCALE 0
|
||||
|
||||
#define CFG_NORMAL_SHADOW_SCALE 0
|
||||
|
||||
#define CFG_SPECULAR_LOD 0.15
|
||||
#define CFG_GLOSS_LOD 22
|
||||
|
||||
#define CFG_NORMAL_DETAIL_TILING 6
|
||||
#define CFG_NORMAL_DETAIL_SCALE 1.5
|
||||
|
||||
#define CFG_FAR_TILING 0
|
||||
#define CFG_FAR_DIFFUSE_CUTOFF 0
|
||||
#define CFG_FAR_NORMAL_CUTOFF 0
|
||||
#define CFG_FAR_SPECULAR_CUTOFF 0
|
||||
|
||||
#include "material.hlsl"
|
||||
#endif
|
||||
161
client/common/shaders/source/plastic.hlsl
Normal file
161
client/common/shaders/source/plastic.hlsl
Normal file
@@ -0,0 +1,161 @@
|
||||
#ifdef CLASSIC
|
||||
#ifdef PIN_HQ
|
||||
#define PIN_SURFACE
|
||||
#define ALREADY_HAS_PS
|
||||
#include "default.hlsl"
|
||||
|
||||
#define SPEC_EXPON 81 //81
|
||||
#define KS .75
|
||||
|
||||
#define FADE_DIST 500
|
||||
#define FADE_DIST_START 0
|
||||
|
||||
float3 CalcBevelDir(float4 edgeDistances)
|
||||
{
|
||||
float3 dir = float3(0, 0, 0);
|
||||
float4 bevelMultiplier = edgeDistances <= BEVEL_WIDTH;
|
||||
|
||||
dir += bevelMultiplier.x * float3(1, 0, 0);
|
||||
dir += bevelMultiplier.y * float3(-1, 0, 0);
|
||||
dir += bevelMultiplier.z * float3(0, 1, 0);
|
||||
dir += bevelMultiplier.w * float3(0, -1, 0);
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
||||
uniform float4 WaveParams; // .x = frequency .y = phase .z = height .w = lerp
|
||||
|
||||
void DefaultPS(VertexOutput IN,
|
||||
#ifdef PIN_GBUFFER
|
||||
out float4 oColor1: COLOR1,
|
||||
#endif
|
||||
out float4 oColor0: COLOR0)
|
||||
{
|
||||
float normalStrength = .4;
|
||||
float fade = saturate(normalStrength - (IN.View_Depth.w - FADE_DIST_START) / FADE_DIST);
|
||||
float3 nn = normalize(IN.Normal);
|
||||
float4 edgeDistances = IN.EdgeDistances;
|
||||
|
||||
float4 albedo = IN.Color;
|
||||
float2 uv;
|
||||
|
||||
float wt = 1.0;
|
||||
#ifndef PIN_MESH
|
||||
uv = IN.UvStuds;
|
||||
|
||||
float3x3 normalMatrix = {
|
||||
IN.Tangent.xyz,
|
||||
cross(nn, IN.Tangent.xyz),
|
||||
nn
|
||||
};
|
||||
//tn = tex2D(NormalMap, uv) - .5;//studs normal
|
||||
float3 tn = float3(0,0,.5);
|
||||
tn = lerp(float3(0, 0, .5), tn, fade);
|
||||
tn = CalcBevel(edgeDistances, tn, IN.View_Depth.w);
|
||||
nn = mul(tn, normalMatrix);
|
||||
wt = 1.0 - abs(length(tn.xy));
|
||||
float4 colorTex = tex2D(DiffuseMap, uv);
|
||||
|
||||
//albedo = lerp(albedo, colorTex.xyz, colorTex.w);//studs normal
|
||||
//albedo += (colorTex.x * 2 - 1) * .07;//studs normal
|
||||
#else
|
||||
uv = IN.Uv;
|
||||
float4 colorTex = tex2D(DiffuseMap, uv);
|
||||
albedo *= colorTex;
|
||||
#endif
|
||||
|
||||
float3 vn = normalize(IN.View_Depth.xyz);
|
||||
float4 light = lgridSample(TEXTURE(LightMap), TEXTURE(LightMapLookup), IN.LightPosition_Fog.xyz);
|
||||
|
||||
float3 diffuse;
|
||||
float3 specular;
|
||||
|
||||
#ifdef CLASSIC_GOURAUD
|
||||
float3 diffusePhong;
|
||||
float3 specularPhong;
|
||||
|
||||
Shade(albedo.rgb, nn, vn, KS, SPEC_EXPON, light, diffusePhong, specularPhong);
|
||||
diffuse = lerp(diffusePhong, IN.Diffuse * albedo.rgb, wt);
|
||||
specular = lerp(specularPhong, IN.Specular, wt);
|
||||
#else
|
||||
Shade(albedo.rgb, nn, vn, KS, SPEC_EXPON, light, diffuse, specular);
|
||||
#endif
|
||||
#ifndef PIN_MESH
|
||||
diffuse = lerp(diffuse, colorTex.xyz, colorTex.w);
|
||||
#endif
|
||||
|
||||
float3 result = diffuse + specular;
|
||||
|
||||
#ifdef PIN_REFLECTION
|
||||
float3 reflection = texCUBE(EnvironmentMap, reflect(-vn, nn)).rgb;
|
||||
result = lerp(result, reflection, IN.Reflection);
|
||||
#endif
|
||||
|
||||
float fogAlpha = saturate((G(FogParams).z - length(IN.View_Depth.xyz)) * G(FogParams).w);
|
||||
result = lerp(G(FogColor), result, fogAlpha);
|
||||
|
||||
oColor0 = float4(result, albedo.a);
|
||||
|
||||
#ifdef PIN_GBUFFER
|
||||
oColor1 = gbufferPack(IN.View_Depth.w, diffuse.rgb, specular.rgb, fogAlpha);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
#define PIN_PLASTIC
|
||||
#include "default.hlsl"
|
||||
#endif
|
||||
#else
|
||||
|
||||
#if defined(PIN_HQ)
|
||||
#define PIN_SURFACE
|
||||
#include "default.hlsl"
|
||||
|
||||
#define CFG_TEXTURE_TILING 1
|
||||
|
||||
#define CFG_BUMP_INTENSITY 0.5
|
||||
|
||||
#define CFG_SPECULAR 0.4
|
||||
#define CFG_GLOSS 9
|
||||
|
||||
#define CFG_NORMAL_SHADOW_SCALE 0.1
|
||||
|
||||
Surface surfaceShader(SurfaceInput IN, float2 fade2)
|
||||
{
|
||||
float fade = fade2.y;
|
||||
|
||||
float4 studs = tex2D(DiffuseMap, IN.UvStuds);
|
||||
float3 normal = nmapUnpack(tex2D(NormalMap, IN.UvStuds));
|
||||
|
||||
#ifdef GLSLES
|
||||
float3 noise = float3(0, 0, 1);
|
||||
#else
|
||||
float3 noise = nmapUnpack(tex2D(NormalDetailMap, IN.Uv * (CFG_TEXTURE_TILING)));
|
||||
#endif
|
||||
|
||||
float noiseScale = saturate0(IN.Color.a * 2 * (CFG_BUMP_INTENSITY) - 1 * (CFG_BUMP_INTENSITY));
|
||||
|
||||
#ifdef PIN_REFLECTION
|
||||
noiseScale *= saturate(1 - 2 * IN.Reflectance);
|
||||
#endif
|
||||
|
||||
normal.xy += noise.xy * noiseScale;
|
||||
|
||||
normal.xy *= fade;
|
||||
|
||||
Surface surface = (Surface)0;
|
||||
surface.albedo = IN.Color.rgb * (studs.r * 2);
|
||||
surface.normal = normal;
|
||||
surface.specular = (CFG_SPECULAR);
|
||||
surface.gloss = (CFG_GLOSS);
|
||||
|
||||
#ifdef PIN_REFLECTION
|
||||
surface.reflectance = IN.Reflectance;
|
||||
#endif
|
||||
|
||||
return surface;
|
||||
}
|
||||
#else
|
||||
#define PIN_PLASTIC
|
||||
#include "default.hlsl"
|
||||
#endif
|
||||
#endif
|
||||
46
client/common/shaders/source/profiler.hlsl
Normal file
46
client/common/shaders/source/profiler.hlsl
Normal file
@@ -0,0 +1,46 @@
|
||||
#include "common.h"
|
||||
|
||||
struct Appdata
|
||||
{
|
||||
float4 Position : POSITION;
|
||||
float2 Uv : TEXCOORD0;
|
||||
float4 Color : COLOR0;
|
||||
};
|
||||
|
||||
struct VertexOutput
|
||||
{
|
||||
float4 HPosition : POSITION;
|
||||
float2 Uv : TEXCOORD0;
|
||||
float4 Color : COLOR0;
|
||||
};
|
||||
|
||||
VertexOutput ProfilerVS(Appdata IN)
|
||||
{
|
||||
VertexOutput OUT = (VertexOutput)0;
|
||||
|
||||
OUT.HPosition = mul(G(ViewProjection), IN.Position);
|
||||
OUT.HPosition.y = -OUT.HPosition.y;
|
||||
|
||||
OUT.Uv = IN.Uv;
|
||||
OUT.Color = IN.Color;
|
||||
|
||||
return OUT;
|
||||
}
|
||||
|
||||
TEX_DECLARE2D(DiffuseMap, 0);
|
||||
|
||||
float4 ProfilerPS(VertexOutput IN): COLOR0
|
||||
{
|
||||
float4 c0 = tex2D(DiffuseMap, IN.Uv);
|
||||
float4 c1 = tex2D(DiffuseMap, IN.Uv + float2(0, 1.f / 9.f));
|
||||
|
||||
return c0.a < 0.5 ? float4(0, 0, 0, c1.a) : c0 * IN.Color;
|
||||
}
|
||||
|
||||
float4 ImGuiPS(VertexOutput IN): COLOR0
|
||||
{
|
||||
float4 texColor = tex2D(DiffuseMap, IN.Uv);
|
||||
float4 finalColor = texColor * IN.Color;
|
||||
|
||||
return finalColor;
|
||||
}
|
||||
101
client/common/shaders/source/rust.hlsl
Normal file
101
client/common/shaders/source/rust.hlsl
Normal file
@@ -0,0 +1,101 @@
|
||||
#ifdef CLASSIC
|
||||
#define PIN_SURFACE
|
||||
#define ALREADY_HAS_PS
|
||||
#include "default.hlsl"
|
||||
|
||||
#define SPEC_EXPON 70
|
||||
#define KS .12
|
||||
|
||||
#define NOISE_SCALE float3(.02083, .0693, .2083)
|
||||
#define SPREAD .3
|
||||
#define RUST_THRESHOLD .8
|
||||
#define CONTRAST float3(.1, .1, .1)
|
||||
#define STUPID 0.125 * 1 //they do this stupid thing where different colors have assigned values for this coord val!!!!!
|
||||
|
||||
#define FADE_DIST 250 //133.33 fix!!!!!!!!!!
|
||||
#define FADE_DIST_START 0
|
||||
|
||||
|
||||
void DefaultPS(VertexOutput IN,
|
||||
#ifdef PIN_GBUFFER
|
||||
out float4 oColor1: COLOR1,
|
||||
#endif
|
||||
out float4 oColor0: COLOR0)
|
||||
{
|
||||
float fade = saturate(1 - (IN.View_Depth.w - FADE_DIST_START) / FADE_DIST);
|
||||
|
||||
float3 nn = normalize(IN.Normal);
|
||||
|
||||
float3x3 normalMatrix = {
|
||||
IN.Tangent.xyz,
|
||||
cross(nn, IN.Tangent.xyz),
|
||||
nn
|
||||
};
|
||||
|
||||
float2 uv = IN.Uv.xy;
|
||||
|
||||
float3 shiftPos = DisplaceCoord(IN.Pos);
|
||||
float noiseval = tex3D(SpecularMap,shiftPos.xyz*NOISE_SCALE.x).x * 0.5;
|
||||
float noiseval2 = tex3D(SpecularMap,shiftPos.zyx*NOISE_SCALE.y).x * 0.3;
|
||||
float noiseval3 = tex3D(SpecularMap,shiftPos.zyx*NOISE_SCALE.z).x * 0.2;
|
||||
noiseval += noiseval2+noiseval3;
|
||||
|
||||
float3 metalColor = IN.Color.xyz * 1.3 + CONTRAST * (noiseval - .5);
|
||||
float3 rustColor = tex2D(DiffuseMap, float2(STUPID, 1 - noiseval)).xyz;
|
||||
|
||||
float3 tn = tex2D(NormalMap,uv).xyz - .5;
|
||||
float tnSum = 0.65 + 0.35 * (tn.x + tn.y + tn.z);
|
||||
|
||||
float interp = (noiseval - RUST_THRESHOLD + SPREAD) / 2 / SPREAD + .5;
|
||||
interp = clamp(interp, 0, 1);
|
||||
tn = lerp(tn, float3(0,0,.5), interp - .4);
|
||||
float3 albedo = lerp(rustColor, metalColor,interp);
|
||||
float3 albedo2 = albedo * tnSum;
|
||||
albedo = lerp(albedo, albedo2, interp);
|
||||
tn = lerp(tn, float3(0,0,.5), interp);
|
||||
|
||||
tn = CalcBevel(IN.EdgeDistances, tn, IN.View_Depth.w);
|
||||
nn = mul(tn, normalMatrix);
|
||||
|
||||
float3 vn = normalize(IN.View_Depth.xyz);
|
||||
float4 light = lgridSample(TEXTURE(LightMap), TEXTURE(LightMapLookup), IN.LightPosition_Fog.xyz);
|
||||
light.a = shadowSample(TEXTURE(ShadowMap), IN.PosLightSpace.xyz, light.a);
|
||||
|
||||
float3 diffuse;
|
||||
float3 specular;
|
||||
Shade(albedo, nn, vn, KS, SPEC_EXPON, light, diffuse, specular);
|
||||
|
||||
oColor0 = float4(diffuse + specular, IN.Color.w);
|
||||
|
||||
float fogAlpha = saturate((G(FogParams).z - length(IN.View_Depth.xyz)) * G(FogParams).w);
|
||||
oColor0.xyz = lerp(G(FogColor), oColor0.rgb, fogAlpha);
|
||||
|
||||
#ifdef PIN_GBUFFER
|
||||
oColor1 = gbufferPack(IN.View_Depth.w, diffuse.rgb, specular.rgb, fogAlpha);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
#define CFG_TEXTURE_TILING 1
|
||||
|
||||
#define CFG_DIFFUSE_SCALE 1
|
||||
#define CFG_SPECULAR_SCALE 1
|
||||
#define CFG_GLOSS_SCALE 256
|
||||
#define CFG_REFLECTION_SCALE 0
|
||||
|
||||
#define CFG_NORMAL_SHADOW_SCALE 0.5
|
||||
|
||||
#define CFG_SPECULAR_LOD 0.35
|
||||
#define CFG_GLOSS_LOD 103
|
||||
|
||||
#define CFG_NORMAL_DETAIL_TILING 0
|
||||
#define CFG_NORMAL_DETAIL_SCALE 0
|
||||
|
||||
#define CFG_FAR_TILING 0.5
|
||||
#define CFG_FAR_DIFFUSE_CUTOFF 0.6
|
||||
#define CFG_FAR_NORMAL_CUTOFF 0
|
||||
#define CFG_FAR_SPECULAR_CUTOFF 0
|
||||
|
||||
#define CFG_OPT_BLEND_COLOR
|
||||
|
||||
#include "material.hlsl"
|
||||
#endif
|
||||
25
client/common/shaders/source/sand.hlsl
Normal file
25
client/common/shaders/source/sand.hlsl
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifdef CLASSIC
|
||||
#include "concrete.hlsl"
|
||||
#else
|
||||
#define CFG_TEXTURE_TILING 1
|
||||
|
||||
#define CFG_DIFFUSE_SCALE 1
|
||||
#define CFG_SPECULAR_SCALE 0.4
|
||||
#define CFG_GLOSS_SCALE 32
|
||||
#define CFG_REFLECTION_SCALE 0
|
||||
|
||||
#define CFG_NORMAL_SHADOW_SCALE 0
|
||||
|
||||
#define CFG_SPECULAR_LOD 0.07
|
||||
#define CFG_GLOSS_LOD 6
|
||||
|
||||
#define CFG_NORMAL_DETAIL_TILING 0
|
||||
#define CFG_NORMAL_DETAIL_SCALE 0
|
||||
|
||||
#define CFG_FAR_TILING 0
|
||||
#define CFG_FAR_DIFFUSE_CUTOFF 0
|
||||
#define CFG_FAR_NORMAL_CUTOFF 0
|
||||
#define CFG_FAR_SPECULAR_CUTOFF 0
|
||||
|
||||
#include "material.hlsl"
|
||||
#endif
|
||||
369
client/common/shaders/source/screenspace.hlsl
Normal file
369
client/common/shaders/source/screenspace.hlsl
Normal file
@@ -0,0 +1,369 @@
|
||||
#include "common.h"
|
||||
|
||||
TEX_DECLARE2D(Texture, 0);
|
||||
TEX_DECLARE2D(Mask, 1);
|
||||
|
||||
// .xy = gbuffer width/height, .zw = inverse gbuffer width/height
|
||||
uniform float4 TextureSize;
|
||||
uniform float4 Params1;
|
||||
uniform float4 Params2;
|
||||
|
||||
#if defined(GLSL) || defined(DX11)
|
||||
float4 convertPosition(float4 p, float scale)
|
||||
{
|
||||
return p;
|
||||
}
|
||||
#else
|
||||
float4 convertPosition(float4 p, float scale)
|
||||
{
|
||||
// half-pixel offset
|
||||
return p + float4(-TextureSize.z, TextureSize.w, 0, 0) * scale;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef GLSL
|
||||
float2 convertUv(float4 p)
|
||||
{
|
||||
return p.xy * float2(0.5, -0.5) + 0.5;
|
||||
}
|
||||
#else
|
||||
float2 convertUv(float4 p)
|
||||
{
|
||||
return p.xy * 0.5 + 0.5;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// simple pass through structure
|
||||
struct VertexOutput
|
||||
{
|
||||
float4 p : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
// position and tex coord + 4 additional tex coords
|
||||
struct VertexOutput_4uv
|
||||
{
|
||||
float4 p : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 uv12 : TEXCOORD1;
|
||||
float4 uv34 : TEXCOORD2;
|
||||
};
|
||||
|
||||
// position and tex coord + 8 additional tex coords
|
||||
struct VertexOutput_8uv
|
||||
{
|
||||
float4 p : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 uv12 : TEXCOORD1;
|
||||
float4 uv34 : TEXCOORD2;
|
||||
float4 uv56 : TEXCOORD3;
|
||||
float4 uv78 : TEXCOORD4;
|
||||
};
|
||||
|
||||
VertexOutput passThrough_vs(float4 p: POSITION)
|
||||
{
|
||||
VertexOutput OUT;
|
||||
OUT.p = convertPosition(p, 1);
|
||||
OUT.uv = convertUv(p);
|
||||
|
||||
return OUT;
|
||||
}
|
||||
|
||||
float4 passThrough_ps( VertexOutput IN ) : COLOR0
|
||||
{
|
||||
return tex2D(Texture, IN.uv);
|
||||
}
|
||||
|
||||
float4 imageProcess_ps( VertexOutput IN ) : COLOR0
|
||||
{
|
||||
float3 color = tex2D(Texture, IN.uv).rgb;
|
||||
|
||||
float4 tintColor = float4(Params2.xyz,1);
|
||||
//float4 tintColor = float4(18.0 / 255.0, 58.0 / 255.0, 80.0 / 255.0, 1);
|
||||
float contrast = Params1.y;
|
||||
float brightness = Params1.x;
|
||||
float grayscaleLvl = Params1.z;
|
||||
|
||||
color = contrast*(color - 0.5) + 0.5 + brightness;
|
||||
float grayscale = (color.r + color.g + color.g) / 3.0;
|
||||
|
||||
return lerp(float4(color.rgb,1), float4(grayscale.xxx,1), grayscaleLvl) * tintColor;
|
||||
}
|
||||
|
||||
float4 gauss(float samples, float2 uv)
|
||||
{
|
||||
float2 step = Params1.xy;
|
||||
float sigma = Params1.z;
|
||||
|
||||
float sigmaN1 = 1 / sqrt(2 * 3.1415926 * sigma * sigma);
|
||||
float sigmaN2 = 1 / (2 * sigma * sigma);
|
||||
|
||||
// First sample is in the center and accounts for our pixel
|
||||
float4 result = tex2D(Texture, uv) * sigmaN1;
|
||||
float weight = sigmaN1;
|
||||
|
||||
// Every loop iteration computes impact of 4 pixels
|
||||
// Each sample computes impact of 2 neighbor pixels, starting with the next one to the right
|
||||
// Note that we sample exactly in between pixels to leverage bilinear filtering
|
||||
for (int i = 0; i < samples; ++i)
|
||||
{
|
||||
float ix = 2 * i + 1.5;
|
||||
float iw = 2 * exp(-ix * ix * sigmaN2) * sigmaN1;
|
||||
|
||||
result += (tex2D(Texture, uv + step * ix) + tex2D(Texture, uv - step * ix)) * iw;
|
||||
weight += 2 * iw;
|
||||
}
|
||||
|
||||
// Since the above is an approximation of the integral with step functions, normalization compensates for the error
|
||||
return (result / weight);
|
||||
}
|
||||
|
||||
float4 fxaa_ps(VertexOutput IN) : COLOR0
|
||||
{
|
||||
float2 uv = IN.uv;
|
||||
float2 rcpFrame = TextureSize.zw;
|
||||
|
||||
// Luma conversion weights
|
||||
const float3 luma = float3(0.299, 0.587, 0.114);
|
||||
|
||||
// Sample 3x3 neighborhood
|
||||
float3 rgbM = tex2D(Texture, uv).rgb;
|
||||
float3 rgbN = tex2D(Texture, uv + float2(0, -rcpFrame.y)).rgb;
|
||||
float3 rgbS = tex2D(Texture, uv + float2(0, rcpFrame.y)).rgb;
|
||||
float3 rgbE = tex2D(Texture, uv + float2(rcpFrame.x, 0)).rgb;
|
||||
float3 rgbW = tex2D(Texture, uv + float2(-rcpFrame.x, 0)).rgb;
|
||||
float3 rgbNW = tex2D(Texture, uv + float2(-rcpFrame.x, -rcpFrame.y)).rgb;
|
||||
float3 rgbNE = tex2D(Texture, uv + float2(rcpFrame.x, -rcpFrame.y)).rgb;
|
||||
float3 rgbSW = tex2D(Texture, uv + float2(-rcpFrame.x, rcpFrame.y)).rgb;
|
||||
float3 rgbSE = tex2D(Texture, uv + float2(rcpFrame.x, rcpFrame.y)).rgb;
|
||||
|
||||
float lumaM = dot(rgbM, luma);
|
||||
float lumaN = dot(rgbN, luma);
|
||||
float lumaS = dot(rgbS, luma);
|
||||
float lumaE = dot(rgbE, luma);
|
||||
float lumaW = dot(rgbW, luma);
|
||||
float lumaNW = dot(rgbNW, luma);
|
||||
float lumaNE = dot(rgbNE, luma);
|
||||
float lumaSW = dot(rgbSW, luma);
|
||||
float lumaSE = dot(rgbSE, luma);
|
||||
|
||||
// Find local contrast including corners
|
||||
float lumaMin = min(lumaM, min(min(min(lumaN, lumaS), min(lumaE, lumaW)),
|
||||
min(min(lumaNW, lumaNE), min(lumaSW, lumaSE))));
|
||||
float lumaMax = max(lumaM, max(max(max(lumaN, lumaS), max(lumaE, lumaW)),
|
||||
max(max(lumaNW, lumaNE), max(lumaSW, lumaSE))));
|
||||
float range = lumaMax - lumaMin;
|
||||
|
||||
// Very low threshold - catch almost all edges
|
||||
if (range < max(0.0156, lumaMax * 0.0625))
|
||||
{
|
||||
return float4(rgbM, 1.0);
|
||||
}
|
||||
|
||||
// Determine edge orientation
|
||||
float edgeVert = abs((0.25 * lumaNW) + (-0.5 * lumaN) + (0.25 * lumaNE)) +
|
||||
abs((0.50 * lumaW) + (-1.0 * lumaM) + (0.50 * lumaE)) +
|
||||
abs((0.25 * lumaSW) + (-0.5 * lumaS) + (0.25 * lumaSE));
|
||||
|
||||
float edgeHorz = abs((0.25 * lumaNW) + (-0.5 * lumaW) + (0.25 * lumaSW)) +
|
||||
abs((0.50 * lumaN) + (-1.0 * lumaM) + (0.50 * lumaS)) +
|
||||
abs((0.25 * lumaNE) + (-0.5 * lumaE) + (0.25 * lumaSE));
|
||||
|
||||
bool isHorizontal = (edgeHorz >= edgeVert);
|
||||
|
||||
// Select samples along edge
|
||||
float luma1 = isHorizontal ? lumaS : lumaE;
|
||||
float luma2 = isHorizontal ? lumaN : lumaW;
|
||||
float gradient1 = luma1 - lumaM;
|
||||
float gradient2 = luma2 - lumaM;
|
||||
|
||||
// Pick steepest gradient
|
||||
bool is1Steepest = abs(gradient1) >= abs(gradient2);
|
||||
float gradientScaled = 0.25 * max(abs(gradient1), abs(gradient2));
|
||||
float lengthSign = is1Steepest ? -1.0 : 1.0;
|
||||
|
||||
if (!isHorizontal)
|
||||
lengthSign *= -1.0;
|
||||
|
||||
// Setup for edge search
|
||||
float2 posB = uv;
|
||||
float2 offNP;
|
||||
offNP.x = (!isHorizontal) ? rcpFrame.x : 0.0;
|
||||
offNP.y = (isHorizontal) ? rcpFrame.y : 0.0;
|
||||
|
||||
if (!isHorizontal)
|
||||
posB.x += lengthSign * 0.5 * rcpFrame.x;
|
||||
else
|
||||
posB.y += lengthSign * 0.5 * rcpFrame.y;
|
||||
|
||||
// Extended edge search - 12 iterations
|
||||
float2 posN = posB - offNP;
|
||||
float2 posP = posB + offNP;
|
||||
|
||||
float lumaEndN = dot(tex2D(Texture, posN).rgb, luma) - lumaM * 0.5;
|
||||
float lumaEndP = dot(tex2D(Texture, posP).rgb, luma) - lumaM * 0.5;
|
||||
|
||||
bool doneN = abs(lumaEndN) >= gradientScaled;
|
||||
bool doneP = abs(lumaEndP) >= gradientScaled;
|
||||
|
||||
// More iterations with finer steps for better accuracy
|
||||
float stepSizes[12] = {1.0, 1.0, 1.5, 1.5, 2.0, 2.0, 4.0, 4.0, 8.0, 8.0, 16.0, 16.0};
|
||||
|
||||
for (int i = 0; i < 12; ++i)
|
||||
{
|
||||
if (doneN && doneP) break;
|
||||
|
||||
if (!doneN)
|
||||
{
|
||||
posN -= offNP * stepSizes[i];
|
||||
lumaEndN = dot(tex2D(Texture, posN).rgb, luma) - lumaM * 0.5;
|
||||
doneN = abs(lumaEndN) >= gradientScaled;
|
||||
}
|
||||
|
||||
if (!doneP)
|
||||
{
|
||||
posP += offNP * stepSizes[i];
|
||||
lumaEndP = dot(tex2D(Texture, posP).rgb, luma) - lumaM * 0.5;
|
||||
doneP = abs(lumaEndP) >= gradientScaled;
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate span and offset
|
||||
float dstN = isHorizontal ? (uv.x - posN.x) : (uv.y - posN.y);
|
||||
float dstP = isHorizontal ? (posP.x - uv.x) : (posP.y - uv.y);
|
||||
|
||||
bool directionN = dstN < dstP;
|
||||
float dst = min(dstN, dstP);
|
||||
|
||||
float spanLength = (dstP + dstN);
|
||||
float spanLengthRcp = 1.0 / spanLength;
|
||||
float pixelOffset = dst * (-spanLengthRcp) + 0.5;
|
||||
|
||||
// Check if we're at a good span
|
||||
bool goodSpanN = (lumaEndN < 0.0) != (lumaM < lumaMin);
|
||||
bool goodSpanP = (lumaEndP < 0.0) != (lumaM < lumaMin);
|
||||
bool goodSpan = directionN ? goodSpanN : goodSpanP;
|
||||
|
||||
if (!goodSpan)
|
||||
pixelOffset = 0.0;
|
||||
|
||||
// sub-pixel antialiasing
|
||||
float lumaAverage = (1.0/12.0) * (2.0 * (lumaN + lumaS + lumaE + lumaW) +
|
||||
lumaNW + lumaNE + lumaSW + lumaSE);
|
||||
|
||||
float subPixelOffset1 = saturate(abs(lumaAverage - lumaM) / range);
|
||||
subPixelOffset1 = (-2.0 * subPixelOffset1 + 3.0) * subPixelOffset1 * subPixelOffset1;
|
||||
subPixelOffset1 = subPixelOffset1 * subPixelOffset1 * 0.85;
|
||||
// Blend edge and subpixel offsets
|
||||
float pixelOffsetFinal = max(pixelOffset, subPixelOffset1);
|
||||
|
||||
// Apply offset
|
||||
float2 finalUv = uv;
|
||||
if (!isHorizontal)
|
||||
finalUv.x += pixelOffsetFinal * lengthSign * rcpFrame.x;
|
||||
else
|
||||
finalUv.y += pixelOffsetFinal * lengthSign * rcpFrame.y;
|
||||
|
||||
// Additional edge blending for remaining jaggies
|
||||
float3 rgbFinal = tex2D(Texture, finalUv).rgb;
|
||||
|
||||
// If we're on a strong edge, do additional smart blending
|
||||
if (range > 0.1)
|
||||
{
|
||||
float edgeBlend = saturate(range * 2.0 - 0.2);
|
||||
float3 rgbBlur = (rgbN + rgbS + rgbE + rgbW) * 0.25;
|
||||
rgbFinal = lerp(rgbFinal, rgbBlur, edgeBlend * 0.15);
|
||||
}
|
||||
|
||||
return float4(rgbFinal, 1.0);
|
||||
}
|
||||
|
||||
float4 blur3_ps(VertexOutput IN): COLOR0
|
||||
{
|
||||
return gauss(3, IN.uv);
|
||||
}
|
||||
|
||||
float4 blur5_ps(VertexOutput IN): COLOR0
|
||||
{
|
||||
return gauss(5, IN.uv);
|
||||
}
|
||||
|
||||
float4 blur7_ps(VertexOutput IN): COLOR0
|
||||
{
|
||||
return gauss(7, IN.uv);
|
||||
}
|
||||
|
||||
float4 glowApply_ps( VertexOutput IN ) : COLOR0
|
||||
{
|
||||
float4 color = tex2D(Texture, IN.uv);
|
||||
return float4(color.rgb * Params1.x, color.a);
|
||||
}
|
||||
|
||||
// this is specific glow downsample
|
||||
float4 downSample4x4Glow_ps( VertexOutput_4uv IN ) : COLOR0
|
||||
{
|
||||
float4 avgColor = tex2D( Texture, IN.uv12.xy );
|
||||
avgColor += tex2D( Texture, IN.uv12.zw );
|
||||
avgColor += tex2D( Texture, IN.uv34.xy );
|
||||
avgColor += tex2D( Texture, IN.uv34.zw );
|
||||
|
||||
avgColor *= 0.25;
|
||||
return float4(avgColor.rgb, 1) * (1-avgColor.a);
|
||||
}
|
||||
|
||||
VertexOutput_4uv downsample4x4_vs(float4 p: POSITION)
|
||||
{
|
||||
float2 uv = convertUv(p);
|
||||
|
||||
VertexOutput_4uv OUT;
|
||||
OUT.p = convertPosition(p, 1);
|
||||
OUT.uv = uv;
|
||||
|
||||
float2 uvOffset = TextureSize.zw * 0.25f;
|
||||
|
||||
OUT.uv12.xy = uv + uvOffset * float2(-1, -1);
|
||||
OUT.uv12.zw = uv + uvOffset * float2(+1, -1);
|
||||
OUT.uv34.xy = uv + uvOffset * float2(-1, +1);
|
||||
OUT.uv34.zw = uv + uvOffset * float2(+1, +1);
|
||||
|
||||
return OUT;
|
||||
}
|
||||
|
||||
|
||||
float4 ShadowBlurPS(VertexOutput IN): COLOR0
|
||||
{
|
||||
#ifdef GLSLES
|
||||
int N = 1;
|
||||
float sigma = 0.5;
|
||||
#else
|
||||
int N = 3;
|
||||
float sigma = 1.5;
|
||||
#endif
|
||||
|
||||
float2 step = Params1.xy;
|
||||
|
||||
float sigmaN1 = 1 / sqrt(2 * 3.1415926 * sigma * sigma);
|
||||
float sigmaN2 = 1 / (2 * sigma * sigma);
|
||||
|
||||
float depth = 1;
|
||||
float color = 0;
|
||||
float weight = 0;
|
||||
|
||||
for (int i = -N; i <= N; ++i)
|
||||
{
|
||||
float ix = i;
|
||||
float iw = exp(-ix * ix * sigmaN2) * sigmaN1;
|
||||
|
||||
float4 data = tex2D(Texture, IN.uv + step * ix);
|
||||
|
||||
depth = min(depth, data.x);
|
||||
color += data.y * iw;
|
||||
weight += iw;
|
||||
}
|
||||
|
||||
float mask = tex2D(Mask, IN.uv).r;
|
||||
|
||||
// Since the above is an approximation of the integral with step functions, normalization compensates for the error
|
||||
return float4(depth, color * mask * (1 / weight), 0, 0);
|
||||
}
|
||||
50
client/common/shaders/source/shadow.hlsl
Normal file
50
client/common/shaders/source/shadow.hlsl
Normal file
@@ -0,0 +1,50 @@
|
||||
#include "common.h"
|
||||
|
||||
struct Appdata
|
||||
{
|
||||
float4 Position : POSITION;
|
||||
|
||||
ATTR_INT4 Extra : COLOR1;
|
||||
};
|
||||
|
||||
struct VertexOutput
|
||||
{
|
||||
float4 HPosition: POSITION;
|
||||
|
||||
float3 PosLightSpace: TEXCOORD0;
|
||||
};
|
||||
|
||||
#ifdef PIN_SKINNED
|
||||
WORLD_MATRIX_ARRAY(WorldMatrixArray, MAX_BONE_COUNT * 3);
|
||||
#endif
|
||||
|
||||
VertexOutput ShadowVS(Appdata IN)
|
||||
{
|
||||
VertexOutput OUT = (VertexOutput)0;
|
||||
|
||||
// Transform position to world space
|
||||
#ifdef PIN_SKINNED
|
||||
int boneIndex = IN.Extra.r;
|
||||
|
||||
float4 worldRow0 = WorldMatrixArray[boneIndex * 3 + 0];
|
||||
float4 worldRow1 = WorldMatrixArray[boneIndex * 3 + 1];
|
||||
float4 worldRow2 = WorldMatrixArray[boneIndex * 3 + 2];
|
||||
|
||||
float3 posWorld = float3(dot(worldRow0, IN.Position), dot(worldRow1, IN.Position), dot(worldRow2, IN.Position));
|
||||
#else
|
||||
float3 posWorld = IN.Position.xyz;
|
||||
#endif
|
||||
|
||||
OUT.HPosition = mul(G(ViewProjection), float4(posWorld, 1));
|
||||
|
||||
OUT.PosLightSpace = shadowPrepareSample(posWorld);
|
||||
|
||||
return OUT;
|
||||
}
|
||||
|
||||
float4 ShadowPS(VertexOutput IN): COLOR0
|
||||
{
|
||||
float depth = shadowDepth(IN.PosLightSpace);
|
||||
|
||||
return float4(depth, 1, 0, 0);
|
||||
}
|
||||
53
client/common/shaders/source/sky.hlsl
Normal file
53
client/common/shaders/source/sky.hlsl
Normal file
@@ -0,0 +1,53 @@
|
||||
#include "common.h"
|
||||
|
||||
struct Appdata
|
||||
{
|
||||
float4 Position : POSITION;
|
||||
float2 Uv : TEXCOORD0;
|
||||
float4 Color : COLOR0;
|
||||
};
|
||||
|
||||
struct VertexOutput
|
||||
{
|
||||
float4 HPosition : POSITION;
|
||||
float PSize : PSIZE;
|
||||
|
||||
float2 Uv : TEXCOORD0;
|
||||
float4 Color : COLOR0;
|
||||
};
|
||||
|
||||
WORLD_MATRIX(WorldMatrix);
|
||||
|
||||
uniform float4 Color;
|
||||
uniform float4 Color2;
|
||||
|
||||
VertexOutput SkyVS(Appdata IN)
|
||||
{
|
||||
VertexOutput OUT = (VertexOutput)0;
|
||||
|
||||
float4 wpos = mul(WorldMatrix, IN.Position);
|
||||
|
||||
OUT.HPosition = mul(G(ViewProjection), wpos);
|
||||
|
||||
#ifndef GLSLES
|
||||
// snap to far plane to prevent scene-sky intersections
|
||||
// small offset is needed to prevent 0/0 division in case w=0, which causes rasterization issues
|
||||
// some mobile chips (hello, Vivante!) don't like it
|
||||
OUT.HPosition.z = OUT.HPosition.w - 1.f / 16;
|
||||
#endif
|
||||
|
||||
OUT.PSize = 2.0; // star size
|
||||
|
||||
OUT.Uv = IN.Uv;
|
||||
OUT.Color = IN.Color * lerp(Color2,Color,wpos.y/1700);
|
||||
//OUT.Color = IN.Color * Color;
|
||||
|
||||
return OUT;
|
||||
}
|
||||
|
||||
TEX_DECLARE2D(DiffuseMap, 0);
|
||||
|
||||
float4 SkyPS(VertexOutput IN): COLOR0
|
||||
{
|
||||
return tex2D(DiffuseMap, IN.Uv) * IN.Color;
|
||||
}
|
||||
90
client/common/shaders/source/slate.hlsl
Normal file
90
client/common/shaders/source/slate.hlsl
Normal file
@@ -0,0 +1,90 @@
|
||||
#ifdef CLASSIC
|
||||
#define PIN_SURFACE
|
||||
#define ALREADY_HAS_PS
|
||||
#include "default.hlsl"
|
||||
|
||||
#define SPEC_EXPON 40
|
||||
#define KS .1
|
||||
|
||||
#define NOISE_SCALE 7
|
||||
#define SPREAD .3
|
||||
#define GRASS_THRESHOLD .95
|
||||
|
||||
#define FADE_DIST 290
|
||||
#define FADE_DIST_START 0
|
||||
|
||||
void DefaultPS(VertexOutput IN,
|
||||
#ifdef PIN_GBUFFER
|
||||
out float4 oColor1: COLOR1,
|
||||
#endif
|
||||
out float4 oColor0: COLOR0)
|
||||
{
|
||||
float3 normal = normalize(IN.Normal);
|
||||
|
||||
float3x3 normalMatrix = {
|
||||
IN.Tangent.xyz,
|
||||
cross(normal, IN.Tangent.xyz),
|
||||
normal,
|
||||
};
|
||||
|
||||
float fade = saturate(1 - (IN.View_Depth.w - FADE_DIST_START) / FADE_DIST);
|
||||
|
||||
float2 uv = IN.Uv.xy;
|
||||
float3 shiftPos = IN.Pos.xyz;
|
||||
|
||||
float noiseval = tex3D(SpecularMap,shiftPos.xyz / NOISE_SCALE * .04).x;
|
||||
float noiseval2 = tex3D(SpecularMap,shiftPos.xyz / NOISE_SCALE * .3).x + .2;
|
||||
noiseval *= noiseval2;
|
||||
|
||||
float3 albedo = IN.Color.xyz + 0.8 * fade * (noiseval * 0.5 - 0.1);
|
||||
|
||||
float3 tn = tex2D(NormalMap,uv).xyz - .5;
|
||||
float tNormSum = 0.9+0.4*(tn.x + tn.y + tn.z);
|
||||
tn = lerp(tn, float3(0,0,.5), .9);
|
||||
albedo *= ((1-fade) + (fade*tNormSum));
|
||||
|
||||
tn = CalcBevel(IN.EdgeDistances, tn, IN.View_Depth.w);
|
||||
float3 nn = mul(tn, normalMatrix);
|
||||
//nn *= fade;
|
||||
//KS *= fade; //ks is a constant and idk if this dumb shit is worth keeping anyways
|
||||
|
||||
float3 vn = normalize(IN.View_Depth.xyz);
|
||||
float4 light = lgridSample(TEXTURE(LightMap), TEXTURE(LightMapLookup), IN.LightPosition_Fog.xyz);
|
||||
light.a = shadowSample(TEXTURE(ShadowMap), IN.PosLightSpace.xyz, light.a);
|
||||
|
||||
float3 diffuse;
|
||||
float3 specular;
|
||||
Shade(albedo, nn, vn, KS, SPEC_EXPON, light, diffuse, specular);
|
||||
|
||||
oColor0 = float4(diffuse + specular, IN.Color.w);
|
||||
|
||||
float fogAlpha = saturate((G(FogParams).z - length(IN.View_Depth.xyz)) * G(FogParams).w);
|
||||
oColor0.xyz = lerp(G(FogColor), oColor0.rgb, fogAlpha);
|
||||
|
||||
#ifdef PIN_GBUFFER
|
||||
oColor1 = gbufferPack(IN.View_Depth.w, diffuse.rgb, specular.rgb, fogAlpha);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
#define CFG_TEXTURE_TILING 1
|
||||
|
||||
#define CFG_DIFFUSE_SCALE 1
|
||||
#define CFG_SPECULAR_SCALE 0.9
|
||||
#define CFG_GLOSS_SCALE 128
|
||||
#define CFG_REFLECTION_SCALE 0
|
||||
|
||||
#define CFG_NORMAL_SHADOW_SCALE 0.5
|
||||
|
||||
#define CFG_SPECULAR_LOD 0.14
|
||||
#define CFG_GLOSS_LOD 20
|
||||
|
||||
#define CFG_NORMAL_DETAIL_TILING 5
|
||||
#define CFG_NORMAL_DETAIL_SCALE 1
|
||||
|
||||
#define CFG_FAR_TILING 0.25
|
||||
#define CFG_FAR_DIFFUSE_CUTOFF 0.75
|
||||
#define CFG_FAR_NORMAL_CUTOFF 0
|
||||
#define CFG_FAR_SPECULAR_CUTOFF 0
|
||||
|
||||
#include "material.hlsl"
|
||||
#endif
|
||||
174
client/common/shaders/source/smoothcluster.hlsl
Normal file
174
client/common/shaders/source/smoothcluster.hlsl
Normal file
@@ -0,0 +1,174 @@
|
||||
#include "common.h"
|
||||
|
||||
struct Appdata
|
||||
{
|
||||
ATTR_INT4 Position : POSITION;
|
||||
|
||||
ATTR_INT4 Normal : NORMAL;
|
||||
|
||||
ATTR_INT4 Material0 : TEXCOORD0;
|
||||
ATTR_INT4 Material1 : TEXCOORD1;
|
||||
};
|
||||
|
||||
struct VertexOutput
|
||||
{
|
||||
float4 HPosition : POSITION;
|
||||
|
||||
float3 Weights: COLOR0;
|
||||
|
||||
float4 Uv0: TEXCOORD0;
|
||||
float4 Uv1: TEXCOORD1;
|
||||
float4 Uv2: TEXCOORD2;
|
||||
|
||||
float4 LightPosition_Fog : TEXCOORD3;
|
||||
float3 PosLightSpace : TEXCOORD4;
|
||||
|
||||
#ifdef PIN_HQ
|
||||
float3 Normal: TEXCOORD5;
|
||||
float4 View_Depth: TEXCOORD6;
|
||||
|
||||
float3 Tangents: COLOR1;
|
||||
#else
|
||||
float3 Diffuse: COLOR1;
|
||||
#endif
|
||||
};
|
||||
|
||||
WORLD_MATRIX_ARRAY(WorldMatrixArray, 72);
|
||||
|
||||
uniform float4 LayerScale;
|
||||
|
||||
float4 getUV(float3 position, ATTR_INT material, ATTR_INT projection, float seed)
|
||||
{
|
||||
float3 u = WorldMatrixArray[1 + int(projection)].xyz;
|
||||
float3 v = WorldMatrixArray[19 + int(projection)].xyz;
|
||||
|
||||
float4 m = WorldMatrixArray[37 + int(material)];
|
||||
|
||||
float2 uv = float2(dot(position, u), dot(position, v)) * m.x + m.y * float2(seed, floor(seed * 2.6651441f));
|
||||
|
||||
return float4(uv, m.zw);
|
||||
}
|
||||
|
||||
VertexOutput TerrainVS(Appdata IN)
|
||||
{
|
||||
VertexOutput OUT = (VertexOutput)0;
|
||||
|
||||
float3 posWorld = IN.Position.xyz * WorldMatrixArray[0].w + WorldMatrixArray[0].xyz;
|
||||
float3 normalWorld = IN.Normal.xyz * (1.0 / 127.0) - 1.0;
|
||||
|
||||
OUT.HPosition = mul(G(ViewProjection), float4(posWorld, 1));
|
||||
|
||||
OUT.LightPosition_Fog = float4(lgridPrepareSample(lgridOffset(posWorld, normalWorld)), (G(FogParams).z - OUT.HPosition.w) * G(FogParams).w);
|
||||
|
||||
OUT.PosLightSpace = shadowPrepareSample(posWorld);
|
||||
|
||||
OUT.Uv0 = getUV(posWorld, IN.Material0.x, IN.Material1.x, IN.Normal.w);
|
||||
OUT.Uv1 = getUV(posWorld, IN.Material0.y, IN.Material1.y, IN.Material0.w);
|
||||
OUT.Uv2 = getUV(posWorld, IN.Material0.z, IN.Material1.z, IN.Material1.w);
|
||||
|
||||
#if defined(GLSLES) && !defined(GL3) // iPad2 workaround
|
||||
OUT.Weights = abs(IN.Position.www - float3(0, 1, 2)) < 0.1;
|
||||
#else
|
||||
OUT.Weights = IN.Position.www == float3(0, 1, 2);
|
||||
#endif
|
||||
|
||||
#ifdef PIN_HQ
|
||||
OUT.Normal = normalWorld;
|
||||
OUT.View_Depth = float4(G(CameraPosition) - posWorld, OUT.HPosition.w);
|
||||
OUT.Tangents = float3(IN.Material1.xyz) > 7.5; // side vs top
|
||||
#else
|
||||
float ndotl = dot(normalWorld, -G(Lamp0Dir));
|
||||
float3 diffuse = max(ndotl, 0) * G(Lamp0Color) + max(-ndotl, 0) * G(Lamp1Color);
|
||||
|
||||
OUT.Diffuse = diffuse;
|
||||
#endif
|
||||
|
||||
return OUT;
|
||||
}
|
||||
|
||||
TEX_DECLARE2D(AlbedoMap, 0);
|
||||
TEX_DECLARE2D(NormalMap, 1);
|
||||
TEX_DECLARE2D(SpecularMap, 2);
|
||||
TEX_DECLARECUBE(EnvMap, 3);
|
||||
LGRID_SAMPLER(LightMap, 4);
|
||||
TEX_DECLARE2D(LightMapLookup, 5);
|
||||
TEX_DECLARE2D(ShadowMap, 6);
|
||||
|
||||
float4 sampleMap(TEXTURE_IN_2D(s), float4 uv)
|
||||
{
|
||||
#ifdef PIN_HQ
|
||||
float2 uvs = uv.xy * LayerScale.xy;
|
||||
|
||||
return tex2Dgrad(s, frac(uv.xy) * LayerScale.xy + uv.zw, ddx(uvs), ddy(uvs));
|
||||
#else
|
||||
return tex2D(s, frac(uv.xy) * LayerScale.xy + uv.zw);
|
||||
#endif
|
||||
}
|
||||
|
||||
float4 sampleBlend(TEXTURE_IN_2D(s), float4 uv0, float4 uv1, float4 uv2, float3 w)
|
||||
{
|
||||
return
|
||||
sampleMap(TEXTURE(s), uv0) * w.x +
|
||||
sampleMap(TEXTURE(s), uv1) * w.y +
|
||||
sampleMap(TEXTURE(s), uv2) * w.z;
|
||||
}
|
||||
|
||||
float3 sampleNormal(TEXTURE_IN_2D(s), float4 uv0, float4 uv1, float4 uv2, float3 w, float3 normal, float3 tsel)
|
||||
{
|
||||
return terrainNormal(sampleMap(TEXTURE(s), uv0), sampleMap(TEXTURE(s), uv1), sampleMap(TEXTURE(s), uv2), w, normal, tsel);
|
||||
}
|
||||
|
||||
void TerrainPS(VertexOutput IN,
|
||||
#ifdef PIN_GBUFFER
|
||||
out float4 oColor1: COLOR1,
|
||||
#endif
|
||||
out float4 oColor0: COLOR0)
|
||||
{
|
||||
float4 light = lgridSample(TEXTURE(LightMap), TEXTURE(LightMapLookup), IN.LightPosition_Fog.xyz);
|
||||
float shadow = shadowSample(TEXTURE(ShadowMap), IN.PosLightSpace, light.a);
|
||||
|
||||
float3 w = IN.Weights.xyz;
|
||||
|
||||
float4 albedo = sampleBlend(TEXTURE(AlbedoMap), IN.Uv0, IN.Uv1, IN.Uv2, w);
|
||||
|
||||
#ifdef PIN_HQ
|
||||
float fade = saturate0(1 - IN.View_Depth.w * G(FadeDistance_GlowFactor).y);
|
||||
|
||||
#ifndef PIN_GBUFFER
|
||||
float3 normal = IN.Normal;
|
||||
#else
|
||||
float3 normal = sampleNormal(TEXTURE(NormalMap), IN.Uv0, IN.Uv1, IN.Uv2, w, IN.Normal, IN.Tangents);
|
||||
#endif
|
||||
|
||||
float4 params = sampleBlend(TEXTURE(SpecularMap), IN.Uv0, IN.Uv1, IN.Uv2, w);
|
||||
|
||||
float ndotl = dot(normal, -G(Lamp0Dir));
|
||||
|
||||
// Compute diffuse term
|
||||
float3 diffuse = (G(AmbientColor) + (saturate(ndotl) * G(Lamp0Color) + max(-ndotl, 0) * G(Lamp1Color)) * shadow + light.rgb + params.b * 2) * albedo.rgb;
|
||||
|
||||
// Compute specular term
|
||||
float specularIntensity = step(0, ndotl) * params.r * fade;
|
||||
float specularPower = params.g * 128 + 0.01;
|
||||
|
||||
float3 specular = G(Lamp0Color) * (specularIntensity * shadow * (float)(half)pow(saturate(dot(normal, normalize(-G(Lamp0Dir) + normalize(IN.View_Depth.xyz)))), specularPower));
|
||||
#else
|
||||
// Compute diffuse term
|
||||
float3 diffuse = (G(AmbientColor) + IN.Diffuse * shadow + light.rgb) * albedo.rgb;
|
||||
|
||||
// Compute specular term
|
||||
float3 specular = 0;
|
||||
#endif
|
||||
|
||||
// Combine
|
||||
oColor0.rgb = diffuse + specular;
|
||||
oColor0.a = 1;
|
||||
|
||||
float fogAlpha = saturate(IN.LightPosition_Fog.w);
|
||||
|
||||
oColor0.rgb = lerp(G(FogColor), oColor0.rgb, fogAlpha);
|
||||
|
||||
#ifdef PIN_GBUFFER
|
||||
oColor1 = gbufferPack(IN.View_Depth.w, diffuse.rgb, specular.rgb, fogAlpha);
|
||||
#endif
|
||||
}
|
||||
76
client/common/shaders/source/smoothplastic.hlsl
Normal file
76
client/common/shaders/source/smoothplastic.hlsl
Normal file
@@ -0,0 +1,76 @@
|
||||
#ifdef CLASSIC
|
||||
#define PIN_SURFACE
|
||||
#define ALREADY_HAS_PS
|
||||
#include "default.hlsl"
|
||||
|
||||
#define SPEC_EXPON 81 //81
|
||||
#define KS .75
|
||||
|
||||
#define FADE_DIST 500
|
||||
#define FADE_DIST_START 0
|
||||
|
||||
float3 CalcBevelDir(float4 edgeDistances)
|
||||
{
|
||||
float3 dir = float3(0, 0, 0);
|
||||
float4 bevelMultiplier = edgeDistances <= BEVEL_WIDTH;
|
||||
|
||||
dir += bevelMultiplier.x * float3(1, 0, 0);
|
||||
dir += bevelMultiplier.y * float3(-1, 0, 0);
|
||||
dir += bevelMultiplier.z * float3(0, 1, 0);
|
||||
dir += bevelMultiplier.w * float3(0, -1, 0);
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
||||
void DefaultPS(VertexOutput IN,
|
||||
#ifdef PIN_GBUFFER
|
||||
out float4 oColor1: COLOR1,
|
||||
#endif
|
||||
out float4 oColor0: COLOR0)
|
||||
{
|
||||
float normalStrength = .4;
|
||||
float fade = saturate(normalStrength - (IN.View_Depth.w - FADE_DIST_START) / FADE_DIST);
|
||||
float3 nn = normalize(IN.Normal);
|
||||
float4 edgeDistances = IN.EdgeDistances;
|
||||
|
||||
float4 albedo = IN.Color;
|
||||
|
||||
// lets generate this matrix in the vertex shader and pass it in later
|
||||
float3x3 normalMatrix = {
|
||||
IN.Tangent.xyz,
|
||||
cross(nn, IN.Tangent.xyz),
|
||||
nn
|
||||
};
|
||||
|
||||
float2 uv = IN.Uv;
|
||||
float3 tn = float3(0,0,.5);
|
||||
tn = lerp(float3(0, 0, .5), tn, fade);
|
||||
tn = CalcBevel(edgeDistances, tn, IN.View_Depth.w);
|
||||
nn = mul(tn, normalMatrix);
|
||||
|
||||
float3 vn = normalize(IN.View_Depth.xyz);
|
||||
float4 light = lgridSample(TEXTURE(LightMap), TEXTURE(LightMapLookup), IN.LightPosition_Fog.xyz);
|
||||
|
||||
float3 diffuse;
|
||||
float3 specular;
|
||||
Shade(albedo.rgb, nn, vn, KS, SPEC_EXPON, light, diffuse, specular);
|
||||
|
||||
float3 result = diffuse + specular;
|
||||
|
||||
#ifdef PIN_REFLECTION
|
||||
float3 reflection = texCUBE(EnvironmentMap, reflect(-vn, nn)).rgb;
|
||||
result = lerp(result, reflection, IN.Reflection);
|
||||
#endif
|
||||
|
||||
float fogAlpha = saturate((G(FogParams).z - length(IN.View_Depth.xyz)) * G(FogParams).w);
|
||||
result = lerp(G(FogColor), result, fogAlpha);
|
||||
oColor0 = float4(result, albedo.a);
|
||||
|
||||
#ifdef PIN_GBUFFER
|
||||
oColor1 = gbufferPack(IN.View_Depth.w, diffuse.rgb, specular.rgb, fogAlpha);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
#define PIN_PLASTIC
|
||||
#include "default.hlsl"
|
||||
#endif
|
||||
310
client/common/shaders/source/smoothwater.hlsl
Normal file
310
client/common/shaders/source/smoothwater.hlsl
Normal file
@@ -0,0 +1,310 @@
|
||||
#include "common.h"
|
||||
|
||||
// Tunables
|
||||
#define CFG_TEXTURE_TILING 0.2
|
||||
#define CFG_TEXTURE_DETILING 0.1
|
||||
|
||||
#define CFG_SPECULAR 2
|
||||
#define CFG_GLOSS 900
|
||||
|
||||
#define CFG_NORMAL_STRENGTH 0.25
|
||||
|
||||
#define CFG_REFRACTION_STRENGTH 0.05
|
||||
|
||||
#define CFG_FRESNEL_OFFSET 0.3
|
||||
|
||||
#define CFG_SSR_STEPS 8
|
||||
#define CFG_SSR_START_DISTANCE 1
|
||||
#define CFG_SSR_STEP_CLAMP 0.2
|
||||
#define CFG_SSR_DEPTH_CUTOFF 10
|
||||
|
||||
// Shader code
|
||||
struct Appdata
|
||||
{
|
||||
ATTR_INT4 Position : POSITION;
|
||||
|
||||
ATTR_INT4 Normal : NORMAL;
|
||||
|
||||
ATTR_INT4 Material0 : TEXCOORD0;
|
||||
ATTR_INT4 Material1 : TEXCOORD1;
|
||||
};
|
||||
|
||||
struct VertexOutput
|
||||
{
|
||||
float4 HPosition : POSITION;
|
||||
|
||||
float4 Weights_Wave: COLOR0;
|
||||
float3 Tangents: COLOR1;
|
||||
|
||||
float2 Uv0: TEXCOORD0;
|
||||
float2 Uv1: TEXCOORD1;
|
||||
float2 Uv2: TEXCOORD2;
|
||||
|
||||
float4 LightPosition_Fog : TEXCOORD3;
|
||||
|
||||
float3 Normal: TEXCOORD4;
|
||||
float4 View_Depth: TEXCOORD5;
|
||||
|
||||
#ifdef PIN_HQ
|
||||
float4 PositionScreen: TEXCOORD6;
|
||||
#endif
|
||||
};
|
||||
|
||||
WORLD_MATRIX_ARRAY(WorldMatrixArray, 72);
|
||||
|
||||
uniform float4 WaveParams; // .x = frequency .y = phase .z = height .w = lerp
|
||||
uniform float4 WaterColor; // deep water color
|
||||
uniform float4 WaterParams; // .x = refraction depth scale, .y = refraction depth offset
|
||||
|
||||
float3 displacePosition(float3 position, float waveFactor)
|
||||
{
|
||||
float x = sin((position.z - position.x) * WaveParams.x - WaveParams.y);
|
||||
float z = sin((position.z + position.x) * WaveParams.x + WaveParams.y);
|
||||
float p = (x + z) * WaveParams.z;
|
||||
|
||||
float3 result = position;
|
||||
|
||||
result.y += p * waveFactor;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
float4 clipToScreen(float4 pos)
|
||||
{
|
||||
#ifdef GLSL
|
||||
pos.xy = pos.xy * 0.5 + 0.5 * pos.w;
|
||||
#else
|
||||
pos.xy = pos.xy * float2(0.5, -0.5) + 0.5 * pos.w;
|
||||
#endif
|
||||
return pos;
|
||||
}
|
||||
|
||||
float2 getUV(float3 position, ATTR_INT projection, float seed)
|
||||
{
|
||||
float3 u = WorldMatrixArray[1 + int(projection)].xyz;
|
||||
float3 v = WorldMatrixArray[19 + int(projection)].xyz;
|
||||
|
||||
float2 uv = float2(dot(position, u), dot(position, v)) * (0.25 * CFG_TEXTURE_TILING) + CFG_TEXTURE_DETILING * float2(seed, floor(seed * 2.6651441f));
|
||||
|
||||
return uv;
|
||||
}
|
||||
|
||||
VertexOutput WaterVS(Appdata IN)
|
||||
{
|
||||
VertexOutput OUT = (VertexOutput)0;
|
||||
|
||||
float3 posWorld = IN.Position.xyz * WorldMatrixArray[0].w + WorldMatrixArray[0].xyz;
|
||||
float3 normalWorld = IN.Normal.xyz * (1.0 / 127.0) - 1.0;
|
||||
|
||||
#if defined(GLSLES) && !defined(GL3) // iPad2 workaround
|
||||
float3 weights = abs(IN.Position.www - float3(0, 1, 2)) < 0.1;
|
||||
#else
|
||||
float3 weights = IN.Position.www == float3(0, 1, 2);
|
||||
#endif
|
||||
|
||||
float waveFactor = dot(weights, IN.Material0.xyz) * (1.0 / 255.0);
|
||||
|
||||
#ifdef PIN_HQ
|
||||
float fade = saturate0(1 - dot(posWorld - G(CameraPosition), -G(ViewDir).xyz) * G(FadeDistance_GlowFactor).y);
|
||||
|
||||
posWorld = displacePosition(posWorld, waveFactor * fade);
|
||||
#endif
|
||||
|
||||
OUT.HPosition = mul(G(ViewProjection), float4(posWorld, 1));
|
||||
|
||||
OUT.LightPosition_Fog = float4(lgridPrepareSample(lgridOffset(posWorld, normalWorld)), (G(FogParams).z - OUT.HPosition.w) * G(FogParams).w);
|
||||
|
||||
OUT.Uv0 = getUV(posWorld, IN.Material1.x, IN.Normal.w);
|
||||
OUT.Uv1 = getUV(posWorld, IN.Material1.y, IN.Material0.w);
|
||||
OUT.Uv2 = getUV(posWorld, IN.Material1.z, IN.Material1.w);
|
||||
|
||||
OUT.Weights_Wave.xyz = weights;
|
||||
OUT.Weights_Wave.w = waveFactor;
|
||||
|
||||
OUT.Normal = normalWorld;
|
||||
OUT.View_Depth = float4(G(CameraPosition) - posWorld, OUT.HPosition.w);
|
||||
OUT.Tangents = float3(IN.Material1.xyz) > 7.5; // side vs top
|
||||
|
||||
#ifdef PIN_HQ
|
||||
OUT.PositionScreen = clipToScreen(OUT.HPosition);
|
||||
#endif
|
||||
|
||||
return OUT;
|
||||
}
|
||||
|
||||
TEX_DECLARE2D(NormalMap1, 0);
|
||||
TEX_DECLARE2D(NormalMap2, 1);
|
||||
TEX_DECLARECUBE(EnvMap, 2);
|
||||
LGRID_SAMPLER(LightMap, 3);
|
||||
TEX_DECLARE2D(LightMapLookup, 4);
|
||||
TEX_DECLARE2D(GBufferColor, 5);
|
||||
TEX_DECLARE2D(GBufferDepth, 6);
|
||||
|
||||
float fresnel(float ndotv)
|
||||
{
|
||||
return saturate(0.78 - 2.5 * abs(ndotv)) + CFG_FRESNEL_OFFSET;
|
||||
}
|
||||
|
||||
float4 sampleMix(float2 uv)
|
||||
{
|
||||
#ifdef PIN_HQ
|
||||
return lerp(tex2D(NormalMap1, uv), tex2D(NormalMap2, uv), WaveParams.w);
|
||||
#else
|
||||
return tex2D(NormalMap1, uv);
|
||||
#endif
|
||||
}
|
||||
|
||||
float3 sampleNormal(float2 uv0, float2 uv1, float2 uv2, float3 w, float3 normal, float3 tsel)
|
||||
{
|
||||
return terrainNormal(sampleMix(uv0), sampleMix(uv1), sampleMix(uv2), w, normal, tsel);
|
||||
}
|
||||
|
||||
float3 sampleNormalSimple(float2 uv0, float2 uv1, float2 uv2, float3 w)
|
||||
{
|
||||
float4 data = sampleMix(uv0) * w.x + sampleMix(uv1) * w.y + sampleMix(uv2) * w.z;
|
||||
|
||||
return nmapUnpack(data).xzy;
|
||||
}
|
||||
|
||||
float unpackDepth(float2 uv)
|
||||
{
|
||||
float4 geomTex = tex2D(GBufferDepth, uv);
|
||||
float d = geomTex.z * (1.0f/256.0f) + geomTex.w;
|
||||
return d * GBUFFER_MAX_DEPTH;
|
||||
}
|
||||
|
||||
float3 getRefractedColor(float4 cpos, float3 N, float3 waterColor)
|
||||
{
|
||||
float2 refruv0 = cpos.xy / cpos.w;
|
||||
float2 refruv1 = refruv0 + N.xz * CFG_REFRACTION_STRENGTH;
|
||||
|
||||
float4 refr0 = tex2D(GBufferColor, refruv0);
|
||||
refr0.w = unpackDepth(refruv0);
|
||||
|
||||
float4 refr1 = tex2D(GBufferColor, refruv1);
|
||||
refr1.w = unpackDepth(refruv1);
|
||||
|
||||
float4 result = lerp(refr0, refr1, saturate(refr1.w - cpos.w));
|
||||
|
||||
// Estimate water absorption by a scaled depth difference
|
||||
float depthfade = saturate((result.w - cpos.w) * WaterParams.x + WaterParams.y);
|
||||
|
||||
// Since GBuffer depth is clamped we tone the refraction down after half of the range for a smooth fadeout
|
||||
float gbuffade = saturate(cpos.w * (2.f / GBUFFER_MAX_DEPTH) - 1);
|
||||
|
||||
float fade = saturate(depthfade + gbuffade);
|
||||
|
||||
return lerp(result.rgb, waterColor, fade);
|
||||
}
|
||||
|
||||
float3 getReflectedColor(float4 cpos, float3 wpos, float3 R)
|
||||
{
|
||||
float3 result = 0;
|
||||
float inside = 0;
|
||||
|
||||
float distance = CFG_SSR_START_DISTANCE;
|
||||
float diff = 0;
|
||||
float diffclamp = cpos.w * CFG_SSR_STEP_CLAMP;
|
||||
|
||||
float4 Pproj = cpos;
|
||||
float4 Rproj = clipToScreen(mul(G(ViewProjection), float4(R, 0)));
|
||||
|
||||
#ifndef GLSL
|
||||
[unroll]
|
||||
#endif
|
||||
for (int i = 0; i < CFG_SSR_STEPS; ++i)
|
||||
{
|
||||
distance += clamp(diff, -diffclamp, diffclamp);
|
||||
|
||||
float4 cposi = Pproj + Rproj * distance;
|
||||
float2 uv = cposi.xy / cposi.w;
|
||||
float depth = unpackDepth(uv);
|
||||
|
||||
diff = depth - cposi.w;
|
||||
}
|
||||
|
||||
float4 cposi = Pproj + Rproj * distance;
|
||||
float2 uv = cposi.xy / cposi.w;
|
||||
|
||||
// Ray hit has to be inside the screen bounds
|
||||
float ufade = abs(uv.x - 0.5) < 0.5;
|
||||
float vfade = abs(uv.y - 0.5) < 0.5;
|
||||
|
||||
// Fade reflections out with distance; use max(ray hit, original depth) to discard hits that are too far
|
||||
// 4 - depth * 4 would give us fade out from 0.75 to 1; 3.9 makes sure reflections go to 0 slightly before GBUFFER_MAX_DEPTH
|
||||
float wfade = saturate((4 - 0.1) - max(cpos.w, cposi.w) * (4.f / GBUFFER_MAX_DEPTH));
|
||||
|
||||
// Ray hit has to be reasonably close to where we started
|
||||
float dfade = abs(diff) < CFG_SSR_DEPTH_CUTOFF;
|
||||
|
||||
// Avoid back-projection
|
||||
float Vfade = Rproj.w > 0;
|
||||
|
||||
float fade = ufade * vfade * wfade * dfade * Vfade;
|
||||
|
||||
return lerp(texCUBE(EnvMap, R).rgb, tex2D(GBufferColor, uv).rgb, fade);
|
||||
}
|
||||
|
||||
float4 WaterPS(VertexOutput IN): COLOR0
|
||||
{
|
||||
float4 light = lgridSample(TEXTURE(LightMap), TEXTURE(LightMapLookup), IN.LightPosition_Fog.xyz);
|
||||
float shadow = light.a;
|
||||
|
||||
float3 w = IN.Weights_Wave.xyz;
|
||||
|
||||
// Use simplified normal reconstruction for LQ mobile (assumes flat water surface)
|
||||
#if defined(GLSLES) && !defined(PIN_HQ)
|
||||
float3 normal = sampleNormalSimple(IN.Uv0, IN.Uv1, IN.Uv2, w);
|
||||
#else
|
||||
float3 normal = sampleNormal(IN.Uv0, IN.Uv1, IN.Uv2, w, IN.Normal, IN.Tangents);
|
||||
#endif
|
||||
|
||||
// Flatten the normal for Fresnel and for reflections to make them less chaotic
|
||||
float3 flatNormal = lerp(IN.Normal, normal, CFG_NORMAL_STRENGTH);
|
||||
|
||||
float3 waterColor = WaterColor.rgb;
|
||||
|
||||
#ifdef PIN_HQ
|
||||
float fade = saturate0(1 - IN.View_Depth.w * G(FadeDistance_GlowFactor).y);
|
||||
|
||||
float3 view = normalize(IN.View_Depth.xyz);
|
||||
|
||||
float fre = fresnel(dot(flatNormal, view)) * IN.Weights_Wave.w;
|
||||
|
||||
float3 position = G(CameraPosition) - IN.View_Depth.xyz;
|
||||
|
||||
#ifdef PIN_GBUFFER
|
||||
float3 refr = getRefractedColor(IN.PositionScreen, normal, waterColor);
|
||||
float3 refl = getReflectedColor(IN.PositionScreen, position, reflect(-view, flatNormal));
|
||||
#else
|
||||
float3 refr = waterColor;
|
||||
float3 refl = texCUBE(EnvMap, reflect(-view, flatNormal)).rgb;
|
||||
#endif
|
||||
|
||||
float specularIntensity = CFG_SPECULAR * fade;
|
||||
float specularPower = CFG_GLOSS;
|
||||
|
||||
float3 specular = G(Lamp0Color) * (specularIntensity * shadow * (float)(half)pow(saturate(dot(normal, normalize(-G(Lamp0Dir) + view))), specularPower));
|
||||
#else
|
||||
float3 view = normalize(IN.View_Depth.xyz);
|
||||
|
||||
float fre = fresnel(dot(flatNormal, view));
|
||||
|
||||
float3 refr = waterColor;
|
||||
|
||||
float3 refl = texCUBE(EnvMap, reflect(-IN.View_Depth.xyz, flatNormal)).rgb;
|
||||
|
||||
float3 specular = 0;
|
||||
#endif
|
||||
|
||||
// Combine
|
||||
float4 result;
|
||||
result.rgb = lerp(refr, refl, fre) * (G(AmbientColor).rgb + G(Lamp0Color).rgb * shadow + light.rgb) + specular;
|
||||
result.a = 1;
|
||||
|
||||
float fogAlpha = saturate(IN.LightPosition_Fog.w);
|
||||
|
||||
result.rgb = lerp(G(FogColor), result.rgb, fogAlpha);
|
||||
|
||||
return result;
|
||||
}
|
||||
200
client/common/shaders/source/ssao.hlsl
Normal file
200
client/common/shaders/source/ssao.hlsl
Normal file
@@ -0,0 +1,200 @@
|
||||
#include "screenspace.hlsl"
|
||||
|
||||
// ao sampling
|
||||
#define SSAO_NUM_PAIRS 8
|
||||
#define SSAO_RADIUS 2
|
||||
#define SSAO_MIN_PIXELS 10
|
||||
#define SSAO_MAX_PIXELS 100
|
||||
#define SSAO_MIP_OFFSET 2
|
||||
|
||||
// ao tuning
|
||||
#define SSAO_OVERSHADOW 0.75
|
||||
#define SSAO_ANGLELIMIT 0.1
|
||||
#define SSAO_BOOST 1
|
||||
|
||||
// blur tuning
|
||||
#define SSAO_BLUR_SAMPLES 3
|
||||
#define SSAO_BLUR_STRENGTH 1.5
|
||||
#define SSAO_BLUR_DEPTH_THRESHOLD 0.4
|
||||
|
||||
// composite tuning
|
||||
#define SSAO_DEPTH_THRESHOLD_CENTER 0.02
|
||||
#define SSAO_DEPTH_THRESHOLD_ESTIMATE 0.4
|
||||
|
||||
TEX_DECLARE2D(depthBuffer, 0);
|
||||
TEX_DECLARE2D(randMap, 1);
|
||||
TEX_DECLARE2D(map, 2);
|
||||
TEX_DECLARE2D(geomMap, 3);
|
||||
|
||||
uniform float4 Params;
|
||||
|
||||
float4 SSAODepthDownPS(float4 pos: POSITION, float2 uv: TEXCOORD0) : COLOR0
|
||||
{
|
||||
float d0 = tex2D(geomMap, uv + TextureSize.zw * float2(-0.25, -0.25)).r;
|
||||
float d1 = tex2D(geomMap, uv + TextureSize.zw * float2(+0.25, -0.25)).r;
|
||||
float d2 = tex2D(geomMap, uv + TextureSize.zw * float2(-0.25, +0.25)).r;
|
||||
float d3 = tex2D(geomMap, uv + TextureSize.zw * float2(+0.25, +0.25)).r;
|
||||
|
||||
return min(min(d0, d3), min(d1, d2));
|
||||
}
|
||||
|
||||
float getSampleLength(float i)
|
||||
{
|
||||
return (i+1) / (SSAO_NUM_PAIRS+2);
|
||||
}
|
||||
|
||||
float2 getSampleRotation(float i)
|
||||
{
|
||||
float pi = 3.1415926;
|
||||
|
||||
return float2(cos(i / SSAO_NUM_PAIRS * 2 * pi), sin (i / SSAO_NUM_PAIRS * 2 * pi));
|
||||
}
|
||||
|
||||
float4 SSAOPS(float4 pos: POSITION, float2 uv: TEXCOORD0): COLOR0
|
||||
{
|
||||
float baseDepth = tex2Dlod(depthBuffer, float4(uv, 0, 0)).r;
|
||||
|
||||
float4 noiseTex = tex2D(randMap, frac(uv*TextureSize.xy /4))*2-1;
|
||||
|
||||
float2x2 rotation =
|
||||
{
|
||||
{ noiseTex.y, noiseTex.x },
|
||||
{ -noiseTex.x, noiseTex.y }
|
||||
};
|
||||
|
||||
const float sphereRadiusZB = SSAO_RADIUS / GBUFFER_MAX_DEPTH;
|
||||
|
||||
float2 radiusTex = clamp(sphereRadiusZB / baseDepth * Params.xy, SSAO_MIN_PIXELS * TextureSize.zw, SSAO_MAX_PIXELS * TextureSize.zw);
|
||||
|
||||
float lod = log2(getSampleLength(0) * length(radiusTex * TextureSize.xy)) - SSAO_MIP_OFFSET;
|
||||
|
||||
float result = 1; // center pixel
|
||||
float weight = 2;
|
||||
|
||||
for (int i = 0; i < SSAO_NUM_PAIRS; i++)
|
||||
{
|
||||
const float offsetLength = getSampleLength(i);
|
||||
const float2 offsetVector = getSampleRotation(i) * offsetLength;
|
||||
const float segmentDiff = sphereRadiusZB * sqrt(1 - offsetLength*offsetLength);
|
||||
const float angleLimit = offsetLength * SSAO_ANGLELIMIT;
|
||||
|
||||
float2 offset = mul(rotation, offsetVector) * radiusTex;
|
||||
|
||||
float2 offsetDepth;
|
||||
offsetDepth.x = tex2Dlod(depthBuffer, float4(uv + offset, 0, lod)).r;
|
||||
offsetDepth.y = tex2Dlod(depthBuffer, float4(uv - offset, 0, lod)).r;
|
||||
|
||||
float2 diff = offsetDepth - baseDepth.xx;
|
||||
|
||||
// 0 is the near surface of the sphere, 1 is the far surface, 0.5 is the middle
|
||||
float2 normalizedDiff = diff * (1 / segmentDiff * 0.5) + 0.5;
|
||||
|
||||
// only add sample contribution if both samples are visible - if one is invisible we estimate the twin as 1-s so sum is 1
|
||||
float sampleadd = saturate(min(normalizedDiff.x, normalizedDiff.y) + SSAO_OVERSHADOW);
|
||||
|
||||
result += (saturate(normalizedDiff.x + angleLimit) + saturate(normalizedDiff.y + angleLimit)) * sampleadd;
|
||||
weight += 2 * sampleadd;
|
||||
}
|
||||
|
||||
// rescale result from 0..0.5 to 0..1 and apply a power function
|
||||
float finalocc = (baseDepth > 0.99) ? 1 : pow(saturate(result / weight * 2), SSAO_BOOST);
|
||||
|
||||
return float4(finalocc, baseDepth, 0, 1);
|
||||
}
|
||||
|
||||
float2 ssaoBlur(float2 uv, float2 offset, TEXTURE_IN_2D(map))
|
||||
{
|
||||
float sigmaN = 1 / (2 * SSAO_BLUR_STRENGTH * SSAO_BLUR_STRENGTH);
|
||||
|
||||
float baseDepth = tex2D(map, uv).g;
|
||||
|
||||
const float sphereRadiusZB = SSAO_BLUR_DEPTH_THRESHOLD / GBUFFER_MAX_DEPTH;
|
||||
|
||||
float depthTolerance = clamp((baseDepth * 80) * sphereRadiusZB, 0.1 * sphereRadiusZB, 10 * sphereRadiusZB);
|
||||
|
||||
float result = 0;
|
||||
float weight = 0;
|
||||
|
||||
for (int i = -SSAO_BLUR_SAMPLES; i <= SSAO_BLUR_SAMPLES; ++i)
|
||||
{
|
||||
const float ix = i;
|
||||
const float iw = exp(-ix * ix * sigmaN);
|
||||
|
||||
float4 data = tex2D(map, uv + offset * ix);
|
||||
|
||||
float w = iw * (abs(data.g - baseDepth) < depthTolerance);
|
||||
|
||||
result += data.r * w;
|
||||
weight += w;
|
||||
}
|
||||
|
||||
return float2(result / weight, baseDepth);
|
||||
}
|
||||
|
||||
float4 SSAOBlurXPS(float4 pos: POSITION, float2 uv : TEXCOORD0): COLOR0
|
||||
{
|
||||
float2 o = float2(TextureSize.z, 0);
|
||||
|
||||
float2 ssaoTerm = ssaoBlur(uv, o, TEXTURE(map));
|
||||
|
||||
return float4(ssaoTerm, 0, 1);
|
||||
}
|
||||
|
||||
float4 SSAOBlurYPS(float4 pos: POSITION, float2 uv : TEXCOORD0): COLOR0
|
||||
{
|
||||
float2 o = float2(0, TextureSize.w);
|
||||
|
||||
float2 ssaoTerm = ssaoBlur(uv, o, TEXTURE(map));
|
||||
|
||||
return float4(ssaoTerm, 0, 1);
|
||||
}
|
||||
|
||||
VertexOutput_4uv SSAOCompositVS(float4 p: POSITION)
|
||||
{
|
||||
float2 uv = convertUv(p);
|
||||
|
||||
VertexOutput_4uv OUT;
|
||||
OUT.p = convertPosition(p, 1);
|
||||
OUT.uv = uv;
|
||||
|
||||
float2 uvOffset = TextureSize.zw * 2;
|
||||
|
||||
OUT.uv12.xy = uv + float2(uvOffset.x, 0);
|
||||
OUT.uv12.zw = uv - float2(uvOffset.x, 0);
|
||||
OUT.uv34.xy = uv + float2(0, uvOffset.y);
|
||||
OUT.uv34.zw = uv - float2(0, uvOffset.y);
|
||||
|
||||
return OUT;
|
||||
}
|
||||
|
||||
float4 SSAOCompositPS(VertexOutput_4uv IN): COLOR0
|
||||
{
|
||||
float4 geom = tex2D(geomMap, IN.uv);
|
||||
float4 mapC = tex2D(map, IN.uv);
|
||||
float4 map0 = tex2D(map, IN.uv12.xy);
|
||||
float4 map1 = tex2D(map, IN.uv12.zw);
|
||||
float4 map2 = tex2D(map, IN.uv34.xy);
|
||||
float4 map3 = tex2D(map, IN.uv34.zw);
|
||||
|
||||
float baseDepth = geom.r;
|
||||
|
||||
float ssaoC = mapC.r;
|
||||
float depthC = mapC.g;
|
||||
|
||||
float4 ssaoEst = float4(map0.r, map1.r, map2.r, map3.r);
|
||||
float4 depthEst = float4(map0.g, map1.g, map2.g, map3.g);
|
||||
|
||||
// can we trust the neighbors? 1 - yes, 0 - no
|
||||
float4 checkEst = abs(depthEst - baseDepth) < SSAO_DEPTH_THRESHOLD_ESTIMATE / GBUFFER_MAX_DEPTH;
|
||||
|
||||
float checkEstSum = dot(checkEst, 1);
|
||||
float ssaoTermEst = dot(ssaoEst, checkEst) / checkEstSum;
|
||||
|
||||
// the final decision: pick the estimate sample if there are good neighbors and base depth is not trustworthy
|
||||
float ssaoTerm = abs(depthC - baseDepth) * checkEstSum > SSAO_DEPTH_THRESHOLD_CENTER / GBUFFER_MAX_DEPTH ? ssaoTermEst : ssaoC;
|
||||
|
||||
// AO reduction for high specular and diffuse values. Computed in gbufferPack in common.h
|
||||
float slope = geom.g;
|
||||
|
||||
return float4((1 - slope) * ssaoTerm.xxx + slope, 1);
|
||||
}
|
||||
39
client/common/shaders/source/texcomp.hlsl
Normal file
39
client/common/shaders/source/texcomp.hlsl
Normal file
@@ -0,0 +1,39 @@
|
||||
#include "common.h"
|
||||
|
||||
struct Appdata
|
||||
{
|
||||
float4 Position : POSITION;
|
||||
float2 Uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct VertexOutput
|
||||
{
|
||||
float4 HPosition : POSITION;
|
||||
float2 Uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
VertexOutput TexCompVS(Appdata IN)
|
||||
{
|
||||
VertexOutput OUT = (VertexOutput)0;
|
||||
|
||||
OUT.HPosition = mul(G(ViewProjection), IN.Position);
|
||||
OUT.Uv = IN.Uv;
|
||||
|
||||
return OUT;
|
||||
}
|
||||
|
||||
TEX_DECLARE2D(DiffuseMap, 0);
|
||||
|
||||
uniform float4 Color;
|
||||
|
||||
float4 TexCompPS(VertexOutput IN): COLOR0
|
||||
{
|
||||
return tex2Dbias(DiffuseMap, float4(IN.Uv, 0, -10)) * Color;
|
||||
}
|
||||
|
||||
float4 TexCompPMAPS(VertexOutput IN): COLOR0
|
||||
{
|
||||
float4 tex = tex2Dbias(DiffuseMap, float4(IN.Uv, 0, -10));
|
||||
|
||||
return float4(tex.rgb * tex.a * Color.rgb, tex.a * Color.a);
|
||||
}
|
||||
58
client/common/shaders/source/ui.hlsl
Normal file
58
client/common/shaders/source/ui.hlsl
Normal file
@@ -0,0 +1,58 @@
|
||||
#include "common.h"
|
||||
|
||||
struct Appdata
|
||||
{
|
||||
float4 Position : POSITION;
|
||||
float2 Uv : TEXCOORD0;
|
||||
float4 Color : COLOR0;
|
||||
};
|
||||
|
||||
struct VertexOutput
|
||||
{
|
||||
float4 HPosition : POSITION;
|
||||
|
||||
float2 Uv : TEXCOORD0;
|
||||
float4 Color : COLOR0;
|
||||
|
||||
#if defined(PIN_FOG)
|
||||
float FogFactor : TEXCOORD1;
|
||||
#endif
|
||||
};
|
||||
|
||||
uniform float4 UIParams; // x = luminance sampling on/off, w = z offset
|
||||
TEX_DECLARE2D(DiffuseMap, 0);
|
||||
|
||||
VertexOutput UIVS(Appdata IN)
|
||||
{
|
||||
VertexOutput OUT = (VertexOutput)0;
|
||||
|
||||
OUT.HPosition = mul(G(ViewProjection), IN.Position);
|
||||
OUT.HPosition.z -= UIParams.w; // against z-fighting
|
||||
|
||||
OUT.Uv = IN.Uv;
|
||||
OUT.Color = IN.Color;
|
||||
|
||||
#if defined(PIN_FOG)
|
||||
OUT.FogFactor = (G(FogParams).z - OUT.HPosition.w) * G(FogParams).w;
|
||||
#endif
|
||||
|
||||
return OUT;
|
||||
}
|
||||
|
||||
float4 UIPS(VertexOutput IN): COLOR0
|
||||
{
|
||||
float4 base;
|
||||
|
||||
if (UIParams.x > 0.5)
|
||||
base = float4(1, 1, 1,tex2D(DiffuseMap, IN.Uv).r);
|
||||
else
|
||||
base = tex2D(DiffuseMap, IN.Uv);
|
||||
|
||||
float4 result = IN.Color * base;
|
||||
|
||||
#if defined(PIN_FOG)
|
||||
result.rgb = lerp(G(FogColor), result.rgb, saturate(IN.FogFactor));
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
213
client/common/shaders/source/water.hlsl
Normal file
213
client/common/shaders/source/water.hlsl
Normal file
@@ -0,0 +1,213 @@
|
||||
|
||||
//
|
||||
// Water shader.
|
||||
// Big, fat and ugly.
|
||||
//
|
||||
// All (most) things considered, I have converged to this particular way of rendering water:
|
||||
//
|
||||
// Vertex waves
|
||||
// No transparency. Solid color for deep water.
|
||||
// Fresnel law, reflects environment.
|
||||
// Phong speculars.
|
||||
// Ripples via animated normal map. Adjustable intensity, speed and scale. Affect reflection and speculars.
|
||||
|
||||
#include "common.h"
|
||||
|
||||
WORLD_MATRIX(WorldMatrix);
|
||||
|
||||
uniform float4 nmAnimLerp; // ratio between normal map frames
|
||||
uniform float4 waveParams; // .x = frequency .y = phase .z = height
|
||||
uniform float4 WaterColor; // deep water color
|
||||
|
||||
#ifdef PIN_HQ
|
||||
# define WATER_LOD 1
|
||||
#else
|
||||
# define WATER_LOD 2
|
||||
#endif
|
||||
|
||||
#define LODBIAS (-1)
|
||||
|
||||
float fadeFactor( float3 wspos )
|
||||
{
|
||||
return saturate( -0.4f + 1.4f*length( G(CameraPosition) - wspos.xyz ) * G(FadeDistance_GlowFactor).y );
|
||||
}
|
||||
|
||||
float wave( float4 wspos )
|
||||
{
|
||||
float x = sin( ( wspos.z - wspos.x - waveParams.y ) * waveParams.x );
|
||||
float z = sin( ( wspos.z + wspos.x + waveParams.y ) * waveParams.x );
|
||||
float p = (x + z) * waveParams.z;
|
||||
return p - p * fadeFactor( wspos.xyz );
|
||||
}
|
||||
|
||||
// perturbs the water mesh and vertex normals
|
||||
void makeWaves( inout float4 wspos, inout float3 wsnrm )
|
||||
{
|
||||
#if WATER_LOD == 0
|
||||
float gridSize = 4.0f;
|
||||
|
||||
float4 wspos1 = wspos;
|
||||
float4 wspos2 = wspos;
|
||||
|
||||
wspos1.x += gridSize;
|
||||
wspos2.z += gridSize;
|
||||
|
||||
wspos.y += wave(wspos) ;
|
||||
wspos1.y += wave(wspos1);
|
||||
wspos2.y += wave(wspos2);
|
||||
|
||||
wsnrm = normalize( cross( wspos2.xyz - wspos.xyz, wspos1.xyz - wspos.xyz ) );
|
||||
#elif WATER_LOD == 1
|
||||
wspos.y += wave( wspos );
|
||||
#else /* do n0thing */
|
||||
#endif
|
||||
}
|
||||
|
||||
struct V2P
|
||||
{
|
||||
float4 pos : POSITION;
|
||||
float4 tc0Fog : TEXCOORD0;
|
||||
float4 wspos : TEXCOORD1;
|
||||
float3 wsnrm : TEXCOORD2;
|
||||
float3 light : TEXCOORD3;
|
||||
float3 fade : TEXCOORD4;
|
||||
};
|
||||
|
||||
V2P water_vs(
|
||||
ATTR_INT4 pos : POSITION,
|
||||
ATTR_INT3 nrm : NORMAL
|
||||
)
|
||||
{
|
||||
V2P o;
|
||||
|
||||
// Decode vertex data
|
||||
float3 normal = (nrm - 127.0) / 127.0;
|
||||
|
||||
normal = normalize(normal);
|
||||
|
||||
float4 wspos = mul( WorldMatrix, pos );
|
||||
float3 wsnrm = normal;
|
||||
|
||||
wspos.y -= 2*waveParams.z;
|
||||
|
||||
makeWaves( /*INOUT*/ wspos, /*INOUT*/ wsnrm );
|
||||
|
||||
o.wspos = wspos;
|
||||
o.wsnrm = wsnrm;
|
||||
|
||||
if( normal.y < 0.01f ) o.wsnrm = normal;
|
||||
|
||||
// box mapping
|
||||
//float3x2 m = { wspos.xz, wspos.xy, wspos.yz };
|
||||
//float2 tcselect = mul( abs( nrm.yzx ), m );
|
||||
|
||||
float2 tcselect;
|
||||
float3 wspostc = float3( wspos.x, -wspos.y, wspos.z );
|
||||
|
||||
tcselect.x = dot( abs( normal.yxz ), wspostc.xzx );
|
||||
tcselect.y = dot( abs( normal.yxz ), wspostc.zyy );
|
||||
|
||||
o.pos = mul( G(ViewProjection), wspos );
|
||||
o.tc0Fog.xy = tcselect * .05f;
|
||||
o.tc0Fog.z = saturate( (G(FogParams).z - o.pos.w) * G(FogParams).w );
|
||||
o.tc0Fog.w = LODBIAS;
|
||||
|
||||
o.light = lgridPrepareSample(lgridOffset(wspos.xyz, wsnrm.xyz));
|
||||
|
||||
o.fade.x = fadeFactor( wspos.xyz );
|
||||
o.fade.y = (1-o.fade.x) * saturate( dot( wsnrm, -G(Lamp0Dir) ) ) * 100;
|
||||
o.fade.z = 1 - 0.9*saturate1( exp( -0.005 * length( G(CameraPosition) - wspos.xyz ) ) );
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TEX_DECLARE2D(NormalMap1, 0);
|
||||
TEX_DECLARE2D(NormalMap2, 1);
|
||||
TEX_DECLARECUBE(EnvMap, 2);
|
||||
LGRID_SAMPLER(LightMap, 3);
|
||||
TEX_DECLARE2D(LightMapLookup, 4);
|
||||
|
||||
float3 pixelNormal( float4 tc0 )
|
||||
{
|
||||
float4 nm1 = tex2Dbias( NormalMap1, tc0 );
|
||||
#if WATER_LOD <= 1
|
||||
float4 nm2 = tex2Dbias( NormalMap2, tc0 );
|
||||
float4 nm3 = lerp( nm1, nm2, nmAnimLerp.xxxx );
|
||||
#else
|
||||
float4 nm3 = nm1;
|
||||
#endif
|
||||
return nmapUnpack( nm3 );
|
||||
}
|
||||
|
||||
// Fresnel approximation. N1 and N2 are refractive indices.
|
||||
// for above water, use n1 = 1, n2 = 1.3, for underwater use n1 = 1.3, n2 = 1
|
||||
float fresnel( float3 N, float3 V, float n1, float n2, float p, float fade )
|
||||
{
|
||||
#if WATER_LOD == 0
|
||||
float r0 = (n1-n2)/(n1+n2);
|
||||
r0 *= r0;
|
||||
return r0 + (1-r0) * pow( 1 - abs( dot( normalize(N), V ) ), p );
|
||||
#else
|
||||
return 0.1 + saturate( - 1.9 * abs( dot( N, V ) ) + 0.8); // HAXX!
|
||||
//return 1 - 2 * abs( dot( N, V ) );
|
||||
#endif
|
||||
}
|
||||
|
||||
float4 envColor( float3 N, float3 V, float fade )
|
||||
{
|
||||
float3 dir = reflect( V, N );
|
||||
return texCUBE(EnvMap, dir) * 0.91f;
|
||||
}
|
||||
|
||||
float4 deepWaterColor(float4 light)
|
||||
{
|
||||
//float4 tint = 5*float4( 0.1f, 0.1f, 0.13f, 1);
|
||||
float4 tint = 0.8f*float4( 118, 143, 153, 255 ) / 255;
|
||||
return (light + texCUBEbias( EnvMap, float4( 0,1,0, 10.0f) )) * tint;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////
|
||||
//////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
float4 water_ps( V2P v ) : COLOR0
|
||||
{
|
||||
|
||||
float4 WaterColorTest = 0.5 * float4( 26, 169, 185, 0 ) / 255;
|
||||
float4 FogColorTest = 0.8 * float4( 35, 107, 130, 0 ) / 255;
|
||||
|
||||
float3 N2 = v.wsnrm;
|
||||
float3 N1 = pixelNormal( v.tc0Fog ).xzy;
|
||||
float3 N3 = 0.5*(N2 + N1);
|
||||
|
||||
N3 = lerp( N3, N2, v.fade.z );
|
||||
|
||||
float3 L = /*normalize*/(-G(Lamp0Dir).xyz);
|
||||
float3 E = normalize( G(CameraPosition) - v.wspos.xyz );
|
||||
|
||||
float4 light = lgridSample(TEXTURE(LightMap), TEXTURE(LightMapLookup), v.light.xyz);
|
||||
|
||||
float fre = fresnel( N3, E, 1.0f, 1.3f, 5, v.fade.x );
|
||||
float3 diffuse = deepWaterColor(light).rgb;
|
||||
float3 env = envColor( N3, -E, v.fade.x ).rgb;
|
||||
|
||||
float3 R = reflect( -L, N1 );
|
||||
|
||||
#if WATER_LOD <= 1
|
||||
float specular = pow( saturate0( dot( R, E ) ), 1600 ) * L.y * 100; // baseline
|
||||
# ifndef GLSLES
|
||||
specular = 0.65 * saturate1( specular * saturate0( light.a - 0.4f ) );
|
||||
# endif
|
||||
#else
|
||||
float specular = 0;
|
||||
#endif
|
||||
|
||||
float3 result = lerp( diffuse, env, fre ) + specular.xxx;
|
||||
result = lerp( G(FogColor).rgb, result, v.tc0Fog.z );
|
||||
|
||||
return float4( result, 1 );
|
||||
}
|
||||
100
client/common/shaders/source/wood.hlsl
Normal file
100
client/common/shaders/source/wood.hlsl
Normal file
@@ -0,0 +1,100 @@
|
||||
#ifdef CLASSIC
|
||||
#define PIN_SURFACE
|
||||
#define ALREADY_HAS_PS
|
||||
#include "default.hlsl"
|
||||
|
||||
#define SPEC_EXPON 4
|
||||
#define KS .1
|
||||
|
||||
#define WoodContrast float3(0.1, 0.1, 0.1)
|
||||
#define Ks1 0.32
|
||||
#define Ks2 0.16
|
||||
#define RingScale 4
|
||||
#define AmpScale 1
|
||||
#define LightRingEnd 0.4
|
||||
#define DarkRingStart 0.8
|
||||
#define DarkRingEnd 0.83
|
||||
#define NormMapScale 0.6
|
||||
#define NoiseScale 64
|
||||
#define MixedColorRatio 0.315
|
||||
#define AAFreqMultiplier 12
|
||||
|
||||
void DefaultPS(VertexOutput IN,
|
||||
#ifdef PIN_GBUFFER
|
||||
out float4 oColor1: COLOR1,
|
||||
#endif
|
||||
out float4 oColor0: COLOR0)
|
||||
{
|
||||
float3 nn = normalize(IN.Normal);
|
||||
|
||||
float3x3 normalMatrix = {
|
||||
IN.Tangent.xyz,
|
||||
cross(nn, IN.Tangent.xyz),
|
||||
nn
|
||||
};
|
||||
|
||||
float4 WoodPos = float4(IN.Pos.xyz, lerp(0, .92, abs(dot(float3(1,0,0), nn))));
|
||||
|
||||
float2 NormalUV = IN.Uv.xy * NormMapScale * 3;
|
||||
float singularityAttenuation = WoodPos.w;
|
||||
|
||||
float noiseval = tex3D(SpecularMap, WoodPos.xyz / NoiseScale).x;
|
||||
float3 tn = tex2D(NormalMap, NormalUV).xyz - .5;
|
||||
tn = lerp(tn, float3(0, 0, .5), singularityAttenuation);
|
||||
float4 edgeDistances = IN.EdgeDistances;
|
||||
tn = CalcBevel(edgeDistances, tn, IN.View_Depth.w);
|
||||
|
||||
nn = mul(tn, normalMatrix);
|
||||
|
||||
float signalfreq = length(float4(ddx(WoodPos.y), ddx(WoodPos.z), ddy(WoodPos.y), ddy(WoodPos.z))); // seems to be angle based thing
|
||||
float aa_attn = saturate(signalfreq*AAFreqMultiplier - 1.0f);
|
||||
float3 Pwood = WoodPos.xyz + (AmpScale * noiseval);
|
||||
float r = RingScale * length(Pwood.yz);
|
||||
r = r + tex3D(SpecularMap,r.xxx/32.0).x;
|
||||
r = r - floor(r); // stepping in the rings in formed through this here
|
||||
r = smoothstep(LightRingEnd, DarkRingStart, r) - smoothstep(DarkRingEnd,1.0,r);
|
||||
// apply anti-aliasing
|
||||
r = lerp(r, MixedColorRatio, aa_attn);
|
||||
|
||||
float3 albedo = IN.Color.xyz + WoodContrast * (MixedColorRatio - r);
|
||||
float Ks = lerp(Ks1,Ks2,r);
|
||||
|
||||
float3 vn = normalize(IN.View_Depth.xyz);
|
||||
float4 light = lgridSample(TEXTURE(LightMap), TEXTURE(LightMapLookup), IN.LightPosition_Fog.xyz);
|
||||
light.a = shadowSample(TEXTURE(ShadowMap), IN.PosLightSpace.xyz, light.a);
|
||||
|
||||
float3 diffuse;
|
||||
float3 specular;
|
||||
Shade(albedo, nn, vn, Ks, SPEC_EXPON, light, diffuse, specular);
|
||||
oColor0 = float4(diffuse + specular, IN.Color.w);
|
||||
|
||||
float fogAlpha = saturate((G(FogParams).z - length(IN.View_Depth.xyz)) * G(FogParams).w);
|
||||
oColor0.xyz = lerp(G(FogColor), oColor0.rgb, fogAlpha);
|
||||
|
||||
#ifdef PIN_GBUFFER
|
||||
oColor1 = gbufferPack(IN.View_Depth.w, diffuse.rgb, specular.rgb, fogAlpha);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
#define CFG_TEXTURE_TILING 1
|
||||
|
||||
#define CFG_DIFFUSE_SCALE 1
|
||||
#define CFG_SPECULAR_SCALE 2
|
||||
#define CFG_GLOSS_SCALE 256
|
||||
#define CFG_REFLECTION_SCALE 0
|
||||
|
||||
#define CFG_NORMAL_SHADOW_SCALE 0.3
|
||||
|
||||
#define CFG_SPECULAR_LOD 0.25
|
||||
#define CFG_GLOSS_LOD 32
|
||||
|
||||
#define CFG_NORMAL_DETAIL_TILING 7
|
||||
#define CFG_NORMAL_DETAIL_SCALE 0.6
|
||||
|
||||
#define CFG_FAR_TILING 0
|
||||
#define CFG_FAR_DIFFUSE_CUTOFF 0
|
||||
#define CFG_FAR_NORMAL_CUTOFF 0
|
||||
#define CFG_FAR_SPECULAR_CUTOFF 0
|
||||
|
||||
#include "material.hlsl"
|
||||
#endif
|
||||
27
client/common/shaders/source/woodplanks.hlsl
Normal file
27
client/common/shaders/source/woodplanks.hlsl
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifdef CLASSIC
|
||||
#include "wood.hlsl"
|
||||
#else
|
||||
#define CFG_TEXTURE_TILING 1
|
||||
|
||||
#define CFG_DIFFUSE_SCALE 1
|
||||
#define CFG_SPECULAR_SCALE 2
|
||||
#define CFG_GLOSS_SCALE 256
|
||||
#define CFG_REFLECTION_SCALE 0
|
||||
|
||||
#define CFG_NORMAL_SHADOW_SCALE 0.3
|
||||
|
||||
#define CFG_SPECULAR_LOD 0.28
|
||||
#define CFG_GLOSS_LOD 53
|
||||
|
||||
#define CFG_NORMAL_DETAIL_TILING 0
|
||||
#define CFG_NORMAL_DETAIL_SCALE 0
|
||||
|
||||
#define CFG_FAR_TILING 0
|
||||
#define CFG_FAR_DIFFUSE_CUTOFF 0
|
||||
#define CFG_FAR_NORMAL_CUTOFF 0
|
||||
#define CFG_FAR_SPECULAR_CUTOFF 0
|
||||
|
||||
#define CFG_OPT_BLEND_COLOR
|
||||
|
||||
#include "material.hlsl"
|
||||
#endif
|
||||
Reference in New Issue
Block a user