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 /
avatar image
2
Question by Derenger21 · Oct 12, 2017 at 11:11 PM · camerashadermultiple

second camera renderWithShader

Hey all, trying my darndest to use google and the unity manual to figure this out but i just can't do it. I feel like I'm missing a huge step that no one points out cos its obvious? anyway;

I have 2 camera's in scene, cam1 is viewport.

cam2 renders out to a RenderTexture to display a top down minimap on the canvas, this camera has its culling mask set up correctly so it only draws 'Tiles' (walls, floors). this all works flawlessly.

what i need is for cam2 to render with fullbright lighting, ignore all light sources and such, google directed me to the shader lab and Camera.RenderWithShader (); try as i might im not getting the results im looking for, either the camera stops rendering all together or it renders with lighting.

I stole a few shader scripts off the googles and tried to study them, people say they work but they don't for me. I still have near-to-no understanding of shader syntax except for the basics i could figure out.

So i guess what im asking here is for some one to briefly go over the steps they would use to achieve the same thing, im TRYING to understand it all because frankly i'd rather learn than get a free ride, you know?

What I've got

 private Camera cam;
     public Shader shad;
 
     void Start () 
     {
         cam = GetComponent<Camera>();
 
         cam.RenderWithShader (shad, "Opaque");  
             //I have no idea what string goes here so i tried listing different tags and things depending on 
             //the shader scripts i got
 
         cam.enabled = true;
     }

alt text

 Shader "Unlit/VertexLightless"
 {
     Properties 
     {
          _Color ("Main Color", Color) = (1,1,1,1)
          _MainTex ("Base (RGB)", 2D) = "white" {}
      }
 
      SubShader 
      {
          Tags { "RenderType"="Opaque" }
            LOD 200
  
          CGPROGRAM
         #pragma surface surf Lambert
  
          sampler2D _MainTex;
         fixed4 _Color;
  
      struct Input 
      {
          float2 uv_MainTex;
         float4 color : COLOR;
      };
  
      void surf (Input IN, inout SurfaceOutput o) 
      {
          fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
          o.Albedo = c.rgb;
          o.Albedo *= IN.color.rgb;
          o.Alpha = c.a;
      }
          ENDCG
      }
      Fallback "VertexLit"
 }


P.S. : The shader isn't my writing, I'm trying to learn from it and get it working. This is my first adventure into shader lab and its proving difficult :( plz halp.

camshaderex.png (120.4 kB)
Comment
Add comment · Show 1
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 Derenger21 · Oct 12, 2017 at 11:45 PM 0
Share

Just made a discovery, aparently setting the tag to null forces all objects to use the replacement shader? either way, im one step forward haha... it's still reading lights.

1 Reply

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

Answer by Bunny83 · Oct 13, 2017 at 02:16 AM

It would help reading the documentation as well as the linked pages like this one.

The method "RenderWithShader" renders the camera manually. Of course rendering it in Start makes no sense at all. Even Update wouldn't work as Update runs way before any rendering starts.

If you're not familiar to manually rendering things you might just want to use "SetReplacementShader" instead and leave the camera enabled. That way it renders automatically but uses the replacement shader.

Also the documentation is pretty clear about how it works:

  • If replacementTag is empty, then all objects in the scene are rendered with the given replacement shader.

  • If replacementTag is not empty, then for each object that would be rendered:
    • The real object’s shader is queried for the tag value.

    • If it does not have that tag, object is not rendered.

    • A subshader is found in the replacement shader that has a given tag with the found value. If no such subshader is found, object is not rendered.

    • Now that subshader is used to render the object.

This is pretty clear what is actually rendered.

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 Derenger21 · Oct 13, 2017 at 02:48 AM 0
Share

I read through those pages before making this post and found them confusing.

i put it in start for the code example on SetReplacementShader and when it didn't work i tried the other call.

turns out my issue was trying to feed the 'correct' tag to replace. "if replacementTag is empty, then all objects in the scene are rendered with the given replacement shader." - is what i missed, and now the shader 'works' but still not giving the desired results, lights are rendered as near pure white and shadows are greys.

avatar image Bunny83 Derenger21 · Oct 13, 2017 at 03:58 AM 0
Share

Well, you use the Lambert lighting model. If you don't want any lighting your shouldn't use that lighting model and provide your own

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

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

Shader based camera compositing. 2 Answers

Dividng clip space by "w" warps the output? 1 Answer

How to achieve diablo style walls? 4 Answers

Wrong Depth texture being passed into the shader. 0 Answers

Shader: determine if camera is orthographic 2 Answers


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