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
0
Question by SARWAN · May 25, 2016 at 05:34 AM · shadertransparent shaderdouble-sided

LightingLambert': cannot implicitly convert from 'half3' to 'struct UnityGI'

Hi,

          I'm in the process of upgrading from unity 4.x to 5.x. I have got the following error in shader 

'LightingLambert': cannot implicitly convert from 'half3' to 'struct UnityGI I don't have much experience in shader. Did anyone faced this issue. or having solution to fix this issue??

Edit: I tried tweaking this shader but no use. Will you take look at it and correct it to work in unity 5.?? Here is the Full code:

 // Upgrade NOTE: commented out 'float4 unity_LightmapST', a built-in variable
 // Upgrade NOTE: commented out 'sampler2D unity_Lightmap', a built-in variable
 // Upgrade NOTE: commented out 'sampler2D unity_LightmapInd', a built-in variable
 // Upgrade NOTE: replaced tex2D unity_Lightmap with UNITY_SAMPLE_TEX2D
 // Upgrade NOTE: replaced tex2D unity_LightmapInd with UNITY_SAMPLE_TEX2D_SAMPLER
 
 Shader "Transparent/Cutout/Soft Edge Lit Double Sided" {
 Properties {
     _Color ("Main Color", Color) = (1,1,1,1)
     _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
     _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
 }
  
 SubShader {
     Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
     LOD 200
     Cull Off
  
     //   render the semitransparent details.
     Pass {
  
         // Dont write to the depth buffer
  
         Name "FORWARD"
         Tags { "LightMode" = "ForwardBase" }
         Blend SrcAlpha OneMinusSrcAlpha
         ZWrite off
  
 CGPROGRAM
 #pragma vertex vert_surf
 #pragma fragment frag_surf
 #pragma fragmentoption ARB_precision_hint_fastest
 #pragma multi_compile_fwdbasealpha
 #include "HLSLSupport.cginc"
 #include "UnityShaderVariables.cginc"
 #define UNITY_PASS_FORWARDBASE
 #include "UnityCG.cginc"
 #include "Lighting.cginc"
 #include "AutoLight.cginc"
  
 #define INTERNAL_DATA
 #define WorldReflectionVector(data,normal) data.worldRefl
 #define WorldNormalVector(data,normal) normal
 #line 1
 #line 12
  
  
 sampler2D _MainTex;
 fixed4 _Color;
  
 struct Input {
     float2 uv_MainTex;
 };
  
 void surf (Input IN, inout SurfaceOutput o) {
     fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
     o.Albedo = c.rgb;
     o.Alpha = c.a;
 }
 #ifdef LIGHTMAP_OFF
 struct v2f_surf {
   float4 pos : SV_POSITION;
   float2 pack0 : TEXCOORD0;
   fixed3 normal : TEXCOORD1;
   fixed3 vlight : TEXCOORD2;
   LIGHTING_COORDS(3,4)
 };
 #endif
 #ifndef LIGHTMAP_OFF
 struct v2f_surf {
   float4 pos : SV_POSITION;
   float2 pack0 : TEXCOORD0;
   float2 lmap : TEXCOORD1;
   LIGHTING_COORDS(2,3)
 };
 #endif
 #ifndef LIGHTMAP_OFF
 // float4 unity_LightmapST;
 #endif
 float4 _MainTex_ST;
 v2f_surf vert_surf (appdata_full v) {
   v2f_surf o;
   o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
   o.pack0.xy = TRANSFORM_TEX(v.texcoord, _MainTex);
   #ifndef LIGHTMAP_OFF
   o.lmap.xy = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
   #endif
   float3 worldN = mul((float3x3)_Object2World, SCALED_NORMAL);
   #ifdef LIGHTMAP_OFF
   o.normal = worldN;
   #endif
   #ifdef LIGHTMAP_OFF
   float3 shlight = ShadeSH9 (float4(worldN,1.0));
   o.vlight = shlight;
   #ifdef VERTEXLIGHT_ON
   float3 worldPos = mul(_Object2World, v.vertex).xyz;
   o.vlight += Shade4PointLights (
     unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0,
     unity_LightColor[0].rgb, unity_LightColor[1].rgb, unity_LightColor[2].rgb, unity_LightColor[3].rgb,
     unity_4LightAtten0, worldPos, worldN );
   #endif // VERTEXLIGHT_ON
   #endif // LIGHTMAP_OFF
   TRANSFER_VERTEX_TO_FRAGMENT(o);
   return o;
 }
 #ifndef LIGHTMAP_OFF
 // sampler2D unity_Lightmap;
 #ifndef DIRLIGHTMAP_OFF
 // sampler2D unity_LightmapInd;
 #endif
 #endif
 fixed4 frag_surf (v2f_surf IN) : COLOR {
   Input surfIN;
   surfIN.uv_MainTex = IN.pack0.xy;
   #ifdef UNITY_COMPILER_HLSL
   SurfaceOutput o = (SurfaceOutput)0;
   #else
   SurfaceOutput o;
   #endif
   o.Albedo = 0.0;
   o.Emission = 0.0;
   o.Specular = 0.0;
   o.Alpha = 0.0;
   o.Gloss = 0.0;
   #ifdef LIGHTMAP_OFF
   o.Normal = IN.normal;
   #endif
   surf (surfIN, o);
   fixed atten = LIGHT_ATTENUATION(IN);
   fixed4 c = 0;
   #ifdef LIGHTMAP_OFF
   c = LightingLambert (o, _WorldSpaceLightPos0.xyz, atten);
   #endif // LIGHTMAP_OFF
   #ifdef LIGHTMAP_OFF
   c.rgb += o.Albedo * IN.vlight;
   #endif // LIGHTMAP_OFF
   #ifndef LIGHTMAP_OFF
   #ifdef DIRLIGHTMAP_OFF
   fixed4 lmtex = UNITY_SAMPLE_TEX2D(unity_Lightmap, IN.lmap.xy);
   fixed3 lm = DecodeLightmap (lmtex);
   #else
   fixed4 lmtex = UNITY_SAMPLE_TEX2D(unity_Lightmap, IN.lmap.xy);
   fixed4 lmIndTex = UNITY_SAMPLE_TEX2D_SAMPLER(unity_LightmapInd,unity_Lightmap, IN.lmap.xy);
   half3 lm = LightingLambert_DirLightmap(o, lmtex, lmIndTex, 0).rgb;
   #endif
   #ifdef SHADOWS_SCREEN
   #if defined(SHADER_API_GLES) && defined(SHADER_API_MOBILE)
   c.rgb += o.Albedo * min(lm, atten*2);
   #else
   c.rgb += o.Albedo * max(min(lm,(atten*2)*lmtex.rgb), lm*atten);
   #endif
   #else // SHADOWS_SCREEN
   c.rgb += o.Albedo * lm;
   #endif // SHADOWS_SCREEN
   c.a = o.Alpha;
 #endif // LIGHTMAP_OFF
   c.a = o.Alpha;
   return c;
 }
  
 ENDCG
     } 
     Pass {
         Name "FORWARD"
         Tags { "LightMode" = "ForwardBase" }
         ColorMask RGB
 CGPROGRAM
 #pragma vertex vert_surf
 #pragma fragment frag_surf
 #pragma fragmentoption ARB_precision_hint_fastest
 #pragma multi_compile_fwdbase
 #include "HLSLSupport.cginc"
 #include "UnityShaderVariables.cginc"
 #define UNITY_PASS_FORWARDBASE
 #include "UnityCG.cginc"
 #include "Lighting.cginc"
 #include "AutoLight.cginc"
  
 #define INTERNAL_DATA
 #define WorldReflectionVector(data,normal) data.worldRefl
 #define WorldNormalVector(data,normal) normal
 #line 1
 #line 65
  
 sampler2D _MainTex;
 fixed4 _Color;
  
 struct Input {
     float2 uv_MainTex;
 };
  
 void surf (Input IN, inout SurfaceOutput o) {
     fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
     o.Albedo = c.rgb;
     o.Alpha = c.a;
 }
 #ifdef LIGHTMAP_OFF
 struct v2f_surf {
   float4 pos : SV_POSITION;
   float2 pack0 : TEXCOORD0;
   fixed3 normal : TEXCOORD1;
   fixed3 vlight : TEXCOORD2;
   LIGHTING_COORDS(3,4)
 };
 #endif
 #ifndef LIGHTMAP_OFF
 struct v2f_surf {
   float4 pos : SV_POSITION;
   float2 pack0 : TEXCOORD0;
   float2 lmap : TEXCOORD1;
   LIGHTING_COORDS(2,3)
 };
 #endif
 #ifndef LIGHTMAP_OFF
 // float4 unity_LightmapST;
 #endif
 float4 _MainTex_ST;
 v2f_surf vert_surf (appdata_full v) {
   v2f_surf o;
   o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
   o.pack0.xy = TRANSFORM_TEX(v.texcoord, _MainTex);
   #ifndef LIGHTMAP_OFF
   o.lmap.xy = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
   #endif
   float3 worldN = mul((float3x3)_Object2World, SCALED_NORMAL);
   #ifdef LIGHTMAP_OFF
   o.normal = worldN;
   #endif
   #ifdef LIGHTMAP_OFF
   float3 shlight = ShadeSH9 (float4(worldN,1.0));
   o.vlight = shlight;
   #ifdef VERTEXLIGHT_ON
   float3 worldPos = mul(_Object2World, v.vertex).xyz;
   o.vlight += Shade4PointLights (
     unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0,
     unity_LightColor[0].rgb, unity_LightColor[1].rgb, unity_LightColor[2].rgb, unity_LightColor[3].rgb,
     unity_4LightAtten0, worldPos, worldN );
   #endif // VERTEXLIGHT_ON
   #endif // LIGHTMAP_OFF
   TRANSFER_VERTEX_TO_FRAGMENT(o);
   return o;
 }
 #ifndef LIGHTMAP_OFF
 // sampler2D unity_Lightmap;
 #ifndef DIRLIGHTMAP_OFF
 // sampler2D unity_LightmapInd;
 #endif
 #endif
 fixed _Cutoff;
 fixed4 frag_surf (v2f_surf IN) : COLOR {
   Input surfIN;
   surfIN.uv_MainTex = IN.pack0.xy;
   #ifdef UNITY_COMPILER_HLSL
   SurfaceOutput o = (SurfaceOutput)0;
   #else
   SurfaceOutput o;
   #endif
   o.Albedo = 0.0;
   o.Emission = 0.0;
   o.Specular = 0.0;
   o.Alpha = 0.0;
   o.Gloss = 0.0;
   #ifdef LIGHTMAP_OFF
   o.Normal = IN.normal;
   #endif
   surf (surfIN, o);
   clip (o.Alpha - _Cutoff);
   fixed atten = LIGHT_ATTENUATION(IN);
   fixed4 c = 0;
   #ifdef LIGHTMAP_OFF
   c = LightingLambert (o, _WorldSpaceLightPos0.xyz, atten);
   #endif // LIGHTMAP_OFF
   #ifdef LIGHTMAP_OFF
   c.rgb += o.Albedo * IN.vlight;
   #endif // LIGHTMAP_OFF
   #ifndef LIGHTMAP_OFF
   #ifdef DIRLIGHTMAP_OFF
   fixed4 lmtex = UNITY_SAMPLE_TEX2D(unity_Lightmap, IN.lmap.xy);
   fixed3 lm = DecodeLightmap (lmtex);
   #else
   fixed4 lmtex = UNITY_SAMPLE_TEX2D(unity_Lightmap, IN.lmap.xy);
   fixed4 lmIndTex = UNITY_SAMPLE_TEX2D_SAMPLER(unity_LightmapInd,unity_Lightmap, IN.lmap.xy);
   half3 lm = LightingLambert_DirLightmap(o, lmtex, lmIndTex, 0).rgb;
   #endif
   #ifdef SHADOWS_SCREEN
   #if defined(SHADER_API_GLES) && defined(SHADER_API_MOBILE)
   c.rgb += o.Albedo * min(lm, atten*2);
   #else
   c.rgb += o.Albedo * max(min(lm,(atten*2)*lmtex.rgb), lm*atten);
   #endif
   #else // SHADOWS_SCREEN
   c.rgb += o.Albedo * lm;
   #endif // SHADOWS_SCREEN
   c.a = o.Alpha;
 #endif // LIGHTMAP_OFF
   c.a = o.Alpha;
   return c;
 }
  
 ENDCG 
 }
 }
 Fallback "Transparent/Cutout/VertexLit"
 }

[1]: /storage/temp/70707-capture.png

capture.png (15.0 kB)
Comment
Add comment · Show 4
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 MaT227 · May 25, 2016 at 05:40 AM 0
Share

Hi, could you tell a bit more about what you are trying to achieve ? It seems that you are using a surface shader but I don't get the point of you vertex function.

Try to take a look at the documentation on how to build such type of shader in Unity 5 as there are a bit different from Unity 4.

Take also a look at Unity built-in shaders this is necessary if you want to understand how to build shaders as everything is not told on the documentation.

I would also suggest to post the whole shader code if it's not too long.

avatar image SARWAN MaT227 · May 25, 2016 at 06:01 AM 0
Share

Thanks for the reply. I will look into it.

avatar image SARWAN MaT227 · May 25, 2016 at 06:03 AM 0
Share

Actually, I'm trying for the double sided transparent which works fine in Unity 4.x to Upgrading to Unity 5 having the error.

avatar image MaT227 · May 25, 2016 at 07:28 AM 2
Share

If you are just willing to add double sided transparency, I'll would suggest you to take a Unity 5 built-in shader as base then add your changes such as : Cull Off and other optional parameters.

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

60 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

Related Questions

transparent mode does not work at alpha=255 1 Answer

How to cut or make transparent part of a mesh 0 Answers

Standard Shader - Transparent/Fade Issue 6 Answers

Problems with two sided textured shader 3 Answers

Sorting semi-transparent pixels 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