骑马与砍杀中文站论坛

 找回密码
 注册(Register!)

QQ登录

只需一步,快速开始

搜索
购买霸主CDKEY 购买战帆CDKEY
查看: 42606|回复: 22

[功能与代码] 【shaders】使用postFX.fx提升战团画质(战团重置版的核心)

[复制链接]

23

主题

339

回帖

299

积分

见习骑士

Rank: 3

UID
3189500
第纳尔
2709
精华
0
互助
26
荣誉
6
贡献
20
魅力
437
注册时间
2020-6-13
鲜花(68) 鸡蛋(0)
发表于 2023-2-17 21:35:24 | 显示全部楼层
这是我诱导chatgpt编写的添加模拟光追的代码,由于我还不太懂相关代码,请楼主看看是否经优化后可行,不妨分享出来
“首先,需要在shader文件中定义一些变量和函数来实现模拟光线追踪的效果。以下是一个简单的示例:”
  1. // 定义场景中的相机
  2. float4x4 view_matrix; // 相机观察矩阵
  3. float4x4 projection_matrix; // 相机投影矩阵

  4. // 定义光线追踪的变量
  5. float3 ray_origin; // 光线起点
  6. float3 ray_direction; // 光线方向
  7. float3 ray_color; // 光线颜色

  8. // 定义光线追踪的函数
  9. float3 TraceRay(float3 ray_origin, float3 ray_direction, int depth)
  10. {
  11.     // 计算光线与场景中物体的交点
  12.     float t = 10000.0; // 初始最大距离
  13.     float3 hit_point = ray_origin;
  14.     float3 hit_normal = 0;
  15.     for (int i = 0; i < num_objects; i++) {
  16.         float t_obj = Intersect(ray_origin, ray_direction, objects[i]);
  17.         if (t_obj > 0 && t_obj < t) {
  18.             t = t_obj;
  19.             hit_point = ray_origin + ray_direction * t;
  20.             hit_normal = CalculateNormal(hit_point, objects[i]);
  21.         }
  22.     }

  23.     // 计算光线的颜色
  24.     if (t < 10000.0) { // 有交点
  25.         // 添加光照效果
  26.         float3 diffuse_color = 0;
  27.         for (int i = 0; i < num_lights; i++) {
  28.             float3 light_direction = Normalize(lights[i].position - hit_point);
  29.             float ndotl = dot(hit_normal, light_direction);
  30.             if (ndotl > 0) {
  31.                 float3 shadow_ray_direction = light_direction;
  32.                 float shadow_t = Intersect(hit_point, shadow_ray_direction, objects);
  33.                 if (shadow_t > 0 && shadow_t < Length(lights[i].position - hit_point)) {
  34.                     ndotl = 0; // 有阴影
  35.                 }
  36.             }
  37.             diffuse_color += lights[i].color * ndotl;
  38.         }
  39.         float3 ambient_color = ambient_intensity * ambient_color;
  40.         ray_color = diffuse_color + ambient_color;
  41.     } else { // 没有交点
  42.         ray_color = background_color;
  43.     }

  44.     // 添加反射效果
  45.     if (depth > 0 && reflection_intensity > 0) {
  46.         float3 reflected_direction = Normalize(ray_direction - 2 * dot(ray_direction, hit_normal) * hit_normal);
  47.         float3 reflected_color = TraceRay(hit_point, reflected_direction, depth - 1);
  48.         ray_color = Lerp(ray_color, reflected_color, reflection_intensity);
  49.     }

  50.     return ray_color;
  51. }
复制代码
“接下来就是在像素着色器函数中调用这个光线追踪函数,获取每个像素的颜色值。下面是一个简单的示例:”
  1. float4 PS(VertexShaderOutput input) : SV_Target
  2. {
  3.     float3 rayDirection = normalize(input.worldPosition - cameraPosition); // 计算光线方向
  4.     float3 color = TraceRay(input.worldPosition, rayDirection, 0); // 调用光线追踪函数获取颜色值
  5.     return float4(color, 1.0f); // 返回颜色值
  6. }
复制代码



B站个人空间:https://b23.tv/rZhCYpH

23

主题

339

回帖

299

积分

见习骑士

Rank: 3

UID
3189500
第纳尔
2709
精华
0
互助
26
荣誉
6
贡献
20
魅力
437
注册时间
2020-6-13
鲜花(68) 鸡蛋(0)
发表于 2023-2-22 14:12:20 | 显示全部楼层
楼主有进展吗??
B站个人空间:https://b23.tv/rZhCYpH

23

主题

339

回帖

299

积分

见习骑士

Rank: 3

UID
3189500
第纳尔
2709
精华
0
互助
26
荣誉
6
贡献
20
魅力
437
注册时间
2020-6-13
鲜花(68) 鸡蛋(0)
发表于 2023-4-7 21:12:01 | 显示全部楼层
fengguoyehao 发表于 2023-4-7 20:25
这个代码太不完整了,我的能力有限,目前没有办法写入骑砍postFX.fx

postFX.txt (31.57 KB, 下载次数: 509) 由于帖子限制,我改了后缀。
可以看看我根据Reshade插件Glamarye_Fast_Effects和_Sebastian_写的ssao代码改的,你下载看看效果如何。不知道为啥在WSE2无效,所以我的mod还是用的reshade

鲜花鸡蛋

fengguoyehao  在2023-4-7 22:49  送朵鲜花  并说:太强了!
fengguoyehao  在2023-4-7 22:47  送朵鲜花  并说:我非常同意你的观点,送朵鲜花鼓励一下
fengguoyehao  在2023-4-7 22:46  送朵鲜花  并说:我非常同意你的观点,送朵鲜花鼓励一下
B站个人空间:https://b23.tv/rZhCYpH

23

主题

339

回帖

299

积分

见习骑士

Rank: 3

UID
3189500
第纳尔
2709
精华
0
互助
26
荣誉
6
贡献
20
魅力
437
注册时间
2020-6-13
鲜花(68) 鸡蛋(0)
发表于 2023-4-7 23:25:20 | 显示全部楼层
fengguoyehao 发表于 2023-4-7 22:44
太强了!请问你是怎么把这个需要获取深度信息的fx成功移植进骑砍的postFX.fx的?我到现在只会移植一些如T ...

获取深度的代码是官网论坛上的,但是移植Reshader的Fake GI的时候用的sampler我是一个个试的,不知道行不行。但是SSAO是肯定行的
B站个人空间:https://b23.tv/rZhCYpH

23

主题

339

回帖

299

积分

见习骑士

Rank: 3

UID
3189500
第纳尔
2709
精华
0
互助
26
荣誉
6
贡献
20
魅力
437
注册时间
2020-6-13
鲜花(68) 鸡蛋(0)
发表于 2023-4-7 23:27:36 | 显示全部楼层
fengguoyehao 发表于 2023-4-7 23:11
屏幕空间光线追踪全局光照:https://bbs.mountblade.com.cn/thread-2043687-1-1.html
去年我与这个帖子 ...

我用过RTGI,虽然效果很好,但是性能骤降。移植估计够呛,太过复杂
B站个人空间:https://b23.tv/rZhCYpH

23

主题

339

回帖

299

积分

见习骑士

Rank: 3

UID
3189500
第纳尔
2709
精华
0
互助
26
荣誉
6
贡献
20
魅力
437
注册时间
2020-6-13
鲜花(68) 鸡蛋(0)
发表于 2023-4-7 23:50:38 | 显示全部楼层
fengguoyehao 发表于 2023-4-7 23:33
我有一个远景模糊的fx,一直想移植,但却一直没有成功,我一直无法获取深度信息。请问可以帮我看一下 ...

稍微改良了一下景深效果 - MOD制作资料区 - 骑马与砍杀中文站论坛 - Powered by Discuz! (mountblade.com.cn)
要不你看看这个?
B站个人空间:https://b23.tv/rZhCYpH
您需要登录后才可以回帖 登录 | 注册(Register!)

本版积分规则

Archiver|手机版|小黑屋|骑马与砍杀中文站

GMT+8, 2025-12-14 20:50 , Processed in 0.081015 second(s), 20 queries , Gzip On, MemCached On.

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表