• 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
3
Question by blinxpro · Jul 07, 2011 at 11:18 PM · texturelightingprojectorbake

Can Unity bake lighting/mapping from a projector?

I would like to use a projector to "map" several objects at once and have them keep that mapping when they are no longer in the projector.

Example:

When an image is "projected" into a camera, it gets "baked" onto the film. The image stays baked on the film even though it is no longer being exposed to that image through the camera lens (the projector).

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

2 Replies

· Add your reply
  • Sort: 
avatar image
6

Answer by Jacktang · Mar 02, 2012 at 07:59 AM

This can actually be done with unity pro, and a bit of shader knowhow. What you do is you write a custom vertex shader that unwraps your mesh according to its UV structure and transforms it into screen space. Then you perform your regular texture projection in the same shader. Assign that shader to a material, assign that material to a projector, put that projector onto a layer, and cull the main camera from rendering that layer, then create a second camera that renders only that projector layer and tell it to render its output to a RenderTexture. You will then have a render texture with your projector sprite projected onto its UVs.

Should be relatively straight forward for anyone who knows their vertex / fragment shaders. Here is a basic one that I came up with. I would wager a guess that this method could be easily translated to light cookies as well.

 Shader "Custom/UnwrapShader" {
     Properties {
         _ProjectedTexture ("Projected Texture", 2D) = "" { TexGen ObjectLinear }
     }
     SubShader {
         Tags { "Queue" = "Transparent" }
         Pass {
             Cull Off
             AlphaTest Greater 0
             Blend SrcAlpha OneMinusSrcAlpha
             
             CGPROGRAM
 
             #pragma vertex vert_main
             #pragma fragment frag_main
             #include "UnityCG.cginc"
         
             sampler2D _ProjectedTexture;
             float4x4 _Projector;
         
             struct Output_Struct {
                 float4 position : SV_POSITION;
                 float4 texcoord : TEXCOORD0;
             };    
             
             Output_Struct vert_main (appdata_tan v) {
                 Output_Struct OUT;
 
                 OUT.position.xy = v.texcoord.xy * 2.0 - 1.0;
                 OUT.position.z = 0;
                 OUT.position.w = v.vertex.w;
                 
                 OUT.texcoord = mul(_Projector, v.vertex);
                 return OUT;
             }
             
             float4 frag_main (Output_Struct OUT) : COLOR {
                 half4 tex = tex2Dproj(_ProjectedTexture, UNITY_PROJ_COORD(OUT.texcoord)) * half4(1,0,0,1);
                 return tex;
             }
     
             ENDCG
         }
     }
 }
Comment
Add comment · Show 2 · 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
avatar image sameer-mirza · Dec 08, 2014 at 08:21 AM 1
Share

Hi @Jacktang, I've tried the above shader with my projector and all the steps you mentioned in your answer. I can see the unwrapped UV islands on my screen (in scene view, and also in game view if I don't remove my projection layer from the culling mask field). However, my second camera does not show this (neither adds to the target RenderTexture). Am I missing something here?

avatar image sameer-mirza · Dec 11, 2014 at 02:04 PM 1
Share

Got this to work finally! Had to duplicate my mesh into the second layer for the second camera to see as well. It seems you can't see projections unless you see the mesh as well. Just putting the projector into another layer did not work until you put a mesh in the same layer as well.

avatar image
-3

Answer by Dreamora · Jul 10, 2011 at 11:18 PM

No, thats not possible.

Projectors only exist at realtime.

Lightmap baking is restricted to static lights and as far as I know does currently not even support light cookies

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

Crash on Bake Selected 0 Answers

Just A Projected Texture, Not Shadow Or Light 3 Answers

Normal maps problem 1 Answer

How to prevent Overlapping Lights from combining / adding intensity? 3 Answers

light probes change texture 0 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