gpt4 book ai didi

ios - 为shader添加bloom(发光)效果(Unity游戏引擎)

转载 作者:可可西里 更新时间:2023-11-01 04:33:15 34 4
gpt4 key购买 nike

我正在 Unity game engine 中创建 iOS 应用 .

我正在尝试重写我的着色器,以便使用它的 Material >绽放(发光)效果(如 Halo component )。

一个示例它的外观:

Bloom (Glow) effect

enter image description here

我真的在互联网上搜索了答案,但没有找到任何适合工作人员或适合我的问题的解决方案。

我的着色器的代码:

Shader "Unlit"
{
Properties
{
_MainTex("Base (RGB) Trans (A)", 2D) = "white" {}
_Color("Main Color", Color) = (1, 1, 1, 1)
}
SubShader
{
Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
LOD 100
Cull off
ZWrite on
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
Lighting Off
SetTexture[_MainTex]
{
constantColor[_Color]
Combine texture * constant, texture * constant
}
}
}
}

最佳答案

着色器程序只是用于在屏幕上绘制三角形的代码。绽放效果是完全不同的野兽,and are screen-space calculations that are done after the geometry is drawn .仅通过修改对象的着色器不会获得光晕效果。

简单地说,使用着色器您永远无法绘制“线外”,此时您需要更改对象无法触及的像素。抱歉,这不在着色器的能力范围内。

不过,您可以通过实现 Image Effect 使其工作脚本,比如 unity 的 built-in bloom effect .将脚本添加到相机并激活相机的 HDR 设置后,您可以使用特殊的着色器来产生光晕,但在此之前不能。

正确设置效果(并在相机上启用 HDR 选项)后,您现在可以使用像素着色器中返回值大于 1 的任何着色器在对象周围生成发光效果。您发布的着色器是旧版着色器程序。这是更新后的代码,其中包含一个 Glow 倍增器:

Shader "Glow" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
_Color ("Color", Color) = (1,1,1,1)
_Glow ("Intensity", Range(0, 3)) = 1
}
SubShader {
Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
LOD 100
Cull Off
ZWrite On
Blend SrcAlpha OneMinusSrcAlpha

Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag

sampler2D _MainTex;
half4 _MainTex_ST;
fixed4 _Color;
half _Glow;

struct vertIn {
float4 pos : POSITION;
half2 tex : TEXCOORD0;
};

struct v2f {
float4 pos : SV_POSITION;
half2 tex : TEXCOORD0;
};

v2f vert (vertIn v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.pos);
o.tex = v.tex * _MainTex_ST.xy + _MainTex_ST.zw;
return o;
}

fixed4 frag (v2f f) : SV_Target {
fixed4 col = tex2D(_MainTex, f.tex);
col *= _Color;
col *= _Glow;
return col;
}
ENDCG
}
}
}

关于ios - 为shader添加bloom(发光)效果(Unity游戏引擎),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38541925/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com