如何使对象在unity3d中发光 [英] How to make an object to glow in unity3d

查看:105
本文介绍了如何使对象在unity3d中发光的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在3D世界中生成许多球体来表示对象,并且当我在黑色背景下工作时,我希望球体周围有一点辉光,我读到可以用着色器完成,但是需要更多指导,例如如何制作着色器以及将着色器放置在何处,我们将不胜感激.

Hi I'm generating lots of spheres in a 3D world to represent objects and as I'm working with a black background I want the spheres to have a little glow around them, I read that It can be done with shaders but need a little more guindance, for example how to make the shader and where to put it, any help will be appreciated.

推荐答案

此链接有一个视频:

https://www.youtube.com/watch?v=nZZ6MDY3JOk

它在对象周围创建边框并发出光晕效果.这是着色器,但您应该观看视频以进行学习(并为他们提供一个视图的功劳):

it creates a rim around the object and a glow effect. Here is the shader but you should watch the video for learning purpose (and to give them that one view count for credit):

Shader "Custom/GlowShader" 
{
 Properties 
 {
  _ColorTint("Color Tint", Color) = (1, 1, 1, 1)
  _MainTex("Base (RGB)", 2D) = "white" {}
  _BumpMap("Normal Map", 2D) = "bump" {}
  _RimColor("Rim Color", Color) = (1, 1, 1, 1)
  _RimPower("Rim Power", Range(1.0, 6.0)) = 3.0

 }
 SubShader {

  Tags { "RenderType"="Opaque" }

  CGPROGRAM
  #pragma surface surf Lambert

  struct Input {

   float4 color : Color;
   float2 uv_MainTex;
   float2 uv_BumpMap;
   float3 viewDir;

  };

  float4 _ColorTint;
  sampler2D _MainTex;
  sampler2D _BumpMap;
  float4 _RimColor;
  float _RimPower;

  void surf (Input IN, inout SurfaceOutput o) 
  {


   IN.color = _ColorTint;
   o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb * IN.color;
   o.Normal = UnpackNormal(tex2D(_BumpMap,IN.uv_BumpMap));

   half rim = 1.0 - saturate(dot(normalize(IN.viewDir), o.Normal));
   o.Emission = _RimColor.rgb * pow(rim, _RimPower);


  }
  ENDCG
 } 
 FallBack "Diffuse"
}

这篇关于如何使对象在unity3d中发光的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆