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
0
Question by Q_B · Nov 30, 2010 at 08:52 AM · shadergraphicsmirrormirrorreflection

Complete Flat Mirror Reflection shader

Greetings. I posted this on a topic on Unity comunity, but with no answers. So, I thought I'd post it here instead.

I've been testing the pro version, and I'm developing some small demos. There's a high probability that the company I'm working for will aquire a license, but I just have 3 trial days left ...

I'm trying to come up with a working mirror reflection shader, with reflection value, and most important, which still receives shadows!

Seems no one has come up with one, so I tried using my limited "code hacking" abilities and came up with a shader that does this. Problem is, and that's due to my ignorance, I can't "assign" the projection matrix to the reflection texture!

Shader "Reflective/Mirror Diffuse" { Properties { _Color ("Main Color", Color) = (1,1,1,1) _ReflectColor ("Reflection Color", Color) = (1,1,1,0.5) _MainTex ("Base (RGB) RefStrength (A)", 2D) = "white" {} _ReflectionTex ("Reflection", 2D) = "white" { TexGen ObjectLinear } } SubShader { LOD 200 Tags { "RenderType"="Opaque" }

CGPROGRAM #pragma surface surf Lambert

sampler2D _MainTex; sampler2D _ReflectionTex; //samplerCUBE _Cube;

float4 _Color; float4 _ReflectColor;

struct Input { float2 uv_MainTex; float2 uv_ReflectionTex; //float2 p_ProjectionMatrix; //float3 worldRefl; };

void surf (Input IN, inout SurfaceOutput o) { half4 tex = tex2D(_MainTex, IN.uv_MainTex); half4 c = tex * _Color; o.Albedo = c.rgb;

 //half4 reflcol = texCUBE (_Cube, IN.worldRefl);
 half4 reflcol = tex2D (_ReflectionTex, IN.uv_ReflectionTex);
 //half4 reflcol = tex2D (_ReflectionTex, IN.worldRefl);
 //half4 reflcol = tex2D (_ReflectionTex, IN.p_ProjectionMatrix);
 reflcol *= tex.a;
 o.Emission = reflcol.rgb * _ReflectColor.rgb;
 o.Alpha = reflcol.a * _ReflectColor.a;

} ENDCG }

FallBack "Reflective/VertexLit" }

Obviously, the "IN.uv_ReflectionTex" is wrong. Now, on the mirror shader, I see a " matrix [_ProjMatrix] " on the _ReflectionTex SetTexture part, and this seems to be what I'm looking for.

But how can I access this correct projection matrix from within the CGPROGRAM shader section?

If anybody can give a helping hand, would be very thankfull, as I'm sure many more users!

Comment
Add comment · Show 2
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 Proclyon · Nov 30, 2010 at 09:14 AM 0
Share

just an idea ( Really could be a terrible idea of $$anonymous$$e) but if you ask a question in several places. You may end up with people giving double answers (or big similar scripts) $$anonymous$$aybe (and just maybe :D) it's smart to link all Q&A together referencing each other like peer to peer network. I would be pretty bummed to write a big answer just to find out John Doe wrote a slightly better one 10 seconds ago on the other site that looks just like $$anonymous$$e.

avatar image Q_B · Nov 30, 2010 at 09:22 AM 0
Share

Heh! You're probably right, I'm not very handy with this intertubes stuff ;)

Still, on my behalf, I said I'm in a tight schedule (3 days), so...

And, if such double answering would occur, I'd be sure to update both threads with the correct answer ...

Anyway, this Unity forums and community stuff (not to mention Unity itself) is really new to me, and it can get overwhel$$anonymous$$g. Sorry for the incorrectness :)

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

No one has followed this question yet.

Related Questions

How to handle side mirror reflections for a car? 2 Answers

Best option to create real mirrors in terms of performance 2 Answers

How to make a 'mirror' and/or 'portal'-like Shader Graph? 1 Answer

Adding a clip() to the default shader? 0 Answers

graphics look bad on iphone 2g 0 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