unity 太阳自发光_unity自发光透明shader

这篇博客介绍了如何使用Unity中的Shader实现物体自发光和透明效果。通过调整Shader属性,可以控制物体的主颜色、发光颜色、光泽度以及透明度。示例代码包括了自发光透明的Shader实现,适用于玻璃等材质效果。
摘要由CSDN通过智能技术生成

这本来是一个glass的shader,但是我发现也可以用到自发光+透明,这两个脚本都是unity文档里面的。呵呵~~~

Shader "Custom/AlphaSelfIllum" {

Properties {

_Color ("Main Color", Color) = (1,1,1,0)

_SpecColor ("Spec Color", Color) = (1,1,1,1)

_Emission ("Emmisive Color", Color) = (0,0,0,0)

_Shininess ("Shininess", Range (0.01, 1)) = 0.7

_MainTex ("Base (RGB)", 2D) = "white" { }

}

SubShader {

// We use the material in many passes by defining them in the subshader.

// Anything defined here becomes default values for all contained passes.

Material {

Diffuse [_Color]

Ambient [_Color]

Shininess [_Shininess]

Specular [_SpecColor]

Emission [_Emission]

}

Lighting On

SeparateSpecular On

// Set up alpha blending

Blend SrcAlpha OneMinusSrcAlpha

// Render the back facing parts of the object.

// If the object is convex, these will always be further away

// than the front-faces.

//控制前面透明度

//Pass {

//    Cull Front

//    SetTexture [_MainTex] {

//        Combine Primary * Texture

//    }

//}

// Render the parts of the object facing us.

// If the object is convex, these will be closer than the

// back-faces.

//控制后面透明度

Pass {

Cull Back

SetTexture [_MainTex] {

Combine Primary * Texture

}

}

}

}

Shader "Custom/AlphaSelfIllum" {

Properties {

_Color ("Main Color", Color) = (1,1,1,0)

_SpecColor ("Spec Color", Color) = (1,1,1,1)

_Emission ("Emmisive Color", Color) = (0,0,0,0)

_Shininess ("Shininess", Range (0.01, 1)) = 0.7

_MainTex ("Base (RGB)", 2D) = "white" { }

}

SubShader {

// We use the material in many passes by defining them in the subshader.

// Anything defined here becomes default values for all contained passes.

Material {

Diffuse [_Color]

Ambient [_Color]

Shininess [_Shininess]

Specular [_SpecColor]

Emission [_Emission]

}

Lighting On

SeparateSpecular On

// Set up alpha blending

Blend SrcAlpha OneMinusSrcAlpha

// Render the back facing parts of the object.

// If the object is convex, these will always be further away

// than the front-faces.

//控制前面透明度

//Pass {

// Cull Front

// SetTexture [_MainTex] {

// Combine Primary * Texture

// }

//}

// Render the parts of the object facing us.

// If the object is convex, these will be closer than the

// back-faces.

//控制后面透明度

Pass {

Cull Back

SetTexture [_MainTex] {

Combine Primary * Texture

}

}

}

}

Shader "Custom/Fog" {

Properties {

_MainTex ("Texture", 2D) = "white" {}

_FogColor ("Fog Color", Color) = (0.3, 0.4, 0.7, 1.0)

}

SubShader {

Tags { "RenderType" = "Opaque" }

CGPROGRAM

#pragma surface surf Lambert finalcolor:mycolor vertex:myvert

struct Input {

float2 uv_MainTex;

half fog;

};

void myvert (inout appdata_full v, out Input data)

{

float4hpos=mul(UNITY_MATRIX_MVP, v.vertex);

data.fog=min(1, dot (hpos.xy, hpos.xy) * 0.1);

}

fixed4 _FogColor;

void mycolor (Input IN, SurfaceOutput o, inout fixed4 color)

{

fixed3fogColor=_FogColor.rgb;

#ifdef UNITY_PASS_FORWARDADD

fogColor=0;

#endif

color.rgb=lerp(color.rgb, fogColor, IN.fog);

}

sampler2D _MainTex;

void surf (Input IN, inout SurfaceOutput o) {

o.Albedo=tex2D(_MainTex, IN.uv_MainTex).rgb;

}

ENDCG

}

Fallback "Diffuse"

}

### 回答1: Unity Shader是一种专门用于制作游戏的图形渲染程序。在大多数游戏中,我们都希望让模型展现出崭新的效果。有时候,如果希望模型边缘看起来发光,则需要使用Shader来进行处理。其中,模型外边缘自发光需要的是特别的处理技巧。 在Unity Shader中实现模型外边缘自发光的方法有很多,但最常见的方式就是通过控制深度、法线和颜色等参数来增加颜色和光亮度。首先,我们需要分析模型边缘的特性,找到边缘的物理体积和光照条件,然后再运用一定的OpenGL技巧给予模型侧面以足够的颜色和光亮度。 另外,还有一种方式可以实现模型的外边缘自发光。那就是将模型的整体颜色设置为辉光色,然后通过代码控制其背面渐变,来实现外边缘的自发光效果。这种方式主要是采用jungle Shader技术来实现模型纹理和物理光源之间的交互效果,运用较为广泛。 总之,实现Unity Shader模型外边缘自发光就需要理解模型的特性,进行合适的参数设置和处理技巧,才能得到理想的效果。不同的游戏场景和模型也会有不同的处理方式,需要开发者结合实际情况进行具体分析和调整。 ### 回答2: Unity Shader中的模型外边缘自发光,可以通过使用描边Shader实现。描边Shader是通过计算法线与表面之间的夹角来确定边缘,并将其与指定颜色进行混合,从而产生模型外边缘的自发光效果。实现该效果的方法有多种,一种常用的做法是在一个关于深度等级的RenderTexture上绘制描边效果,然后将其与原始场景渲染结果叠加在一起。此外,还可以使用几何着色器(Geometry Shader)来实现描边效果,但需要支持OpenGL 4.0以上版本的显卡才能正常运行。 描边Shader的效果取决于边缘权重的计算方法和颜色混合技术。使用不同的模型接口和最小距离阈值,可以调整边沿的宽度和数量。同时,利用颜色叠加,可以给边缘添加动态效果,比如透明度和闪烁等。在制作游戏时,可以通过组合描边Shader与材质、纹理、照明等属性,增强游戏画面的视觉效果,从而提高游戏的品质和受欢迎程度。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值