mirror of
https://github.com/XProger/OpenLara.git
synced 2025-08-06 13:16:52 +02:00
#15 PSV fix water mask; disable volumetric caustics effect for PSV; fix underwater shading; convert BGRA -> RGBA for d3d9 renderer (except GUI); caustics fade on room edges;
This commit is contained in:
@@ -485,7 +485,7 @@ struct WaterCache {
|
||||
int w = maxX - minX;
|
||||
int h = maxZ - minZ;
|
||||
|
||||
uint16 *m = new uint16[w * h];
|
||||
uint8 *m = new uint8[w * h];
|
||||
memset(m, 0, w * h * sizeof(m[0]));
|
||||
|
||||
for (int z = minZ; z < maxZ; z++)
|
||||
@@ -505,9 +505,9 @@ struct WaterCache {
|
||||
}
|
||||
}
|
||||
|
||||
m[(x - minX) + w * (z - minZ)] = hasWater ? 0xFFFF : 0x0000; // TODO: flow map
|
||||
m[(x - minX) + w * (z - minZ)] = hasWater ? 0xFF : 0x00; // TODO: flow map
|
||||
}
|
||||
mask = new Texture(w, h, FMT_RGBA16, OPT_NEAREST, m);
|
||||
mask = new Texture(w, h, FMT_LUMINANCE, OPT_NEAREST, m);
|
||||
delete[] m;
|
||||
|
||||
size = vec3(float((maxX - minX) * 512), 1.0f, float((maxZ - minZ) * 512)); // half size
|
||||
@@ -748,6 +748,9 @@ struct WaterCache {
|
||||
}
|
||||
|
||||
void renderRays() {
|
||||
#ifdef _OS_PSV // TODO
|
||||
return;
|
||||
#endif
|
||||
if (!visible) return;
|
||||
PROFILE_MARKER("WATER_RAYS");
|
||||
|
||||
|
@@ -1,6 +1,8 @@
|
||||
#ifdef __psp2__
|
||||
#define _GAPI_GXM
|
||||
#pragma pack_matrix( column_major )
|
||||
#else
|
||||
#define _GAPI_D3D9
|
||||
#endif
|
||||
|
||||
#define ALPHA_REF 0.5
|
||||
@@ -25,8 +27,8 @@ static const float3 SHADOW_TEXEL = float3(1.0 / SHADOW_SIZE, 1.0 / SHADOW_SIZE,
|
||||
#else
|
||||
#define FLAGS_REG b0
|
||||
#define FLAGS_TYPE bool4
|
||||
#define RGBA(c) (c).rgba
|
||||
#define RGB(c) (c).rgb
|
||||
#define RGBA(c) (c).bgra
|
||||
#define RGB(c) (c).bgr
|
||||
#define CLIP_PLANE
|
||||
#endif
|
||||
|
||||
@@ -101,13 +103,19 @@ float calcSpecular(float3 normal, float3 viewVec, float3 lightVec, float intensi
|
||||
|
||||
float calcCaustics(float3 coord, float3 n) {
|
||||
float2 cc = saturate((coord.xz - uRoomSize.xy) / uRoomSize.zw);
|
||||
return tex2Dlod(sReflect, float4(cc.x, 1.0 - cc.y, 0, 0)).x * max(0.0, -n.y);
|
||||
float2 border = 256.0 / uRoomSize.zw;
|
||||
float2 fade = smoothstep((float2)0.0, border, cc) * (1.0 - smoothstep(1.0 - border, 1.0, cc));
|
||||
return tex2Dlod(sReflect, float4(cc.x, 1.0 - cc.y, 0, 0)).x * max(0.0, -n.y) * fade.x * fade.y;
|
||||
}
|
||||
|
||||
float calcCausticsV(float3 coord) {
|
||||
return 0.5 + abs(sin(dot(coord.xyz, 1.0 / 1024.0) + uParam.x)) * 0.75;
|
||||
}
|
||||
|
||||
half3 calcNormalV(float2 tc, half base) {
|
||||
half dx = (half)tex2Dlod(sNormal, float4(tc.x + uTexParam.x, tc.y, 0, 0)).x - base;
|
||||
half dz = (half)tex2Dlod(sNormal, float4(tc.x, tc.y + uTexParam.y, 0, 0)).x - base;
|
||||
return normalize( half3(dx, 64.0 / (1024.0 * 8.0), dz) );
|
||||
half dz = (half)tex2Dlod(sNormal, float4(tc.x, tc.y - uTexParam.y, 0, 0)).x - base;
|
||||
return (half3)normalize( half3(dx, 64.0 / (1024.0 * 8.0), dz) );
|
||||
}
|
||||
|
||||
float3 calcNormalF(float2 tcR, float2 tcB, float base) {
|
||||
@@ -117,19 +125,24 @@ float3 calcNormalF(float2 tcR, float2 tcB, float base) {
|
||||
}
|
||||
|
||||
half calcFresnel(half VoH, half f0) {
|
||||
half f = pow(1.0 - VoH, 5.0);
|
||||
return f + f0 * (1.0f - f);
|
||||
half f = (half)pow(1.0 - VoH, 5.0);
|
||||
return f + f0 * (1.0h - f);
|
||||
}
|
||||
|
||||
void applyFogUW(inout float3 color, float3 coord, float waterFogDist) {
|
||||
void applyFogUW(inout float3 color, float3 coord, float waterFogDist, float waterColorDist) {
|
||||
float h = coord.y - uParam.y;
|
||||
float3 dir = uViewPos.xyz - coord.xyz;
|
||||
float dist;
|
||||
if (uViewPos.y < uParam.y)
|
||||
dist = abs((coord.y - uParam.y) / normalize(uViewPos.xyz - coord.xyz).y);
|
||||
else
|
||||
dist = length(uViewPos.xyz - coord.xyz);
|
||||
|
||||
if (uViewPos.y < uParam.y) {
|
||||
dist = abs(h / normalize(dir).y);
|
||||
} else {
|
||||
dist = length(dir);
|
||||
}
|
||||
|
||||
float fog = saturate(1.0 / exp(dist * waterFogDist));
|
||||
dist += coord.y - uParam.y;
|
||||
color.xyz *= lerp(float3(1.0, 1.0, 1.0), UNDERWATER_COLOR, clamp(dist * waterFogDist, 0.0, 2.0));
|
||||
dist += h;
|
||||
color.xyz *= lerp((float3)1.0, UNDERWATER_COLOR, clamp(dist * waterColorDist, 0.0, 2.0));
|
||||
color.xyz = lerp(UNDERWATER_COLOR * 0.2, color.xyz, fog);
|
||||
}
|
||||
|
||||
|
@@ -54,7 +54,7 @@ VS_OUTPUT main(VS_INPUT In) {
|
||||
light = max((float4)0.0, lum) * max((float4)0.0, (float4)1.0 - att);
|
||||
|
||||
#ifdef UNDERWATER
|
||||
light.x *= abs(sin(dot(Out.coord.xyz, 1.0 / 512.0) + uParam.x)) * 1.5 + 0.5;
|
||||
light.x *= calcCausticsV(Out.coord);
|
||||
Out.normal.w = 0.0;
|
||||
#else
|
||||
Out.normal.w = saturate(1.0 / exp(length(Out.viewVec.xyz)));
|
||||
@@ -86,7 +86,7 @@ VS_OUTPUT main(VS_INPUT In) {
|
||||
#else // PIXEL
|
||||
|
||||
float4 main(VS_OUTPUT In) : COLOR0 {
|
||||
float4 color = tex2D(sDiffuse, In.texCoord.xy / In.texCoord.zw);
|
||||
float4 color = RGBA(tex2D(sDiffuse, In.texCoord.xy / In.texCoord.zw));
|
||||
|
||||
#ifdef ALPHA_TEST
|
||||
clip(color.w - ALPHA_REF);
|
||||
@@ -130,7 +130,7 @@ float4 main(VS_OUTPUT In) : COLOR0 {
|
||||
specular *= (1.0 - uwSign);
|
||||
color.xyz += specular;
|
||||
|
||||
applyFogUW(color.xyz, In.coord, WATER_FOG_DIST * uwSign);
|
||||
applyFogUW(color.xyz, In.coord, WATER_FOG_DIST * uwSign, WATER_COLOR_DIST * uwSign);
|
||||
#else
|
||||
color.xyz += specular;
|
||||
applyFog(color.xyz, In.normal.w);
|
||||
|
@@ -37,7 +37,7 @@ VS_OUTPUT main(VS_INPUT In) {
|
||||
#else // PIXEL
|
||||
|
||||
float4 main(VS_OUTPUT In) : COLOR0 {
|
||||
float4 color = tex2D(sDiffuse, In.texCoord.xy / In.texCoord.zw);
|
||||
float4 color = RGBA(tex2D(sDiffuse, In.texCoord.xy / In.texCoord.zw));
|
||||
|
||||
#ifdef CLIP_PLANE
|
||||
clip(In.clipDist);
|
||||
|
@@ -40,7 +40,7 @@ VS_OUTPUT main(VS_INPUT In) {
|
||||
|
||||
float4 main(VS_OUTPUT In) : COLOR0 {
|
||||
float3 rv = reflect(-In.viewVec.xyz, In.normal.xyz);
|
||||
float4 color = texCUBE(sEnvironment, normalize(rv));
|
||||
float4 color = RGBA(texCUBE(sEnvironment, normalize(rv)));
|
||||
|
||||
#ifdef CLIP_PLANE
|
||||
clip(In.viewVec.w);
|
||||
|
@@ -50,7 +50,7 @@ VS_OUTPUT main(VS_INPUT In) {
|
||||
light = max((float4)0.0, lum) * max((float4)0.0, (float4)1.0 - att);
|
||||
|
||||
#ifdef UNDERWATER
|
||||
light.x *= abs(sin(dot(Out.coord.xyz, 1.0 / 512.0) + uParam.x)) * 1.5 + 0.5;
|
||||
light.x *= calcCausticsV(Out.coord);
|
||||
Out.normal.w = 0.0;
|
||||
#else
|
||||
float3 viewVec = (uViewPos.xyz - Out.coord) * uFogParams.w;
|
||||
@@ -82,7 +82,7 @@ VS_OUTPUT main(VS_INPUT In) {
|
||||
#else // PIXEL
|
||||
|
||||
float4 main(VS_OUTPUT In) : COLOR0 {
|
||||
float4 color = tex2D(sDiffuse, In.texCoord.xy / In.texCoord.zw);
|
||||
float4 color = RGBA(tex2D(sDiffuse, In.texCoord.xy / In.texCoord.zw));
|
||||
|
||||
#ifdef ALPHA_TEST
|
||||
clip(color.w - ALPHA_REF);
|
||||
@@ -117,7 +117,7 @@ float4 main(VS_OUTPUT In) : COLOR0 {
|
||||
color.xyz *= light;
|
||||
|
||||
#ifdef UNDERWATER
|
||||
applyFogUW(color.xyz, In.coord, WATER_FOG_DIST);
|
||||
applyFogUW(color.xyz, In.coord, WATER_FOG_DIST, WATER_COLOR_DIST);
|
||||
#else
|
||||
applyFog(color.xyz, In.normal.w);
|
||||
#endif
|
||||
|
@@ -72,7 +72,7 @@ VS_OUTPUT main(VS_INPUT In) {
|
||||
#else // PIXEL
|
||||
|
||||
float4 main(VS_OUTPUT In) : COLOR0 {
|
||||
float4 color = tex2D(sDiffuse, In.texCoord.xy);
|
||||
float4 color = RGBA(tex2D(sDiffuse, In.texCoord.xy));
|
||||
|
||||
#ifdef ALPHA_TEST
|
||||
clip(color.w - ALPHA_REF);
|
||||
@@ -95,7 +95,7 @@ float4 main(VS_OUTPUT In) : COLOR0 {
|
||||
color.xyz *= light;
|
||||
|
||||
#ifdef UNDERWATER
|
||||
applyFogUW(color.xyz, In.coord, WATER_FOG_DIST);
|
||||
applyFogUW(color.xyz, In.coord, WATER_FOG_DIST, WATER_COLOR_DIST);
|
||||
#else
|
||||
applyFog(color.xyz, In.normal.w);
|
||||
#endif
|
||||
|
@@ -357,7 +357,9 @@ uniform vec4 uFogParams;
|
||||
|
||||
float calcCaustics(vec3 n) {
|
||||
vec2 cc = clamp((vCoord.xz - uRoomSize.xy) / uRoomSize.zw, vec2(0.0), vec2(1.0));
|
||||
return texture2D(sReflect, cc).x * max(0.0, -n.y);
|
||||
vec2 border = vec2(256.0) / uRoomSize.zw;
|
||||
vec2 fade = smoothstep(vec2(0.0), border, cc) * (1.0 - smoothstep(vec2(1.0) - border, vec2(1.0), cc));
|
||||
return texture2D(sReflect, cc).x * max(0.0, -n.y) * fade.x * fade.y;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@@ -5,7 +5,7 @@ R"====(
|
||||
#endif
|
||||
|
||||
#define MAX_LIGHTS 4
|
||||
#define WATER_FOG_DIST (1.0 / (1024.0 * 6.0))
|
||||
#define WATER_FOG_DIST (1.0 / (6.0 * 1024.0))
|
||||
#define WATER_COLOR_DIST (1.0 / (2.0 * 1024.0))
|
||||
#define UNDERWATER_COLOR vec3(0.6, 0.9, 0.9)
|
||||
|
||||
|
@@ -2,7 +2,6 @@
|
||||
|
||||
struct VS_OUTPUT {
|
||||
float4 pos : POSITION;
|
||||
float2 texCoord : TEXCOORD0;
|
||||
float3 oldPos : TEXCOORD1;
|
||||
float3 newPos : TEXCOORD2;
|
||||
};
|
||||
@@ -25,8 +24,6 @@ VS_OUTPUT main(VS_INPUT In) {
|
||||
|
||||
float3 coord = In.aCoord.xyz * (1.0 / 32767.0);
|
||||
|
||||
Out.texCoord = getUV(coord.xy, uTexParam);
|
||||
|
||||
float3 rCoord = float3(coord.x, coord.y, 0.0) * uPosScale[1].xzy;
|
||||
|
||||
float2 uv = getInvUV(rCoord.xy, uTexParam).xy;
|
||||
@@ -35,7 +32,7 @@ VS_OUTPUT main(VS_INPUT In) {
|
||||
|
||||
float3 light = float3(0.0, 0.0, 1.0);
|
||||
float3 refOld = refract(-light, float3(0.0, 0.0, 1.0), 0.75);
|
||||
float3 refNew = refract(-light, normal, 0.75);
|
||||
float3 refNew = refract(-light, normalize(normal + float3(0.0, 0.0, 0.25)), 0.75);
|
||||
|
||||
Out.oldPos = rCoord + refOld * (-1.0 / refOld.z) + refOld * ((-refOld.z - 1.0) / refOld.z);
|
||||
Out.newPos = rCoord + refNew * ((info.r - 1.0) / refNew.z) + refOld * ((-refNew.z - 1.0) / refOld.z);
|
||||
|
@@ -32,9 +32,9 @@ VS_OUTPUT main(VS_INPUT In) {
|
||||
Out.viewVec.y = abs(Out.viewVec.y);
|
||||
Out.lightVec.y = abs(Out.lightVec.y);
|
||||
Out.lightVec = uLightPos[0].xyz - coord;
|
||||
|
||||
Out.viewVec.w = step(uPosScale[0].y, uViewPos.y) * WATER_COLOR_DIST;
|
||||
|
||||
|
||||
Out.viewVec.w = step(uPosScale[0].y, uViewPos.y);
|
||||
|
||||
Out.texCoordR = Out.texCoord + float2(uTexParam.x, 0.0);
|
||||
Out.texCoordB = Out.texCoord + float2(0.0, uTexParam.y);
|
||||
|
||||
@@ -68,9 +68,9 @@ half4 main(VS_OUTPUT In) : COLOR0 {
|
||||
color.xyz += specular;
|
||||
|
||||
float dist = (In.viewVec.y / viewVec.y) * In.viewVec.w;
|
||||
color.xyz *= lerp((half3)1.0, UNDERWATER_COLOR_H, (half)clamp(dist, 0.0, 2.0));
|
||||
color.xyz *= lerp((half3)1.0, UNDERWATER_COLOR_H, (half)clamp(dist * WATER_COLOR_DIST, 0.0, 2.0));
|
||||
|
||||
half fog = saturate(1.0h / exp(dist));
|
||||
half fog = saturate(1.0h / exp(dist * WATER_FOG_DIST));
|
||||
color.xyz = lerp(UNDERWATER_COLOR_H * 0.2, color.xyz, fog);
|
||||
|
||||
return color;
|
||||
|
@@ -2,13 +2,13 @@
|
||||
|
||||
struct VS_OUTPUT {
|
||||
float4 pos : POSITION;
|
||||
float2 texCoord : TEXCOORD0;
|
||||
half2 maskCoord : TEXCOORD1;
|
||||
float2 texCoordL : TEXCOORD2;
|
||||
float2 texCoordR : TEXCOORD3;
|
||||
float2 texCoordT : TEXCOORD4;
|
||||
float2 texCoordB : TEXCOORD5;
|
||||
half2 noiseCoord : TEXCOORD6;
|
||||
float2 texCoord : TEXCOORD0;
|
||||
half2 maskCoord : TEXCOORD1;
|
||||
float2 texCoordL : TEXCOORD2;
|
||||
float2 texCoordR : TEXCOORD3;
|
||||
float2 texCoordT : TEXCOORD4;
|
||||
float2 texCoordB : TEXCOORD5;
|
||||
half2 noiseCoord : TEXCOORD6;
|
||||
};
|
||||
|
||||
#ifdef VERTEX
|
||||
|
Reference in New Issue
Block a user