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
1
Question by Gunder · Jan 19, 2010 at 10:22 AM · shadercustom-shader

Mirror + Shadows shader.

I'm trying to make a floor with a wood texture and a reflection. It's works for my using the mirror reflection shader from Unity Community. But, i need to include shadows and i don't have idea how to do it. 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

5 Replies

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

Answer by Gunder · Jan 19, 2010 at 04:25 PM

I got it, only modify the shader:

Shader "FX/Mirror Reflection" { 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) = "_Skybox" { TexGen ObjectLinear } } SubShader { LOD 200 Tags { "RenderType"="Opaque" } Pass { Name "BASE" Tags {"LightMode" = "Always"} CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma fragmentoption ARB_fog_exp2 #pragma fragmentoption ARB_precision_hint_fastest #include "UnityCG.cginc"

     struct v2f {
         V2F_POS_FOG;
         float2 uv : TEXCOORD0;
         float3 uv2 : TEXCOORD1;
     };

     uniform float4 _MainTex_ST;
     uniform float3x3 _ProjMatrix;

     v2f vert(appdata_tan v)
     {
         v2f o;
         PositionFog( v.vertex, o.pos, o.fog );
         float3 viewDir = ObjSpaceViewDir( v.vertex );
         o.uv2 = mul( _ProjMatrix, viewDir );
         o.uv = TRANSFORM_TEX(v.texcoord,_MainTex);
         return o; 
     }

     uniform sampler2D _MainTex;
     uniform sampler2D _ReflectionTex;
     uniform float4 _ReflectColor;

     half4 frag (v2f i) : COLOR
     {
         half4 texcol = tex2D (_MainTex, i.uv);
         half4 reflcol = tex2Dproj( _ReflectionTex, i.uv2 ) * 2;
         reflcol *= _ReflectColor.a;
         return reflcol * _ReflectColor;
     } 
     ENDCG
 }

 UsePass "Diffuse/PPL"

} FallBack "Reflective/VertexLit", 1

}

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 Kurylo3d.du · Jun 11, 2010 at 02:08 PM

your shader doesnt seem to work like the original mirror shader does... I cant get it to reflect anything.

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 Wahooney · Aug 15, 2010 at 02:56 PM

Same, it seems only my sky colour gets reflected.

Edit: I hacked this together from your mirror code and the water code that comes with unity pro, it seems to work well on my side.

Shader "FX/Mirror Reflection" { 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" {} _ReflDistort ("Reflection distort", Range (0,1.5)) = 0.44 _ReflectionTex ("Reflection", 2D) = "white" { TexGen ObjectLinear } }

 SubShader
 {
     LOD 200
     Tags { "RenderType"="Opaque" }
     Pass { 
         Name "BASE"
         Tags {"LightMode" = "Always"}
         CGPROGRAM
         #pragma vertex vert
         #pragma fragment frag
         #pragma fragmentoption ARB_fog_exp2
         #pragma fragmentoption ARB_precision_hint_fastest
         #include "UnityCG.cginc"

         uniform float4 _MainTex_ST;
         uniform float3x3 _ProjMatrix;

         struct appdata {
             float4 vertex : POSITION;
             float3 normal : NORMAL;
             float2 texcoord : TEXCOORD1;
         };            

         struct v2f {
             V2F_POS_FOG;
             float3 ref;
             float2 uv;
             float3 viewDir;
         };

         v2f vert(appdata v)
         {
             v2f o;
             PositionFog( v.vertex, o.pos, o.fog );

             // object space view direction (will normalize per pixel)
             o.viewDir.xzy = ObjSpaceViewDir(v.vertex);

             // calculate the reflection vector
             float3x4 mat = float3x4 (
                 0.5, 0, 0, 0.5,
                 0, 0.5 * _ProjectionParams.x, 0, 0.5,
                 0, 0, 0, 1
             );    
             o.ref = mul (mat, o.pos);
             o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);

             return o;
         }

         uniform sampler2D _MainTex;
         uniform sampler2D _ReflectionTex;
         uniform float4 _ReflectColor;
         uniform float _ReflDistort;

         half4 frag (v2f i) : COLOR
         {
             half4 texcol = tex2D (_MainTex, i.uv);

             float3 uv2 = i.ref; 
             half4 reflcol = tex2Dproj( _ReflectionTex, uv2 ) * 1;
             reflcol *= _ReflectColor.a;
             return reflcol * _ReflectColor;
         } 
         ENDCG
     }

     UsePass "Diffuse/PPL"
 }

 FallBack "Reflective/VertexLit", 1

}

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 tamalive · Jul 25, 2011 at 04:54 AM

I don't know why this not work on my PC. Can you help me ?

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 dumbbaby · Nov 25, 2013 at 06:34 PM 0
Share

Did you solve this problem?

avatar image
0

Answer by dahooo2 · May 14, 2012 at 05:12 PM

Hello, I would like to pass a matrix 4x4 to my shader from my csharp script. In my shader I put in the CGPROGRAM part :

 uniform float3x3 _ProjMatrix;

And in my script I put :

 mat.SetMatrix( "_ProjMatrix", mtx );

If I use a shaderLab shader I can access it doing :

 matrix [_ProjMatrix]

But in a vertex, fragment shader I cannot acces it.

Can you help me plase? In your shader, how do you supply _ProjMatrix?

Thanks.

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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Better shader effects on terrain - Bumpmapping or Specular? 2 Answers

Teeth Shader 1 Answer

Passing variables from Script to a Shader 2 Answers

HDRP Change color on touch ground on a custom pass shader 0 Answers

Hologram emitter effect only using shader (2D on single triangle) 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