Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Gandi · Aug 17, 2012 at 10:04 AM · rendertexturerender to texture

Real time rendering in cubemap in image effect

I try to do that : -> MainCamera -> Script to render scene in cube map -> MainCamera -> Script image effect using the cube map (This script it's OK with static cube-map)

The result is :

  • A empty grey cube map

  • have this bug :

    RenderTexture error: failed to retrieve color surface [invalid call] Erro in file: C:/BuildAgent/work/d9c031b1c154f5ae/Runtime/GfxDevice/d3d/RenderTextureD3D.cpp at line: 278

perhaps it's the same on this thread : http://answers.unity3d.com/questions/16149/Water-in-cubemap.html

My render cube map script : ( you can see my tests )

 enum TextureCubeMapSize
 {
     Low = 512,
     Normal = 1024,
     Best = 2048,
     //VeryHigh = 4096,
 }
     
 public var m_TextureCubeMapSize : TextureCubeMapSize = TextureCubeMapSize.Normal ;
 public var m_RenderTexture : RenderTexture = null ;
 public var m_OneFacePerFrame = false ;
 //private var m_DummyCam : Camera = null ;
     
 function OnDisable()
 {
     if( m_RenderTexture )
     {
         DestroyImmediate( m_RenderTexture ) ;
         m_RenderTexture = null ;
     }
     
 //    if( m_DummyCam )
 //    {
 //        DestroyImmediate( m_DummyCam ) ;
 //        m_DummyCam = null ;
 //    }
 }
 
 function Start () 
 {
     // render all six faces at startup
     UpdateCubemap( 63 ) ;
 }
 
 function LateUpdate() 
 {    
     //yield WaitForEndOfFrame() ;
         UpdateCubemap() ;
     //yield ;
 }
 /*
 function OnPostRender()
 {}
 
 function OnPreCull()
 {}
 
 function OnPreRender()
 {}
 
 function OnRenderImage( inSource : RenderTexture, inDestination : RenderTexture ) 
 {}
 
 function OnRenderObject()
 {}
 */
 
 function OnWillRenderObject()
 {        
     //UpdateCubemap() ;
 }
 
 function OnWillRender() 
 {        
     //UpdateCubemap() ;
 }
 
 function UpdateCubemap( inFaceMask : int ) 
 {
 //    if( !m_DummyCam )
 //    {
 //        var aDummyCamObject = new GameObject ("CubemapCamera", Camera ) ;
 //        aDummyCamObject.hideFlags = HideFlags.HideAndDontSave;
 //        aDummyCamObject.transform.position = transform.position ;
 //        aDummyCamObject.transform.rotation = transform.rotation ;
 //        m_DummyCam = aDummyCamObject.camera;
 //        m_DummyCam.enabled = false ;
 //    }
     
     if( !m_RenderTexture ) 
     {    
         m_RenderTexture = new RenderTexture( m_TextureCubeMapSize, m_TextureCubeMapSize, 16, RenderTextureFormat.RGB565, RenderTextureReadWrite.Default ) ;
         m_RenderTexture.isCubemap = true ;
         //m_RenderTexture.hideFlags = HideFlags.HideAndDontSave ;     
         //camera.targetTexture = m_RenderTexture ;      
     }
 
 //    m_DummyCam.transform.position = transform.position ;
 //    m_DummyCam.transform.rotation = transform.rotation ;
     camera.RenderToCubemap( m_RenderTexture, inFaceMask ) ;
     
 }
 
 function UpdateCubemap()
 {
     if( m_OneFacePerFrame )
     {
         var aFaceToRender = Time.frameCount % 6 ;
         var aFaceMask = 1 << aFaceToRender ;
         UpdateCubemap( aFaceMask ) ;            
     } 
     else 
     {
         UpdateCubemap( 63 ) ; // all six faces
     }    
 }


[Unity 3.5.5f3 pro : Windows seven 64bits : Geforce 650M 1Gb ( optimus use the geforce with unity ) : i5 : 8go RAM ]

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Gandi · Aug 20, 2012 at 10:13 PM

It's work now :

You should use a dummy camera for the rendering in cube-map. Else you cannot use that into a post-effect. They are like a snake biting its own tail.

And i have a stupid error in my code from this function :

 OnRenderImage( inSource : RenderTexture, inDestination : RenderTexture ) 

I wrote that :

 if( m_ScriptRenderScene && !m_ScriptRenderScene.m_RenderTexture )
     m_Material.SetTexture( "inCube", m_ScriptRenderScene.m_RenderTexture ) ;

I delete the pointer negation and it's work ( this error is very stupid )


The result is :

 enum TextureCubeMapSize
 {
     Low = 512,
     Normal = 1024,
     Best = 2048,
     VeryHigh = 4096,
 }
     
 public var m_TextureCubeMapSize : TextureCubeMapSize = TextureCubeMapSize.Normal ;
 public var m_RenderTexture : RenderTexture = null ;
 public var m_OneFacePerFrame = false ;
 private var m_DummyCam : Camera = null ;
     
 function OnDisable()
 {
     if( m_RenderTexture )
     {
         DestroyImmediate( m_RenderTexture ) ;
         m_RenderTexture = null ;
     }
     
     if( m_DummyCam )
     {
         DestroyImmediate( m_DummyCam ) ;
         m_DummyCam = null ;
     }
 }
 
 function Start () 
 {
     // render all six faces at startup
     UpdateCubemap( 63 ) ;
 }
 
 function LateUpdate() 
 {    
     UpdateCubemap() ;
 }
 
 function UpdateCubemap( inFaceMask : int ) 
 {
     if( !m_DummyCam )
     {
         var aDummyCamObject = new GameObject ("CubemapCamera", Camera ) ;
         aDummyCamObject.hideFlags = HideFlags.HideAndDontSave;
         aDummyCamObject.transform.position = transform.position ;
         aDummyCamObject.transform.rotation = transform.rotation ;
         m_DummyCam = aDummyCamObject.camera;
         m_DummyCam.enabled = false ;
     }
     
     if( !m_RenderTexture ) 
     {    
         m_RenderTexture = new RenderTexture( m_TextureCubeMapSize, m_TextureCubeMapSize, 24 ) ;
         m_RenderTexture.isCubemap = true ; 
         m_RenderTexture.useMipMap = false ;
         m_RenderTexture.Create() ;       
 
     }
 
     m_DummyCam.transform.position = transform.position ;
     m_DummyCam.transform.rotation = transform.rotation ;
     m_DummyCam.RenderToCubemap( m_RenderTexture, inFaceMask ) ;    
 }
 
 function UpdateCubemap()
 {
     if( m_OneFacePerFrame )
     {
         var aFaceToRender = Time.frameCount % 6 ;
         var aFaceMask = 1 << aFaceToRender ;
         UpdateCubemap( aFaceMask ) ;            
     } 
     else 
     {
         UpdateCubemap( 63 ) ; // all six faces
     }    
 }



Now i have a other problem :

The camera orientation has no effect on the rendering cube-map. And it's very important for me.

Comment
Add comment · Share
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

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Force RenderTexture aliasing 0 Answers

Howto render camera into texture while still rendering into scene view? 1 Answer

How to prevent RenderTexture colour blending 1 Answer

Render particle system to texture. 0 Answers

Why Camera clear color alpha channel is ignored? 2 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