- Home /
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.
Answer by zpinner · May 23, 2012 at 10:47 PM
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.
Answer by Weitzel · May 23, 2012 at 01:12 PM
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;
}
Answer by zpinner · May 23, 2012 at 01:18 PM
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
is camera.fov accessible from shader as $$anonymous$$VP matrix? or do I have to set it via script?
Answer by zpinner · Jul 16, 2012 at 09:40 PM
Hey wr_uk,
you have to paste that code in the shader code.
the Shader.SetGlobalFloat("_CAMERA_FOV", Camera.fov); code you put where you're changing the camera.fov
Thanks for the reply zpinner.
I'm a bit lost when it comes to code. I'm not sure what you mean by code you put where you're changing the camera.fov
so here the toon shader code.
Shader "Toon/Lighted Outline" { Properties { _Color ("$$anonymous$$ain Color", Color) = (0.5,0.5,0.5,1) _OutlineColor ("Outline Color", Color) = (0,0,0,1) Outline ("Outline width", Range (.002, 0.03)) = .005 $$anonymous$$ainTex ("Base (RGB)", 2D) = "white" {} _Ramp ("Toon Ramp (RGB)", 2D) = "gray" {} }
SubShader { Tags { "RenderType"="Opaque" } UsePass "Toon/Lighted/FORWARD" UsePass "Toon/Basic Outline/OUTLINE" }
Fallback "Toon/Lighted" }
where exactly do I paste it?
Your answer
Follow this Question
Related Questions
How to Get Nice Thick Toon-Like Outlines On Non-Smooth Geometry? 1 Answer
Cutout toon shader 1 Answer
Silhouette enhancement toon shader 0 Answers
How do I get the textures to work on thir toon shader? 1 Answer
Unity Pro Toon Shader Question 1 Answer