骑马与砍杀中文站论坛

 找回密码
 注册(Register!)

QQ登录

只需一步,快速开始

搜索
查看: 918|回复: 5

[功能与代码] 【战团】闪电枪?闪电枪!会闪,会动的着色器效果 及讲解

[复制链接]

31

主题

200

回帖

184

积分

见习骑士

Rank: 3

UID
2462463
第纳尔
1572
精华
0
互助
23
荣誉
0
贡献
0
魅力
80
注册时间
2015-3-3
鲜花(55) 鸡蛋(0)
发表于 2024-5-15 01:48:24 | 显示全部楼层 |阅读模式
本帖最后由 战争傀儡阿格兰 于 2024-5-15 02:00 编辑

代码环境1.171
【战团】阿格兰魔球修改器——合集https://bbs.mountblade.com.cn/thread-2097734-1-1.html

很久没发帖子了。一方面是我觉得要修改的地方已经改完了。另一方面是最近沉迷研究着色器语言HLSL。

代码实际效果:
投掷武器,效果见视频


注:闪电是着色器效果,采用拿破仑着色器作为底子。一方面是开源,另一方面是因为兼容性高。这个着色器的缺点,是火把等光源,没有照亮功能。如果你的mod,有除了postfx.fx以外任何fx、fxo这种带fx字样的文件,那都是冲突的。即,只和postfx.fx共存。

代码使用方式:解压缩,然后魔球“工具-物品导入向导”。再之后mb.fx文件,复制到mod根文件夹,就是main.bmp所在的文件夹。
注:替换投掷石子动作为投掷标枪,如果魔球导入后,动作替换失败,在module.ini文件把“load_mod_resource = lightningspear”剪切到第一行复制



游客,如果您要查看本帖隐藏内容请回复


——————————以下是源码——————————

●这次没有ms码了,是着色器HLSL语言中的代码了。

讲下骑马与砍杀战团的着色器的【实战经验】
333.png
第一讲【文件组成】
      除了特殊的postfx.fx文件,其余文件就这么多。就是这么几个简单的文件,不要学霸王奉先“可编程渲染管线shader编程基础环境搭建”,堆叠名词,网上东抄西抄,半点shader都没写出来,啥也不懂就在那里装x,没有可操作性,更加不可能带来实际效果。

第二讲【mb.fx及其源码】
     mb_source.fx是源码,使用HLSL语言。根据专业人士@zz010606的研究,跟C语言类似。使用bat文件后,编译出来的mb.fx文件就是着色器文件了。mb.fx和mb_a,mb_b等各种都是同一个东西,通过优化bat文件,整合后只需出一个,编译后的fx文件。

    注:该步骤没有反编译的可能性。删除源码就能保留技术了。


第三讲【postfx.fx及其特点】
      另外有个postfx.fx文件,这次我没提供。各大mod都有这个,我提供了反而冲突了。这个是也是着色器的一部分,和上述mb.fx的区别是:1、postfx.fx可以直接编辑,无需编译。2、骑砍MS代码中的set_shader_param_int ,set_shader_param_float,set_shader_param_float4,set_shader_param_float4x4 这四个代码,只能发送到mb.fx,不能发送到postfx.fx。

    注:直接在mb.fx里定义好"float aaa = 0.0f;"后,在MS里使用(set_shader_param_float, "@aaa", -2),就能传递过去,实时变化。这就是很多mod,汉化后,着色器失效的原因。汉化后,传递过去的就是中文了,mb.fx就不认识了。

第四讲【实战】
      什么?你问中间的步骤呢?参考m大(弃坑)、九章(弃坑且忘光)、@武安apk43(活跃中)等人的教学贴。我这里都是对他们的补充,实战后的补充。
      想要入门着色器的改编,最重要的就是看懂结构,去抄,去改。如果你是空降过来的HLSL大佬,你肯定就是自己写了。比方我的代码, VertexShader = vs_font_compiled_2_0这个是任何着色器都会有的部分,我就没动。我增加了PS部分,并在定义“技术”(technique lightning_12345)的时候,引用了我新增的技术。
      我选择这一段,是告诉各位,brf里贴图槽12345,并不是固定好了高光就是高光,法线就是法线。这是我新手时期最大的困惑。理解了这一点,才能更好入门。
      WSE2虽然让你加了个什么代码兼容,但是实际上会影响你着色器效果,属于流氓干涉行为。个人建议想要搞好着色器,就不要碰WSE2。
      看不懂的地方,找ai问。因为和C语言类似,所以ai识别率较高。
      如果你想问有没有函数表?不好意思,没人整理,只能靠猜。比方rand系列这种生成随机数的函数,不好意思,hlsl不支持。随机数的话,我是ms生成随机数后,发送给mb.fx。变相解决。



找到PS_OUTPUT ps_no_shading_no_alpha这句及紧跟的大括号,找到大括号结尾,另起一行:
//agland
PS_OUTPUT ps_lightning_1(VS_OUTPUT_FONT_X In)
{
        PS_OUTPUT Output;

    float offsetX = 1.25;
    float offsetY = 4.5;
    float slideTime = time_var * 19.3;
        
    float mix1 = clamp(exp(2.0 * sin(slideTime)) - offsetY, 0.0 , 1.0);

    float mix2 = clamp(exp(2.0 * sin(slideTime - offsetX)) - offsetY, 0.0 , 1.0);
   
    float mix3 = clamp(exp(2.0 * sin(slideTime - offsetX * 2.0)) - offsetY, 0.0 , 1.0);
   
    float mix4 = clamp(exp(2.0 * sin(slideTime - offsetX* 3.0)) - offsetY, 0.0 , 1.0);

    float mix5 = clamp(exp(2.0 * sin(slideTime - offsetX* 4.0)) - offsetY, 0.0 , 1.0);
        
        float4 tex_col = tex2D(MeshTextureSampler, In.Tex0)* mix1;
        float4 tex_col2 = tex2D(Diffuse2Sampler, In.Tex0)* mix2;
        float4 tex_col3 = tex2D(NormalTextureSampler, In.Tex0)* mix3;
        float4 tex_col4 = tex2D(EnvTextureSampler, In.Tex0)* mix4;
        //float4 tex_col4 = tex2D(Diffuse2Sampler, In.Tex0)* mix4;
        float4 tex_col5 = tex2D(SpecularTextureSampler, In.Tex0)* mix5;        

        tex_col = tex_col + tex_col2 + tex_col3 + tex_col4 + tex_col5;        

        INPUT_TEX_GAMMA(tex_col.rgb);
        Output.RGBColor =  In.Color * tex_col;
        OUTPUT_GAMMA(Output.RGBColor.rgb);
        return Output;
}
PS_OUTPUT ps_lightning_2(VS_OUTPUT_FONT_X In)
{
        PS_OUTPUT Output;

    float offsetX = 1.25;
    float offsetY = 4.5;
        
    float slideTime = time_var * 18.1;
        
    float mix1 = clamp(exp(2.0 * sin(slideTime)) - offsetY, 0.0 , 1.0);

    float mix2 = clamp(exp(2.0 * sin(slideTime - offsetX)) - offsetY, 0.0 , 1.0);
   
    float mix3 = clamp(exp(2.0 * sin(slideTime - offsetX * 2.0)) - offsetY, 0.0 , 1.0);
   
    float mix4 = clamp(exp(2.0 * sin(slideTime - offsetX* 3.0)) - offsetY, 0.0 , 1.0);

    float mix5 = clamp(exp(2.0 * sin(slideTime - offsetX* 4.0)) - offsetY, 0.0 , 1.0);
        
        float4 tex_col = tex2D(MeshTextureSampler, In.Tex0)* mix1;
        float4 tex_col2 = tex2D(Diffuse2Sampler, In.Tex0)* mix2;
        float4 tex_col3 = tex2D(NormalTextureSampler, In.Tex0)* mix3;
        float4 tex_col4 = tex2D(EnvTextureSampler, In.Tex0)* mix4;
        //float4 tex_col4 = tex2D(Diffuse2Sampler, In.Tex0)* mix4;
        float4 tex_col5 = tex2D(SpecularTextureSampler, In.Tex0)* mix5;        

        tex_col = tex_col + tex_col2 + tex_col3 + tex_col4 + tex_col5;        

        INPUT_TEX_GAMMA(tex_col.rgb);
        Output.RGBColor =  In.Color * tex_col;
        OUTPUT_GAMMA(Output.RGBColor.rgb);
        return Output;
}PS_OUTPUT ps_lightning_3(VS_OUTPUT_FONT_X In)
{
        PS_OUTPUT Output;

    float offsetX = 1.25;
    float offsetY = 4.5;
    float slideTime = time_var * 20.2;
        
    float mix1 = clamp(exp(2.0 * sin(slideTime)) - offsetY, 0.0 , 1.0);

    float mix2 = clamp(exp(2.0 * sin(slideTime - offsetX)) - offsetY, 0.0 , 1.0);
   
    float mix3 = clamp(exp(2.0 * sin(slideTime - offsetX * 2.0)) - offsetY, 0.0 , 1.0);
   
    float mix4 = clamp(exp(2.0 * sin(slideTime - offsetX* 3.0)) - offsetY, 0.0 , 1.0);

    float mix5 = clamp(exp(2.0 * sin(slideTime - offsetX* 4.0)) - offsetY, 0.0 , 1.0);
        
        float4 tex_col = tex2D(MeshTextureSampler, In.Tex0)* mix1;
        float4 tex_col2 = tex2D(Diffuse2Sampler, In.Tex0)* mix2;
        float4 tex_col3 = tex2D(NormalTextureSampler, In.Tex0)* mix3;
        float4 tex_col4 = tex2D(EnvTextureSampler, In.Tex0)* mix4;
        //float4 tex_col4 = tex2D(Diffuse2Sampler, In.Tex0)* mix4;
        float4 tex_col5 = tex2D(SpecularTextureSampler, In.Tex0)* mix5;        

        tex_col = tex_col + tex_col2 + tex_col3 + tex_col4 + tex_col5;        

        INPUT_TEX_GAMMA(tex_col.rgb);
        Output.RGBColor =  In.Color * tex_col;
        OUTPUT_GAMMA(Output.RGBColor.rgb);
        return Output;
}PS_OUTPUT ps_lightning_4(VS_OUTPUT_FONT_X In)
{
        PS_OUTPUT Output;

    float offsetX = 1.25;
    float offsetY = 4.5;
    float slideTime = time_var * 14.9;
        
    float mix1 = clamp(exp(2.0 * sin(slideTime)) - offsetY, 0.0 , 1.0);

    float mix2 = clamp(exp(2.0 * sin(slideTime - offsetX)) - offsetY, 0.0 , 1.0);
   
    float mix3 = clamp(exp(2.0 * sin(slideTime - offsetX * 2.0)) - offsetY, 0.0 , 1.0);
   
    float mix4 = clamp(exp(2.0 * sin(slideTime - offsetX* 3.0)) - offsetY, 0.0 , 1.0);

    float mix5 = clamp(exp(2.0 * sin(slideTime - offsetX* 4.0)) - offsetY, 0.0 , 1.0);
        
        float4 tex_col = tex2D(MeshTextureSampler, In.Tex0)* mix1;
        float4 tex_col2 = tex2D(Diffuse2Sampler, In.Tex0)* mix2;
        float4 tex_col3 = tex2D(NormalTextureSampler, In.Tex0)* mix3;
        //float4 tex_col4 = tex2D(EnvTextureSampler, In.Tex0)* mix4;
        float4 tex_col4 = tex2D(Diffuse2Sampler, In.Tex0)* mix4;
        float4 tex_col5 = tex2D(SpecularTextureSampler, In.Tex0)* mix5;        

        tex_col = tex_col + tex_col2 + tex_col3 + tex_col4 + tex_col5;        

        INPUT_TEX_GAMMA(tex_col.rgb);
        Output.RGBColor =  In.Color * tex_col;
        OUTPUT_GAMMA(Output.RGBColor.rgb);
        return Output;
}PS_OUTPUT ps_lightning_5(VS_OUTPUT_FONT_X In)
{
        PS_OUTPUT Output;

    float offsetX = 1.25;
    float offsetY = 4.5;
    float slideTime = time_var * 15.4;
        
    float mix1 = clamp(exp(2.0 * sin(slideTime)) - offsetY, 0.0 , 1.0);

    float mix2 = clamp(exp(2.0 * sin(slideTime - offsetX)) - offsetY, 0.0 , 1.0);
   
    float mix3 = clamp(exp(2.0 * sin(slideTime - offsetX * 2.0)) - offsetY, 0.0 , 1.0);
   
    float mix4 = clamp(exp(2.0 * sin(slideTime - offsetX* 3.0)) - offsetY, 0.0 , 1.0);

    float mix5 = clamp(exp(2.0 * sin(slideTime - offsetX* 4.0)) - offsetY, 0.0 , 1.0);
        
        float4 tex_col = tex2D(MeshTextureSampler, In.Tex0)* mix1;
        float4 tex_col2 = tex2D(Diffuse2Sampler, In.Tex0)* mix2;
        float4 tex_col3 = tex2D(NormalTextureSampler, In.Tex0)* mix3;
        //float4 tex_col4 = tex2D(EnvTextureSampler, In.Tex0)* mix4;
        float4 tex_col4 = tex2D(Diffuse2Sampler, In.Tex0)* mix4;
        float4 tex_col5 = tex2D(SpecularTextureSampler, In.Tex0)* mix5;        

        tex_col = tex_col + tex_col2 + tex_col3 + tex_col4 + tex_col5;        

        INPUT_TEX_GAMMA(tex_col.rgb);
        Output.RGBColor =  In.Color * tex_col;
        OUTPUT_GAMMA(Output.RGBColor.rgb);
        return Output;
}

technique lightning_1
{
        pass P0
        {
                VertexShader = vs_font_compiled_2_0;
                PixelShader = compile ps_2_0 ps_lightning_1();
        }
}
technique lightning_2
{
        pass P0
        {
                VertexShader = vs_font_compiled_2_0;
                PixelShader = compile ps_2_0 ps_lightning_2();
        }
}
technique lightning_3
{
        pass P0
        {
                VertexShader = vs_font_compiled_2_0;
                PixelShader = compile ps_2_0 ps_lightning_3();
        }
}
technique lightning_4
{
        pass P0
        {
                VertexShader = vs_font_compiled_2_0;
                PixelShader = compile ps_2_0 ps_lightning_4();
        }
}
technique lightning_5
{
        pass P0
        {
                VertexShader = vs_font_compiled_2_0;
                PixelShader = compile ps_2_0 ps_lightning_5();
        }
}

//agland



评分

参与人数 2第纳尔 +40 互助 +3 魅力 +30 收起 理由
幼稚园殺手 + 20 + 2 + 10 您的帖子很有价值!
Aomine Daiki + 20 + 1 + 20 您的帖子很有价值!

查看全部评分

鲜花鸡蛋

ggfgfgf  在2024-5-18 13:56  送朵鲜花  并说:我非常同意你的观点,送朵鲜花鼓励一下
ggfgfgf  在2024-5-18 13:56  送朵鲜花  并说:我非常同意你的观点,送朵鲜花鼓励一下
幼稚园殺手  在2024-5-18 13:34  送朵鲜花  并说:我非常同意你的观点,送朵鲜花鼓励一下
幼稚园殺手  在2024-5-18 13:34  送朵鲜花  并说:我非常同意你的观点,送朵鲜花鼓励一下
huagao  在2024-5-15 19:27  送朵鲜花  并说:我非常同意你的观点,送朵鲜花鼓励一下
路过的罗格  在2024-5-15 13:35  送朵鲜花  并说:我非常同意你的观点,送朵鲜花鼓励一下
815208129  在2024-5-15 13:06  送朵鲜花  并说:我非常同意你的观点,送朵鲜花鼓励一下
815208129  在2024-5-15 13:06  送朵鲜花  并说:我非常同意你的观点,送朵鲜花鼓励一下
815208129  在2024-5-15 13:06  送朵鲜花  并说:我非常同意你的观点,送朵鲜花鼓励一下
815208129  在2024-5-15 13:06  送朵鲜花  并说:我非常同意你的观点,送朵鲜花鼓励一下

16

主题

591

回帖

327

积分

见习骑士

Rank: 3

UID
3102512
第纳尔
2370
精华
0
互助
29
荣誉
0
贡献
0
魅力
63
注册时间
2019-9-6

骑砍中文站APP会员勋章战团正版勋章霸主正版勋章

鲜花(51) 鸡蛋(0)
发表于 2024-5-15 12:29:24 来自手机 | 显示全部楼层
给劲       来自: Android客户端

23

主题

335

回帖

267

积分

见习骑士

Rank: 3

UID
3189500
第纳尔
2549
精华
0
互助
24
荣誉
4
贡献
10
魅力
235
注册时间
2020-6-13
鲜花(66) 鸡蛋(0)
发表于 2024-5-15 18:18:45 来自手机 | 显示全部楼层
可以啊阿格兰,期待更多骚操作来自: Android客户端

3

主题

115

回帖

115

积分

见习骑士

Rank: 3

UID
3500189
第纳尔
780
精华
0
互助
14
荣誉
1
贡献
10
魅力
235
注册时间
2023-3-30
鲜花(40) 鸡蛋(0)
发表于 2024-5-15 18:44:55 | 显示全部楼层
WSE2属于流氓干涉行为,我十分赞同这句话。

4

主题

16

回帖

6

积分

平民

Rank: 1

UID
3559852
第纳尔
10
精华
0
互助
0
荣誉
0
贡献
0
魅力
0
注册时间
2023-9-9
鲜花(0) 鸡蛋(0)
发表于 2024-5-16 10:34:19 来自手机 | 显示全部楼层
这个效果很帅!!!!来自: iPhone客户端

0

主题

22

回帖

7

积分

平民

Rank: 1

UID
3284052
第纳尔
467
精华
0
互助
0
荣誉
0
贡献
0
魅力
0
注册时间
2021-11-3

骑砍中文站APP会员勋章

鲜花(10) 鸡蛋(0)
发表于 2024-5-16 12:51:35 来自手机 | 显示全部楼层
很棒,学习了来自: Android客户端
您需要登录后才可以回帖 登录 | 注册(Register!)

本版积分规则

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

GMT+8, 2024-5-29 12:29 , Processed in 0.517308 second(s), 31 queries , Gzip On, MemCached On.

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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