Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions assets/svencoop/renderer/shader/wsurf_shader.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,14 @@ vec2 ParallaxMapping(vec3 T, vec3 B, vec3 N, vec3 viewDirWorld, vec2 baseTexcoor

vec2 deltaTexCoords = p / numLayers;

vec2 mainTexCoods = baseTexcoord;
// Start at the top of the height field, with mid-gray on the surface plane.
const float referenceHeight = 0.5;
vec2 mainTexCoods = baseTexcoord + p * (1.0 - referenceHeight);

vec2 currentTexCoords = mainTexCoods;

vec2 ddx = dFdx(mainTexCoods);
vec2 ddy = dFdy(mainTexCoods);
vec2 ddx = dFdx(baseTexcoord);
vec2 ddy = dFdy(baseTexcoord);

float currentDepthMapValue = 1.0 - textureGrad(parallaxTex, vec2(currentTexCoords.x * v_parallaxtexcoord.x, currentTexCoords.y * v_parallaxtexcoord.y), ddx, ddy ).r;

Expand Down Expand Up @@ -207,18 +209,7 @@ vec2 ParallaxMapping(vec3 T, vec3 B, vec3 N, vec3 viewDirWorld, vec2 baseTexcoor

vec4 SampleDiffuseTexture(vec2 baseTexcoord)
{

#if defined(PARALLAXTEXTURE_ENABLED)

vec3 viewDir = normalize(v_worldpos.xyz - GetCameraViewPos(GetCameraViewIndex()));

vec4 diffuseColor = texture(diffuseTex, ParallaxMapping(v_tangent, v_bitangent, v_normal, viewDir, baseTexcoord));

#else

vec4 diffuseColor = texture(diffuseTex, baseTexcoord);

#endif
vec4 diffuseColor = texture(diffuseTex, baseTexcoord);

#if defined(DECAL_ENABLED)

Expand All @@ -242,6 +233,13 @@ void main()

vec2 baseTexcoord = v_diffusetexcoord.xy;

#if defined(PARALLAXTEXTURE_ENABLED)

vec3 viewDir = normalize(v_worldpos.xyz - GetCameraViewPos(GetCameraViewIndex()));
baseTexcoord = ParallaxMapping(v_tangent, v_bitangent, v_normal, viewDir, baseTexcoord);

#endif

#if defined(DIFFUSE_ENABLED)

vec4 diffuseColor = SampleDiffuseTexture(baseTexcoord);
Expand Down Expand Up @@ -356,9 +354,9 @@ void main()
#elif defined(GLOW_COLOR_ENABLED)

#if defined(ALPHA_SOLID_ENABLED)
vec4 diffuseColor = SampleDiffuseTexture(v_texcoord);
vec4 glowDiffuseColor = SampleDiffuseTexture(baseTexcoord);

if(diffuseColor.a < 0.5)
if(glowDiffuseColor.a < 0.5)
discard;
#endif

Expand Down
3 changes: 3 additions & 0 deletions docs/en/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ For decals: texture list is parsed from `{GameDirectory}/renderer/decal_textures
The rules of texture searching follow the same way as "BSP detail textures"

* `r_wsurf_parallax_scale` controls the intensity (and direction if negative value is given) of parallax textures.
* The red channel stores height, with `0.5` (mid-gray) as the zero-offset reference plane. With the default scale of `-0.02`, darker values appear recessed and brighter values appear raised. Changing the sign reverses this direction; a scale of `0` disables the offset.
* Diffuse, detail, normal and specular textures share the parallax-adjusted coordinates, with each texture's own UV scale applied afterward. Lightmap coordinates remain unchanged.
* Earlier versions used white (`1.0`) as the zero-offset reference. Custom height maps authored for that convention may need adjustment. The bundled `shot_parallax.dds` already uses a mid-gray background and a dark center.

### BSP specular textures

Expand Down
5 changes: 4 additions & 1 deletion docs/zh-CN/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,10 @@ SSAO (屏幕空间环境光遮蔽)是一种在后处理阶段为场景添加

列表中指定的视差贴图文件加载位置和加载顺序参考 "BSP细节贴图" 中的相关说明。

* 控制台参数 `r_wsurf_parallax_scale` 可以用于控制视差(凹陷/突起)效果的最大强度(果为负则改变凹陷/突起的方向)。
* 控制台参数 `r_wsurf_parallax_scale` 可以用于控制视差(凹陷/突起)效果的最大强度,改变正负号会反转凹陷/突起的方向。
* 视差贴图的红色通道表示高度,`0.5`(中灰)为零偏移基准。在默认强度 `-0.02` 下,较暗区域表现为凹陷,较亮区域表现为突起;强度设为 `0` 时不产生偏移。
* 基础贴图、细节贴图、法线贴图和高光贴图共享视差偏移后的坐标,再分别应用各自的 UV 缩放。光照贴图坐标保持不变。
* 旧版本以白色(`1.0`)为零偏移基准,按旧约定制作的自定义高度图可能需要调整。自带的 `shot_parallax.dds` 已使用中灰背景和深色中心。


### BSP高光贴图
Expand Down
8 changes: 8 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ add_test(NAME triapi_shader_tests COMMAND triapi_shader_tests
"${PROJECT_SOURCE_DIR}/assets/svencoop/renderer/shader")
set_tests_properties(triapi_shader_tests PROPERTIES SKIP_RETURN_CODE 2)

add_executable(wsurf_parallax_shader_tests wsurf_parallax_shader_tests.cpp)
target_compile_definitions(wsurf_parallax_shader_tests PRIVATE GLEW_STATIC GLFW_INCLUDE_NONE)
target_compile_options(wsurf_parallax_shader_tests PRIVATE /UNDEBUG)
target_link_libraries(wsurf_parallax_shader_tests PRIVATE renderer_settings libglew_static glfw)
add_test(NAME wsurf_parallax_shader_tests COMMAND wsurf_parallax_shader_tests
"${PROJECT_SOURCE_DIR}/assets/svencoop/renderer/shader")
set_tests_properties(wsurf_parallax_shader_tests PROPERTIES SKIP_RETURN_CODE 2 TIMEOUT 60)

# Real cs_assault geometry and lights, comparing cached depth with an uncached
# oracle on the GPU. No engine ABI stubs or test copies of the cache policy.
add_executable(gl_shadow_cache_tests gl_shadow_cache_tests.cpp "${TINYOBJLOADER_SOURCE_PATH}/tiny_obj_loader.cc")
Expand Down
Loading
Loading