본문 바로가기
Shader

후처리 이펙트를 만듭시다 ~ 랄랄라 : Make the post effects

by 대마왕J 2015. 8. 13.

기본형만 백업해 두기로 합시다

It's only Base code

==================================

 

using UnityEngine;
using System.Collections;

[ExecuteInEditMode]
public class NxBloom : MonoBehaviour {

 public Shader nxbloom;
 private Material bloomMaterial;

 #region Properties
 Material material
 {
  get
  {
   if (bloomMaterial == null)
   {
    bloomMaterial = new Material (nxbloom);
    bloomMaterial.hideFlags = HideFlags.HideAndDontSave;
   }
   return bloomMaterial;
  }
 }
 #endregion

 // Use this for initialization
 void Start () {
  if (!SystemInfo.supportsImageEffects)
  {
   enabled = false;
   return;
  }

  if (!nxbloom && nxbloom.isSupported)
  {
   enabled = false;
  } 
 }

 void OnRenderImage (RenderTexture sourceTexture , RenderTexture destTexture){


  if (nxbloom != null){
   Graphics.Blit(sourceTexture, destTexture, material);
  } 
  else{
   Graphics.Blit(sourceTexture, destTexture, material);
  }
 }
 
 // Update is called once per frame
 void Update () {
 
 }

 void OnDisable(){

  if(bloomMaterial)
  {
   DestroyImmediate(bloomMaterial);
  }
 }
}

 

============================

 

기본 Shader

 

Shader "Custom/nxbloom" {
 Properties {
  _MainTex ("Albedo (RGB)", 2D) = "white" {}
 }
 SubShader {
  pass {
  
  CGPROGRAM
  #pragma vertex vert_img
  #pragma fragment frag
  #pragma fragmentoption ARB_precision_hint_fastest
  #include "UnityCG.cginc"
  
  uniform sampler2D _MainTex;
  
  fixed4 frag(v2f_img i ) :COLOR
  {
   fixed4 renderTex = tex2D(_MainTex, i.uv);
   return renderTex ;  
  } 
  
  ENDCG
  
  }
 }  
}

 

 

여기서 시작하면 됨

Now, let's start over here!

반응형

댓글