diff --git a/data/WZPrebuiltPackages.cmake b/data/WZPrebuiltPackages.cmake index c973bf24353..8c8ea8ffccc 100644 --- a/data/WZPrebuiltPackages.cmake +++ b/data/WZPrebuiltPackages.cmake @@ -2,5 +2,5 @@ # Prebuilt package DL info # terrain_overrides/high.wz -set(WZ_PREBUILT_TERRAIN_HIGH_DL_URL "https://github.com/Warzone2100/data-terrain-high/releases/download/v1/high.wz") -set(WZ_PREBUILT_TERRAIN_HIGH_DL_SHA512 "44a39e585344b25ab0fa4ed769f2b48bf23a0e4fc4b23e0fab4e68643cc6e3ebeabba790e8b1e6c96493ad01b6a2f09e92b893063013077dcac2475f0b5373d6") +set(WZ_PREBUILT_TERRAIN_HIGH_DL_URL "https://github.com/Warzone2100/data-terrain-high/releases/download/v2/high.wz") +set(WZ_PREBUILT_TERRAIN_HIGH_DL_SHA512 "c96ee757c6771ed7cfd104bf4d86bf80a6ce9f1598a16bd26a711fcf2359ae7b13d3812d9cbe64ff6d1e9d55ed7f28c72a150e1c755cc595928f893029802570") diff --git a/data/base/shaders/terrain_water_high.frag b/data/base/shaders/terrain_water_high.frag index de18ea15fda..8be250bd951 100644 --- a/data/base/shaders/terrain_water_high.frag +++ b/data/base/shaders/terrain_water_high.frag @@ -54,26 +54,22 @@ vec4 main_bumpMapping() vec2 uv1 = uv1_uv2.xy; vec2 uv2 = uv1_uv2.zw; - vec3 N1 = texture2DArray(tex_nm, vec3(uv2, 0.f), WZ_MIP_LOAD_BIAS).xzy; // y is up in modelSpace - vec3 N2 = texture2DArray(tex_nm, vec3(uv1, 1.f), WZ_MIP_LOAD_BIAS).xzy; - //use overlay blending to mix normal maps properly - bvec3 computedN_select = lessThan(N1, vec3(0.5)); - vec3 computedN_multiply = 2.f * N1 * N2; - vec3 computedN_screen = vec3(1.f) - 2.f * (vec3(1.f) - N1) * (vec3(1.f) - N2); - vec3 N = mix(computedN_screen, computedN_multiply, vec3(computedN_select)); - - N = mix(normalize(N * 2.f - 1.f), vec3(0.f,1.f,0.f), vec3(float(N == vec3(0.f,0.f,0.f)))); - - float lambertTerm = max(dot(N, lightDir), 0.0); // diffuse lighting - - // Gaussian specular term computation - float gloss = texture2DArray(tex_sm, vec3(uv1, 0.f), WZ_MIP_LOAD_BIAS).r * texture2DArray(tex_sm, vec3(uv2, 1.f), WZ_MIP_LOAD_BIAS).r; - vec3 H = normalize(halfVec); - float exponent = acos(dot(H, N)) / (gloss + 0.05); - float gaussianTerm = exp(-(exponent * exponent)); - - vec4 fragColor = (texture2DArray(tex, vec3(uv1, 0.f), WZ_MIP_LOAD_BIAS)+texture2DArray(tex, vec3(uv2, 1.f), WZ_MIP_LOAD_BIAS)) * (gloss+vec4(0.08,0.13,0.15,1.0)); - fragColor = fragColor*(ambientLight+diffuseLight*lambertTerm) + specularLight*(1.0-gloss)*gaussianTerm*vec4(1.0,0.843,0.686,1.0); + vec3 N1 = texture2DArray(tex_nm, vec3(uv1, 0.f), WZ_MIP_LOAD_BIAS).xzy*vec3(2.f, 2.f, 2.f) + vec3(-1.f, 0.f, -1.f); // y is up in modelSpace + vec3 N2 = texture2DArray(tex_nm, vec3(uv2, 1.f), WZ_MIP_LOAD_BIAS).xzy*vec3(-2.f, 2.f,-2.f) + vec3(1.f, -1.f, 1.f); + + //use RNM blending to mix normal maps properly, see https://blog.selfshadow.com/publications/blending-in-detail/ + vec3 N = normalize(N1 * dot(N1,N2) - N2*N1.y); + + // Light + float noise = texture2DArray(tex, vec3(uv1, 0.f), WZ_MIP_LOAD_BIAS).r * texture2DArray(tex, vec3(uv2, 1.f), WZ_MIP_LOAD_BIAS).r; + float foam = texture2DArray(tex_sm, vec3(uv1, 0.f), WZ_MIP_LOAD_BIAS).r * texture2DArray(tex_sm, vec3(uv2, 1.f), WZ_MIP_LOAD_BIAS).r; + + float lambertTerm = max(dot(N, lightDir), 0.0); + float blinnTerm = pow(max(dot(N, halfVec), 0.0), 32.f); + + vec4 fragColor = vec4(0.16,0.26,0.3,1.0)+(noise+foam)*noise*0.5; + fragColor = fragColor*(ambientLight+diffuseLight*lambertTerm) + specularLight*blinnTerm*(foam*foam+noise); + vec4 lightmap_vec4 = texture(lightmap_tex, uvLightmap, 0.f); vec4 color = fragColor * vec4(vec3(lightmap_vec4.a), 1.f); // ... * tile brightness / ambient occlusion (stored in lightmap.a); color.rgb = blendAddEffectLighting(color.rgb, (lightmap_vec4.rgb / 1.5f)); // additive color (from environmental point lights / effects) @@ -83,8 +79,8 @@ vec4 main_bumpMapping() void main() { vec4 fragColor = main_bumpMapping(); - fragColor = mix(fragColor, fragColor-depth*0.0007, depth*0.0009); - fragColor.a = mix(0.25, 1.0, depth2*0.005); + fragColor = mix(fragColor, fragColor-depth, depth); + fragColor.a = mix(0.25, 1.0, depth2); if (fogEnabled > 0) { diff --git a/data/base/shaders/terrain_water_high.vert b/data/base/shaders/terrain_water_high.vert index 3759c9fbaec..8b7341561c7 100644 --- a/data/base/shaders/terrain_water_high.vert +++ b/data/base/shaders/terrain_water_high.vert @@ -37,8 +37,8 @@ VERTEX_OUTPUT vec3 halfVec; void main() { uvLightmap = (ModelUVLightmapMatrix * vec4(vertex.xyz, 1.f)).xy; - depth = vertex.w; - depth2 = length(vertex.y - vertex.w); + depth = vertex.w*0.0007; + depth2 = length(vertex.y - vertex.w)*0.005; vec2 uv1 = vec2(vertex.x/4.f/128.f + timeSec/80.f, -vertex.z/4.f/128.f + timeSec/40.f); // (ModelUV1Matrix * vertex).xy; vec2 uv2 = vec2(vertex.x/4.f/128.f, -vertex.z/4.f/128.f - timeSec/40.f); // (ModelUV2Matrix * vertex).xy; @@ -46,7 +46,7 @@ void main() vec3 eyeVec = normalize(cameraPos.xyz - vertex.xyz); lightDir = sunPos.xyz; - halfVec = lightDir + eyeVec; + halfVec = normalize(lightDir + eyeVec); vec4 position = ModelViewProjectionMatrix * vec4(vertex.xyz, 1.f); vertexDistance = position.z; diff --git a/data/base/shaders/vk/terrain_water_high.frag b/data/base/shaders/vk/terrain_water_high.frag index d0e02eae159..a6249c04a45 100644 --- a/data/base/shaders/vk/terrain_water_high.frag +++ b/data/base/shaders/vk/terrain_water_high.frag @@ -44,26 +44,22 @@ vec4 main_bumpMapping() vec2 uv1 = uv1_uv2.xy; vec2 uv2 = uv1_uv2.zw; - vec3 N1 = texture(tex_nm, vec3(uv2, 0.f), WZ_MIP_LOAD_BIAS).xzy; // y is up in modelSpace - vec3 N2 = texture(tex_nm, vec3(uv1, 1.f), WZ_MIP_LOAD_BIAS).xzy; - //use overlay blending to mix normal maps properly - bvec3 computedN_select = lessThan(N1, vec3(0.5)); - vec3 computedN_multiply = 2.f * N1 * N2; - vec3 computedN_screen = vec3(1.f) - 2.f * (vec3(1.f) - N1) * (vec3(1.f) - N2); - vec3 N = mix(computedN_screen, computedN_multiply, vec3(computedN_select)); - - N = mix(normalize(N * 2.f - 1.f), vec3(0.f,1.f,0.f), vec3(float(N == vec3(0.f,0.f,0.f)))); - - float lambertTerm = max(dot(N, lightDir), 0.0); // diffuse lighting - - // Gaussian specular term computation - float gloss = texture(tex_sm, vec3(uv1, 0.f), WZ_MIP_LOAD_BIAS).r * texture(tex_sm, vec3(uv2, 1.f), WZ_MIP_LOAD_BIAS).r; - vec3 H = normalize(halfVec); - float exponent = acos(dot(H, N)) / (gloss + 0.05); - float gaussianTerm = exp(-(exponent * exponent)); - - vec4 fragColor = (texture(tex, vec3(uv1, 0.f), WZ_MIP_LOAD_BIAS)+texture(tex, vec3(uv2, 1.f), WZ_MIP_LOAD_BIAS)) * (gloss+vec4(0.08,0.13,0.15,1.0)); - fragColor = fragColor*(ambientLight+diffuseLight*lambertTerm) + specularLight*(1.0-gloss)*gaussianTerm*vec4(1.0,0.843,0.686,1.0); + vec3 N1 = texture(tex_nm, vec3(uv1, 0.f), WZ_MIP_LOAD_BIAS).xzy*vec3(2.f, 2.f, 2.f) + vec3(-1.f, 0.f, -1.f); // y is up in modelSpace + vec3 N2 = texture(tex_nm, vec3(uv2, 1.f), WZ_MIP_LOAD_BIAS).xzy*vec3(-2.f, 2.f,-2.f) + vec3(1.f, -1.f, 1.f); + + //use RNM blending to mix normal maps properly, see https://blog.selfshadow.com/publications/blending-in-detail/ + vec3 N = normalize(N1 * dot(N1,N2) - N2*N1.y); + + // Light + float noise = texture(tex, vec3(uv1, 0.f), WZ_MIP_LOAD_BIAS).r * texture(tex, vec3(uv2, 1.f), WZ_MIP_LOAD_BIAS).r; + float foam = texture(tex_sm, vec3(uv1, 0.f), WZ_MIP_LOAD_BIAS).r * texture(tex_sm, vec3(uv2, 1.f), WZ_MIP_LOAD_BIAS).r; + + float lambertTerm = max(dot(N, lightDir), 0.0); + float blinnTerm = pow(max(dot(N, halfVec), 0.0), 32.f); + + vec4 fragColor = vec4(0.16,0.26,0.3,1.0)+(noise+foam)*noise*0.5; + fragColor = fragColor*(ambientLight+diffuseLight*lambertTerm) + specularLight*blinnTerm*(foam*foam+noise); + vec4 lightmap_vec4 = texture(lightmap_tex, uvLightmap, 0.f); vec4 color = fragColor * vec4(vec3(lightmap_vec4.a), 1.f); // ... * tile brightness / ambient occlusion (stored in lightmap.a); color.rgb = blendAddEffectLighting(color.rgb, (lightmap_vec4.rgb / 1.5f)); // additive color (from environmental point lights / effects) @@ -73,8 +69,8 @@ vec4 main_bumpMapping() void main() { vec4 fragColor = main_bumpMapping(); - fragColor = mix(fragColor, fragColor-depth*0.0007, depth*0.0009); - fragColor.a = mix(0.25, 1.0, depth2*0.005); + fragColor = mix(fragColor, fragColor-depth, depth); + fragColor.a = mix(0.25, 1.0, depth2); if (fogEnabled > 0) { diff --git a/data/base/shaders/vk/terrain_water_high.vert b/data/base/shaders/vk/terrain_water_high.vert index e0e0479ca98..14d8a4df136 100644 --- a/data/base/shaders/vk/terrain_water_high.vert +++ b/data/base/shaders/vk/terrain_water_high.vert @@ -31,8 +31,8 @@ layout(location = 7) out float depth2; void main() { uvLightmap = (ModelUVLightmapMatrix * vec4(vertex.xyz, 1.f)).xy; - depth = vertex.w; - depth2 = length(vertex.y - vertex.w); + depth = vertex.w*0.0007; + depth2 = length(vertex.y - vertex.w)*0.005; vec2 uv1 = vec2(vertex.x/4.f/128.f + timeSec/80.f, -vertex.z/4.f/128.f + timeSec/40.f); // (ModelUV1Matrix * vertex).xy; vec2 uv2 = vec2(vertex.x/4.f/128.f, -vertex.z/4.f/128.f - timeSec/40.f); // (ModelUV2Matrix * vertex).xy; @@ -40,7 +40,7 @@ void main() vec3 eyeVec = normalize(cameraPos.xyz - vertex.xyz); lightDir = sunPos.xyz; - halfVec = lightDir + eyeVec; + halfVec = normalize(lightDir + eyeVec); vec4 position = ModelViewProjectionMatrix * vec4(vertex.xyz, 1.f); vertexDistance = position.z; diff --git a/data/terrain_overrides/high b/data/terrain_overrides/high index ed6bef73723..67d4590fb62 160000 --- a/data/terrain_overrides/high +++ b/data/terrain_overrides/high @@ -1 +1 @@ -Subproject commit ed6bef73723070aba7f81e130a7bf97297a728a4 +Subproject commit 67d4590fb62eb60907a3cdc24f2aa112bebfb9f8