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 rocksvick · May 14, 2012 at 12:51 PM · shadertransparencytagspass

Different behavious of shader in unity's build in simulator and ios device

Hello

I am trying to draw object on plane , i have used the shader . shader is working fine on Unit's simulator but when i make a build for ios device and run that code on device object on plane is not being drawn properly . Below is the shader i am using .Anyone having idea, whats wrong ?

Shader "GLSL planar shadow_Texture" { Properties {

   _ShadowTex ("Shadow Image", 2D) = "white" {} 
   
   }

SubShader { Tags { "Queue" = "Transparent" }

   Pass {   
      Tags { "LightMode" = "ForwardBase" } 


          
         // rendering of projected shadow
      Offset -1.0, -2.0 
      
      ZWrite Off // don't occlude other objects
      Blend SrcAlpha OneMinusSrcAlpha
     
         // make sure shadow polygons are on top of shadow receiver
         
 
      GLSLPROGRAM
      
      uniform sampler2D _ShadowTex;  
 
      varying vec4 textureCoordinates_shadow; 
 
      // User-specified uniforms
      uniform vec4 _ShadowColor;
      uniform mat4 _World2Receiver; // set by script
          
          
      uniform vec3 _WorldSpaceCameraPos; 

// // camera position in world space // uniform mat4 _Object2World; // model matrix // uniform mat4 _World2Object; // inverse model matrix // // (apart from the factor unity_Scale.w)

      varying vec3 varyingNormalDirection; 
         // normalized surface normal vector
      varying vec3 varyingViewDirection; 
         // normalized view direction 
         
         
      // The following built-in uniforms ) 
      // are also defined in "UnityCG.glslinc", 
      // i.e. one could #include "UnityCG.glslinc" 
      uniform mat4 _Object2World; // model matrix
      uniform mat4 _World2Object; // inverse model matrix
      uniform vec4 unity_Scale; // w = 1/uniform scale; 
         // should be multiplied to _World2Object 
      uniform vec4 _WorldSpaceLightPos0; 
         // position or direction of light source
 
      #ifdef VERTEX
 
      void main()
      {            
      
          textureCoordinates_shadow = gl_MultiTexCoord0;
          
         mat4 modelMatrix = _Object2World;
         mat4 modelMatrixInverse = _World2Object * unity_Scale.w;
         modelMatrixInverse[3][3] = 1.0; 
         mat4 viewMatrix = gl_ModelViewMatrix * modelMatrixInverse;
         
         //  soft shadow 
         varyingNormalDirection = normalize(
            vec3(vec4(gl_Normal, 0.0) * modelMatrixInverse));
         varyingViewDirection = normalize(_WorldSpaceCameraPos 
            - vec3(modelMatrix * gl_Vertex));
         
 
         vec4 lightDirection;
         if (0.0 != _WorldSpaceLightPos0.w) 
         {
            // point or spot light
            lightDirection = normalize(
               modelMatrix * gl_Vertex - _WorldSpaceLightPos0);
         } 
         else 
         {
            // directional light
            lightDirection = -normalize(_WorldSpaceLightPos0); 
         }
 
         vec4 vertexInWorldSpace = modelMatrix * gl_Vertex;
         vec4 world2ReceiverRow1 = 
            vec4(_World2Receiver[0][1], _World2Receiver[1][1], 
            _World2Receiver[2][1], _World2Receiver[3][1]);
         float distanceOfVertex = 
            dot(world2ReceiverRow1, vertexInWorldSpace); 
            // = (_World2Receiver * vertexInWorldSpace).y 
            // = height over plane 
         float lengthOfLightDirectionInY = 
            dot(world2ReceiverRow1, lightDirection); 
            // = (_World2Receiver * lightDirection).y 
            // = length in y direction
 
         if (distanceOfVertex > 0.0 && lengthOfLightDirectionInY < 0.0)
         {
            lightDirection = lightDirection 
               * (distanceOfVertex / (-lengthOfLightDirectionInY));
         }
         else
         {
            lightDirection = vec4(0.0, 0.0, 0.0, 0.0); 
               // don't move vertex
         }
 
         gl_Position = gl_ProjectionMatrix * (viewMatrix 
            * (vertexInWorldSpace + lightDirection));
      }
 
      #endif
 
      #ifdef FRAGMENT
 
      void main()
      {
          
          
      
          
          gl_FragColor = 
            texture2D(_ShadowTex, vec2(textureCoordinates_shadow));
          

// gl_FragColor = _ShadowColor;

      }
 
      #endif
 
      ENDGLSL
   }

} }

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Can I make any parts of an object inside a partially transparent object fully invisible? 1 Answer

Is it possible to get back data for a specific vertex from a shader ? 0 Answers

shader Transparency 1 Answer

Effects Process after Opaque queue before Transparency? 0 Answers

Cant get Alpha Channel to Work with Custom 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