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.
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;
}
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:
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
Try this code to adjust the line width by camera distance.
Simply add this script to the object with the Toon Shader (even if the render is multimaterial).
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OutLineAdjust : MonoBehaviour {
public Material[] thisMats;
public float scale = 0.0002f;
public float Minumum = 0.0025f;
List<float> OrValues = new List<float>();
void Awake () {
thisMats = GetComponentInChildren<Renderer>().materials;
for (int i = 0; i < thisMats.Length; i++)
OrValues.Add( thisMats*.GetFloat("_Outline"));*