x


ToonShader offset and Camera fov

Hey guys, I'm aplying a camera zoom (making fov smaller) to my game, but the toonshader offset, responsible for drawing the outline, gets very thick related to the the rest of objects in scene.

The offset isn't related with the fov, it's always the same. So when it gets a closer look, obviously it seems thicker.

So, I was wondering if someone had a problem like that and/or have a tip/idea or workaround to solve this problem.

more ▼

asked May 23 '12 at 12:40 PM

zpinner gravatar image

zpinner
144 10 16 21

(comments are locked)
10|3000 characters needed characters left

8 answers: sort voted first

Hey Matthew,

I solved the problem using Shader.SetGlobalFloat("_CAMERA_FOV", Camera.fov); with that I could access the fov in shader and fix the offset value. basically I'm using this:

....
uniform float _CAMERA_FOV = 60.0f;
...
float2 offset = TransformViewToProjection(norm.xy) * _CAMERA_FOV/60.0f;

but it's probably too primitive, I'll sophisticate it a little bit later.

more ▼

answered May 23 '12 at 10:47 PM

zpinner gravatar image

zpinner
144 10 16 21

(comments are locked)
10|3000 characters needed characters left

I don't know the toon shader very well, if you can access the outline variable in a script you can tie it to the distance from the camera object.

If the camera only follows one object, give it its own material or this will affect all objects with the same material.

the script could look something like

var camera : Camera;
var toonShader : ToonShader;

function Update(){
    toonShader.lineWidthOrWhateverTheVariableNameIs = 
        (camera.transform.position - toonShader.transform.position).magnitude * scaler;
}
more ▼

answered May 23 '12 at 01:12 PM

Weitzel gravatar image

Weitzel
170 4

(comments are locked)
10|3000 characters needed characters left

Can anybody help?

more ▼

answered Jul 17 '12 at 10:07 AM

wr_uk gravatar image

wr_uk
1 1 1 1

(comments are locked)
10|3000 characters needed characters left

Heres an example of the problemalt text

toonshader.png (55.1 kB)
more ▼

answered Jul 16 '12 at 08:43 PM

wr_uk gravatar image

wr_uk
1 1 1 1

(comments are locked)
10|3000 characters needed characters left

Hey Matthew, thanks for the reply. That's a good idea, it has a property called outLineWidth. I'll try that, but first I'm thinking about a solution within the shader code. I have many cameras, and I think that getting the fov from camera in shader would be more perfomatic

more ▼

answered May 23 '12 at 01:18 PM

zpinner gravatar image

zpinner
144 10 16 21

any other tips are appreciated. thanks

May 23 '12 at 01:18 PM zpinner

is camera.fov accessible from shader as MVP matrix? or do I have to set it via script?

May 23 '12 at 04:17 PM zpinner
(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:

x1666
x59
x38

asked: May 23 '12 at 12:40 PM

Seen: 952 times

Last Updated: Jul 17 '12 at 11:55 AM