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 sabrenman94 · May 08, 2018 at 04:24 PM · camerashaderfilterdarken

How to darken the camera feed from ARkit without darkening the AR objects

Using the ARkit plugin I'm trying to apply a darkening filter/effect on the camera feed but not on the AR objects. I see the material for the camera feed is called YUVmaterial but I don't know shader code, and I don't see it being applyied anywhere physically/spacially in the scene.

Any suggestions?

Thanks

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hammadb · Jun 12, 2018 at 02:49 AM

Here is a version of the YUV AR shader that will dim the screen via the dimFactor property.

 Shader "Unlit/ARCameraShaderDim"
 {
     Properties
     {
         _dimFactor ("DimFactor", float) = 1
         _textureY ("TextureY", 2D) = "white" {}
         _textureCbCr ("TextureCbCr", 2D) = "black" {}
     }
     SubShader
     {
         Cull Off
         Tags { "RenderType"="Opaque" }
         LOD 100
 
         Pass
         {
             ZWrite Off
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
             
             #include "UnityCG.cginc"
 
             float4x4 _DisplayTransform;
 
             struct Vertex
             {
                 float4 position : POSITION;
                 float2 texcoord : TEXCOORD0;
             };
 
             struct TexCoordInOut
             {
                 float4 position : SV_POSITION;
                 float2 texcoord : TEXCOORD0;
             };
 
             TexCoordInOut vert (Vertex vertex)
             {
                 TexCoordInOut o;
                 o.position = UnityObjectToClipPos(vertex.position); 
 
                 float texX = vertex.texcoord.x;
                 float texY = vertex.texcoord.y;
                 
                 o.texcoord.x = (_DisplayTransform[0].x * texX + _DisplayTransform[1].x * (texY) + _DisplayTransform[2].x);
                   o.texcoord.y = (_DisplayTransform[0].y * texX + _DisplayTransform[1].y * (texY) + (_DisplayTransform[2].y));
                 
                 return o;
             }
             
             // samplers
             sampler2D _textureY;
             sampler2D _textureCbCr;
             float _dimFactor;
 
             fixed4 frag (TexCoordInOut i) : SV_Target
             {
                 // sample the texture
                 float2 texcoord = i.texcoord;
                 float y = tex2D(_textureY, texcoord).r;
                 float4 ycbcr = float4(y, tex2D(_textureCbCr, texcoord).rg, 1.0);
 
                 const float4x4 ycbcrToRGBTransform = float4x4(
                         float4(1.0, +0.0000, +1.4020, -0.7010),
                         float4(1.0, -0.3441, -0.7141, +0.5291),
                         float4(1.0, +1.7720, +0.0000, -0.8860),
                         float4(0.0, +0.0000, +0.0000, +1.0000)
                     );
 
                 fixed4 rgba = mul(ycbcrToRGBTransform, ycbcr);
                 return rgba * fixed4(_dimFactor, _dimFactor, _dimFactor, 1);
             }
             ENDCG
         }
     }
 }
 

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 sabrenman94 · Jun 12, 2018 at 05:26 PM 0
Share

Thank you!

avatar image AlexCWesterberg · Sep 30, 2021 at 09:31 AM 0
Share

Hello @hammadb This solutions seems to do the trick, however, the camera feed seems to be rotated 90 degrees for me. It looks stretched and as Landscape when in portrait and so on. Any idea why?

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

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

Leaves disappear in game mode 0 Answers

Grey/Dark line between two cubes 1 Answer

Unable to Launch Game:Shaders Problem 0 Answers

How to bring UI element infront of other objects? 0 Answers

Problem with follow-up camera with curved world shader 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