• 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 N1nja · Jun 15, 2010 at 01:30 AM · camerashadereditor

How can I get the Scene Editor's Camera Position in ShaderLab?

I am using a vertex shader, that relies on the position of the Camera.. I am unable to get the camera used in Scene Editor.. is there a way to get teh camera position in the Shader Lib, without setting it as a variable? ( like a pre-defined one, that includes the scene editor camera );

Otherwise I'd like to know how I can grab the Camera GameObject from the Scene Editor

Comment
Add comment · Show 1
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 qJake · Jun 15, 2010 at 02:05 AM 0
Share

Fixed your title so people know it's for ShaderLab and not an editor script.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Yogr · Jul 07, 2010 at 03:13 PM

Hi, take a look at this: link text

unity sets those state variables according to the current camera, object and lights. Since the model*view matrix transforms objects from local to eye space, you can assume that the camera is located at (0,0,0).

Bye!

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
avatar image
0

Answer by qJake · Jun 15, 2010 at 02:00 AM

Have you checked the Vertex shaders that are included with Unity? Their source code can be downloaded here:

http://unity3d.com/support/resources/assets/built-in-shaders

Perhaps you could review the source of the built-in Vertex shader to see how they overcome this problem?

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 N1nja · Jun 15, 2010 at 10:01 AM 0
Share

after reviewing all of those sources, the built-in shaders seem to have no indication of having any direct access to any camera position.

avatar image qJake · Jun 16, 2010 at 01:11 AM 0
Share

I'm not going to pretend I understand vertex sahders, but if the built-in vertex shaders don't use the current camera's position, why do you need it?

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Several questions about OnRenderObject and Camera projection matrix use. 0 Answers

Dividng clip space by "w" warps the output? 1 Answer

Camera Zoom in Scene View 1 Answer

Unity 4.5 Editor hangs when moving the camera 0 Answers

Why does Viking Village Water move with camera in Editor? 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