Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by abhishek94 · Jun 26, 2016 at 06:00 AM · unity 5editor-scripting

Hello I am new to unity 5.3 , While working over Creation of Beautiful Terrain with the help of https://www.youtube.com/watch?v=qdXT-BFz27k and While Entering into playmode I am getting following Error

CODE IS THIS AND ERROR IS SHOWN IN THE IMAGEalt text #pragma strict

@script ExecuteInEditMode @script RequireComponent (Camera) @script AddComponentMenu ("Image Effects/Bloom (HDR, Lens Flares)")

enum LensflareStyle34 { Ghosting = 0, Anamorphic = 1, Combined = 2, }

enum TweakMode34 { Basic = 0, Complex = 1, }

enum HDRBloomMode { Auto = 0, On = 1, Off = 2, }

enum BloomScreenBlendMode { Screen = 0, Add = 1,
}

class BloomAndLensFlares extends PostEffectsBase { public var tweakMode : TweakMode34 = 0; public var screenBlendMode : BloomScreenBlendMode = BloomScreenBlendMode.Add;

 public var hdr : HDRBloomMode = HDRBloomMode.Auto;
 private var doHdr : boolean = false;
 public var sepBlurSpread : float = 1.5f;
 public var useSrcAlphaAsMask : float = 0.5f;
 
 public var bloomIntensity : float = 1.0f;
 public var bloomThreshhold : float = 0.5f;
 public var bloomBlurIterations : int = 2;    
     
 public var lensflares : boolean = false;
 public var hollywoodFlareBlurIterations : int = 2;
 public var lensflareMode : LensflareStyle34 = 1;
 public var hollyStretchWidth : float = 3.5f;
 public var lensflareIntensity : float = 1.0f;
 public var lensflareThreshhold : float = 0.3f;
 public var flareColorA : Color = Color (0.4f, 0.4f, 0.8f, 0.75f);
 public var flareColorB : Color = Color (0.4f, 0.8f, 0.8f, 0.75f);
 public var flareColorC : Color = Color (0.8f, 0.4f, 0.8f, 0.75f);
 public var flareColorD : Color = Color (0.8f, 0.4f, 0.0f, 0.75f);
 public var blurWidth : float = 1.0f;    
 public var lensFlareVignetteMask : Texture2D;
             
 public var lensFlareShader : Shader; 
 private var lensFlareMaterial : Material;
 
 public var vignetteShader : Shader;
 private var vignetteMaterial : Material;
 
 public var separableBlurShader : Shader;
 private var separableBlurMaterial : Material;
 
 public var addBrightStuffOneOneShader: Shader;
 private var addBrightStuffBlendOneOneMaterial : Material;

 public var screenBlendShader : Shader;
 private var screenBlend : Material;
 
 public var hollywoodFlaresShader: Shader;
 private var hollywoodFlaresMaterial : Material;
 
 public var brightPassFilterShader : Shader;
 private var brightPassFilterMaterial : Material;
 
 function OnDisable()
 {
     if (screenBlend) 
         DestroyImmediate(screenBlend);
     if (lensFlareMaterial) 
         DestroyImmediate(lensFlareMaterial);
     if (vignetteMaterial) 
         DestroyImmediate(vignetteMaterial);
     if (separableBlurMaterial) 
         DestroyImmediate(separableBlurMaterial);
     if (addBrightStuffBlendOneOneMaterial) 
         DestroyImmediate(addBrightStuffBlendOneOneMaterial);
     if (hollywoodFlaresMaterial) 
         DestroyImmediate(hollywoodFlaresMaterial);
     if (brightPassFilterMaterial) 
         DestroyImmediate(brightPassFilterMaterial);
 }
 function CheckResources () : boolean {
     CheckSupport (false);
     
     screenBlend = CheckShaderAndCreateMaterial (screenBlendShader, screenBlend);
     lensFlareMaterial = CheckShaderAndCreateMaterial(lensFlareShader,lensFlareMaterial);
     vignetteMaterial = CheckShaderAndCreateMaterial(vignetteShader,vignetteMaterial);
     separableBlurMaterial = CheckShaderAndCreateMaterial(separableBlurShader,separableBlurMaterial);
     addBrightStuffBlendOneOneMaterial = CheckShaderAndCreateMaterial(addBrightStuffOneOneShader,addBrightStuffBlendOneOneMaterial);
     hollywoodFlaresMaterial = CheckShaderAndCreateMaterial (hollywoodFlaresShader, hollywoodFlaresMaterial);
     brightPassFilterMaterial = CheckShaderAndCreateMaterial(brightPassFilterShader, brightPassFilterMaterial);
     
     if(!isSupported)
         ReportAutoDisable ();
     return isSupported;
 }
 
 function OnRenderImage (source : RenderTexture, destination : RenderTexture) {            
     if(CheckResources()==false) {
         Graphics.Blit (source, destination);
         return;
     }
             
     // screen blend is not supported when HDR is enabled (will cap values)
     
     doHdr = false;
     if(hdr == HDRBloomMode.Auto)
         doHdr = source.format == RenderTextureFormat.ARGBHalf && GetComponent<Camera>().hdr;
 
         doHdr = hdr == HDRBloomMode.On;
     }
     
     doHdr = doHdr && supportHDRTextures;
     
     var realBlendMode : BloomScreenBlendMode = screenBlendMode;
     if(doHdr)
         realBlendMode = BloomScreenBlendMode.Add;
     
     var rtFormat = (doHdr) ? RenderTextureFormat.ARGBHalf : RenderTextureFormat.Default;
     var halfRezColor : RenderTexture = RenderTexture.GetTemporary (source.width / 2, source.height / 2, 0, rtFormat);            
     var quarterRezColor : RenderTexture = RenderTexture.GetTemporary (source.width / 4, source.height / 4, 0, rtFormat);    
     var secondQuarterRezColor : RenderTexture = RenderTexture.GetTemporary (source.width / 4, source.height / 4, 0, rtFormat);    
     var thirdQuarterRezColor : RenderTexture = RenderTexture.GetTemporary (source.width / 4, source.height / 4, 0, rtFormat);    
     
     var widthOverHeight : float = (1.0f * source.width) / (1.0f * source.height);
     var oneOverBaseSize : float = 1.0f / 512.0f;
     
     // downsample
      
     Graphics.Blit (source, halfRezColor, screenBlend, 2); // <- 2 is stable downsample
     Graphics.Blit (halfRezColor, quarterRezColor, screenBlend, 2); // <- 2 is stable downsample    
     
     RenderTexture.ReleaseTemporary (halfRezColor);            

     // cut colors (threshholding)            
     
     BrightFilter (bloomThreshhold, useSrcAlphaAsMask, quarterRezColor, secondQuarterRezColor);        
             
     // blurring
     
     if (bloomBlurIterations < 1) bloomBlurIterations = 1;    
                     
     for (var iter : int = 0; iter < bloomBlurIterations; iter++ ) {
         var spreadForPass : float = (1.0f + (iter * 0.5f)) * sepBlurSpread;
         separableBlurMaterial.SetVector ("offsets", Vector4 (0.0f, spreadForPass * oneOverBaseSize, 0.0f, 0.0f));    
         Graphics.Blit (iter == 0 ? secondQuarterRezColor : quarterRezColor, thirdQuarterRezColor, separableBlurMaterial); 
         separableBlurMaterial.SetVector ("offsets", Vector4 ((spreadForPass / widthOverHeight) * oneOverBaseSize, 0.0f, 0.0f, 0.0f));    
         Graphics.Blit (thirdQuarterRezColor, quarterRezColor, separableBlurMaterial);        
     }

     // lens flares: ghosting, anamorphic or a combination 
     
     if (lensflares) {                            
          
         if (lensflareMode == 0) {
                         
             BrightFilter (lensflareThreshhold, 0.0f, quarterRezColor, thirdQuarterRezColor);                
             
             // smooth a little, this needs to be resolution dependent
             /*                
             separableBlurMaterial.SetVector ("offsets", Vector4 (0.0f, (2.0f) / (1.0f * quarterRezColor.height), 0.0f, 0.0f));    
             Graphics.Blit (thirdQuarterRezColor, secondQuarterRezColor, separableBlurMaterial);                
             separableBlurMaterial.SetVector ("offsets", Vector4 ((2.0f) / (1.0f * quarterRezColor.width), 0.0f, 0.0f, 0.0f));    
             Graphics.Blit (secondQuarterRezColor, thirdQuarterRezColor, separableBlurMaterial); 
             */
             // no ugly edges!
             
             Vignette (0.975, thirdQuarterRezColor, secondQuarterRezColor);        
             BlendFlares (secondQuarterRezColor, quarterRezColor);
         } 
         
         // (b) hollywood/anamorphic flares?
         
         else {
             
             // thirdQuarter has the brightcut unblurred colors
             // quarterRezColor is the blurred, brightcut buffer that will end up as bloom
             
             hollywoodFlaresMaterial.SetVector ("_Threshhold", Vector4 (lensflareThreshhold, 1.0f / (1.0f - lensflareThreshhold), 0.0f, 0.0f));
             hollywoodFlaresMaterial.SetVector ("tintColor", Vector4 (flareColorA.r, flareColorA.g, flareColorA.b, flareColorA.a) * flareColorA.a * lensflareIntensity);
             Graphics.Blit (thirdQuarterRezColor, secondQuarterRezColor, hollywoodFlaresMaterial, 2);     
             Graphics.Blit (secondQuarterRezColor, thirdQuarterRezColor, hollywoodFlaresMaterial, 3);     
             
             hollywoodFlaresMaterial.SetVector ("offsets", Vector4 ((sepBlurSpread * 1.0f / widthOverHeight) * oneOverBaseSize, 0.0, 0.0, 0.0));    
             hollywoodFlaresMaterial.SetFloat ("stretchWidth", hollyStretchWidth);
             Graphics.Blit (thirdQuarterRezColor, secondQuarterRezColor, hollywoodFlaresMaterial, 1);    
             hollywoodFlaresMaterial.SetFloat ("stretchWidth", hollyStretchWidth * 2.0f);
             Graphics.Blit (secondQuarterRezColor, thirdQuarterRezColor, hollywoodFlaresMaterial, 1);    
             hollywoodFlaresMaterial.SetFloat ("stretchWidth", hollyStretchWidth * 4.0f);
             Graphics.Blit (thirdQuarterRezColor, secondQuarterRezColor, hollywoodFlaresMaterial, 1);    
                                             
             if (lensflareMode == 1) {                                                            
                 for (var itera : int = 0; itera < hollywoodFlareBlurIterations; itera++ ) {
                     separableBlurMaterial.SetVector ("offsets", Vector4 ((hollyStretchWidth * 2.0f / widthOverHeight) * oneOverBaseSize, 0.0, 0.0, 0.0));    
                     Graphics.Blit (secondQuarterRezColor, thirdQuarterRezColor, separableBlurMaterial);
                     separableBlurMaterial.SetVector ("offsets", Vector4 ((hollyStretchWidth * 2.0f / widthOverHeight) * oneOverBaseSize, 0.0, 0.0, 0.0));    
                     Graphics.Blit (thirdQuarterRezColor, secondQuarterRezColor, separableBlurMaterial);                         
                 }        
                             
                 AddTo (1.0, secondQuarterRezColor, quarterRezColor);
             }  
             else {            
             
                 // (c) combined
                                                                         
                 for (var ix : int = 0; ix < hollywoodFlareBlurIterations; ix++ ) {
                     separableBlurMaterial.SetVector ("offsets", Vector4 ((hollyStretchWidth * 2.0f / widthOverHeight) * oneOverBaseSize, 0.0, 0.0, 0.0));    
                     Graphics.Blit (secondQuarterRezColor, thirdQuarterRezColor, separableBlurMaterial); 
                     separableBlurMaterial.SetVector ("offsets", Vector4 ((hollyStretchWidth * 2.0f / widthOverHeight) * oneOverBaseSize, 0.0, 0.0, 0.0));    
                     Graphics.Blit (thirdQuarterRezColor, secondQuarterRezColor, separableBlurMaterial);                             
                 }        
             
                 Vignette (1.0, secondQuarterRezColor, thirdQuarterRezColor);
                 BlendFlares (thirdQuarterRezColor, secondQuarterRezColor);
                 AddTo (1.0, secondQuarterRezColor, quarterRezColor);
             }                                                                                        
         }
     }        
     
     // screen blend bloom results to color buffer
     
     screenBlend.SetFloat ("_Intensity", bloomIntensity);
     screenBlend.SetTexture ("_ColorBuffer", source);
     Graphics.Blit (quarterRezColor, destination, screenBlend, realBlendMode);        
     
     RenderTexture.ReleaseTemporary (quarterRezColor);    
     RenderTexture.ReleaseTemporary (secondQuarterRezColor);    
     RenderTexture.ReleaseTemporary (thirdQuarterRezColor);        
 }
 
 private function AddTo (intensity_ : float, from : RenderTexture, to : RenderTexture) {
     addBrightStuffBlendOneOneMaterial.SetFloat ("_Intensity", intensity_);
     Graphics.Blit (from, to, addBrightStuffBlendOneOneMaterial);         
 }
 
 private function BlendFlares (from : RenderTexture, to : RenderTexture) {
     lensFlareMaterial.SetVector ("colorA", Vector4 (flareColorA.r, flareColorA.g, flareColorA.b, flareColorA.a) * lensflareIntensity);
     lensFlareMaterial.SetVector ("colorB", Vector4 (flareColorB.r, flareColorB.g, flareColorB.b, flareColorB.a) * lensflareIntensity);
     lensFlareMaterial.SetVector ("colorC", Vector4 (flareColorC.r, flareColorC.g, flareColorC.b, flareColorC.a) * lensflareIntensity);
     lensFlareMaterial.SetVector ("colorD", Vector4 (flareColorD.r, flareColorD.g, flareColorD.b, flareColorD.a) * lensflareIntensity);
     Graphics.Blit (from, to, lensFlareMaterial);            
 }

 private function BrightFilter (thresh : float, useAlphaAsMask : float, from : RenderTexture, to : RenderTexture) {
     if(doHdr)
         brightPassFilterMaterial.SetVector ("threshhold", Vector4 (thresh, 1.0f, 0.0f, 0.0f));
     else
         brightPassFilterMaterial.SetVector ("threshhold", Vector4 (thresh, 1.0f / (1.0f-thresh), 0.0f, 0.0f));
     brightPassFilterMaterial.SetFloat ("useSrcAlphaAsMask", useAlphaAsMask);
     Graphics.Blit (from, to, brightPassFilterMaterial);            
 }
 
 private function Vignette (amount : float, from : RenderTexture, to : RenderTexture) {
     if(lensFlareVignetteMask) {
         screenBlend.SetTexture ("_ColorBuffer", lensFlareVignetteMask);
         Graphics.Blit (from, to, screenBlend, 3);                 
     } 
     else {
         vignetteMaterial.SetFloat ("vignetteIntensity", amount);
         Graphics.Blit (from, to, vignetteMaterial);         
     }
 }

}

screenshot-49.png (94.8 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Unable to load asset at path with unity tutorial code 1 Answer

how to stop reorderable list from passing Event value to the new element 1 Answer

Precalculate lighting by editor script 0 Answers

Can't remove using Unity Editor, it is necessary for the development of the game. 0 Answers

Unity editor not saving object changes 4 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges