- Home /
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