Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
1
Question by zpinner · May 23, 2012 at 12:40 PM · shaderfovtoon

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.

Comment
Add comment
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

9 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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.

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
1

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;
 }

   
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 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

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 zpinner · May 23, 2012 at 01:18 PM 0
Share

any other tips are appreciated. thanks

avatar image zpinner · May 23, 2012 at 04:17 PM 0
Share

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

avatar image
0

Answer by wr_uk · Jul 16, 2012 at 08:43 PM

Heres an example of the problemalt text


toonshader.png (55.1 kB)
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 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

Comment
Add comment · Show 1 · 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 wr_uk · Jul 16, 2012 at 10:16 PM 0
Share

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?

  • 1
  • 2
  • ›

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.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


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