Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by romT · May 15, 2017 at 01:45 PM · shadercolorvertexfrustum

Controlled aera rendering via shader

Hi,

I have started using shader in Unity but with some difficulties. I am trying to render some GameObject (i will call CubeB) in a specific aera of my screen. I want them in front of all other GameObject. I want to control the size of this aera.

But first I try to render just a Color in this aera.

For that I set a Plane in my scene with a script and just a transform. The script picks a material with the shader, transform the plane and draw a Mesh. The plane is normalized and the Mesh is set at each frame. The size, position, rotation of the plane change every frame via the following script :

     /// Origin of the player's head
     [Tooltip("Transform of the player's head")]
     public Transform HeadTransform;
 
     /// Material used to play with the Zbuffer for the RA rendering
     [Tooltip("Material used to play with the Zbuffer for the RA rendering.")]
     [SerializeField]
     private Material FadeMaterial;
     private Material FadeMaterialInstance;
 
     private Mesh PlaneMesh;
 
     private Matrix4x4 local;
     
     void Start()
     {
         PlaneMesh = new Mesh();
         Vector3[] verts = new Vector3[]
         {
             new Vector3(-1, -1, 0),
             new Vector3(-1, 1, 0),
             new Vector3(1, 1, 0),
             new Vector3(1, -1, 0)
         };
         int[] elts = new int[] { 0, 1, 2, 0, 2, 3 };
         PlaneMesh.vertices = verts;
         PlaneMesh.triangles = elts;
         PlaneMesh.RecalculateBounds();
         
         if(FadeMaterial != null)
             FadeMaterialInstance = new Material(FadeMaterial);
     }
 
     void Update()
     {
         Matrix4x4 local = Matrix4x4.TRS(Vector3.forward * 0.33f, Quaternion.identity, Vector3.one); // Has to be in front of the clipping plan of the camera
 
         Graphics.DrawMesh(PlaneMesh, HeadTransform.localToWorldMatrix*local, FadeMaterialInstance,0);
         FadeMaterialInstance.SetPass(0);
     }
 }

Then in the shader attached to the Material FADEMATERIAL try to do what I want. But no color appears at my screen ... I don't understand.

The shader :

 Shader "Custom/FadeBlack"
 {        
         SubShader
         {
             Tags{ "Queue" = "Geometry+5" "IgnoreProjector" = "True" }
 
             ZTest Always    
 
             Pass
             {
                 ZWrite On
 
                 CGPROGRAM
                 #pragma vertex vert
                 #pragma fragment frag
 
                 #include "UnityCG.cginc"
 
                 uniform float _fovSize;
 
                 struct appdata
                 {
                     float4 vertex : POSITION; 
                 };
 
                 struct v2f
                 {
                     float4 vertex : SV_POSITION; 
                     float4 uv : TEXCOORD0;
                 };
     
                 v2f vert(appdata v)
                 {
                     v2f o;
                     o.vertex = v.vertex;
                     o.uv = v.vertex; 
                     return o;
                 }
 
                 struct fragmentOutput 
                 {
                     float zvalue : SV_Depth;
                     float4 color : SV_Target;
                 };
 
                 fragmentOutput frag(v2f i)
                 {
                     fragmentOutput o;
                     o.zvalue = 0.0;
                     o.color = (1,1,1,1);
                     _fovSize = 0.5;
 
                     if ((i.vertex.y <(-_fovSize) || i.vertex.y >(_fovSize))   ||
                          (i.vertex.x <(-_fovSize) || i.vertex.x >(_fovSize)))
                     {
                         o.zvalue = 1.0;
                                                 o.color = (0,0,0.5,1);
                     }
                     return o;
                 }
                 ENDCG
             }
         }
 }
 

Any idea of what is it happening ?

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

0 Replies

· Add your reply
  • Sort: 

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

129 People are following this question.

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

Related Questions

RESOLVED: Shader built using Shadergraph's Vertex Color node looks washed out 1 Answer

Need Help for constant alpha shader (example image) 0 Answers

Random rotation in a shader? 1 Answer

Shader Transparency problem 1 Answer

How to design Monument Valley? 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