x


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

more ▼

asked Jun 15 '10 at 01:30 AM

N1nja gravatar image

N1nja
445 23 29 37

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

Jun 15 '10 at 02:05 AM qJake
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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?

more ▼

answered Jun 15 '10 at 02:00 AM

qJake gravatar image

qJake
11.6k 43 78 161

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

Jun 15 '10 at 10:01 AM N1nja

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?

Jun 16 '10 at 01:11 AM qJake
(comments are locked)
10|3000 characters needed characters left

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!

more ▼

answered Jul 07 '10 at 03:13 PM

Yogr gravatar image

Yogr
1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3132
x1745
x1730

asked: Jun 15 '10 at 01:30 AM

Seen: 2517 times

Last Updated: Jun 15 '10 at 02:04 AM