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 raziel999 · Apr 03, 2015 at 10:11 AM · shaderlightmapblending

Custom Shader, doesn`t receive Light "Blend3TextureBase"

Hello! I have a custom shader, thats blending 3 textures, 2 Textures and one LightMap.

The problem, is that this shader doesn`t receive light. I tryed 2 days to modify it, but when i try to add #pragma surface surf lambert, it tells me that "#pragma surface does not allow specifying other programs at line".

I can`t use another shader, because after the map will be very ugly. I will attach here the shader code, maybe someone can tell me how to edit it.

Thank you!

 Shader "Marius/BlendTexturBase" {
 Properties {
 
     _MainTex ("Texture 1", 2D) = "white" { }
     _SecTex ("Texture 2", 2D) = "white" { }
     
     _LightMap ("Lightmap", 2D) = "white" { }
     _LightIntensity ("Lightmap Intensity", Float) = 1.0
 }
 SubShader {
     Tags { "Queue"="Geometry" "IgnoreProjectors"="True" "RenderType"="Opaque" }
      LOD 300
     Pass {
     
 CGPROGRAM
 #pragma vertex vert
 #pragma fragment frag
 #pragma exclude_renderers d3d11 xbox360 ps3 flash 
 #pragma fragmentoption ARB_precision_hint_fastest
 #pragma glsl_no_auto_normalization 
 #include "UnityCG.cginc"
 
 sampler2D _MainTex;
 sampler2D _LightMap;
 sampler2D _SecTex;
 
 fixed _LightIntensity;
 fixed _SliderTexture;
  
 
 
 struct a2f 
 {
     float4 vertex : POSITION; 
     float2 uv_main : TEXCOORD0;
     float2 uv_light : TEXCOORD1;
 
 }; 
 
 struct v2f 
 {
     float4 vertex : SV_POSITION;
     float2 uv_main : TEXCOORD0;
     float2 uv_light : TEXCOORD1;
     float2 uv_sec : TEXCOORD2;
 
 };
 
 
 uniform float4 _MainTex_ST; 
 uniform float4 _SecTex_ST;
 
 
 
 v2f vert (a2f v)
 {
 
     v2f o;
     
     o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
     o.uv_light = v.uv_light;
     
      o.uv_main = TRANSFORM_TEX (v.uv_main, _MainTex);
      o.uv_sec = TRANSFORM_TEX (v.uv_main, _SecTex);
     
     return o;
 }
  
 
 fixed4 frag( v2f i ) : COLOR
 {
     float4 main = tex2D (_MainTex, i.uv_main);
     float4 sec = tex2D (_SecTex, i.uv_sec); 
     
     float4 light = tex2D (_LightMap, i.uv_light);
     float4 main2 = lerp (main , sec,  light.a);
     
     
     return main2 * light * _LightIntensity;
 }
 
 
 ENDCG
     }
 } 
 }
 

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 tanoshimi · Apr 03, 2015 at 10:13 AM 0
Share

This is a vert/frag shader. Are you trying to rewrite the whole thing as a surface shader? (the easiest way to incorporate lighting, but you lose some flexibility) Or are you trying to add lighting calculations into the vert/frag structure? (more complicated but more powerful - you might want to read http://en.wikibooks.org/wiki/Cg_Program$$anonymous$$g/Unity/$$anonymous$$ultiple_Lights)

avatar image raziel999 · Apr 03, 2015 at 10:57 AM 0
Share

tanoshimi , i`m not good at writing shaders, i am good at C# only. I understand very less the Shader code. If you can help me at adding light in this shader, i will give you a bonus. Add me on skype please: sat.angel666 I will show you exacly what i want exacly.

Thanks!

avatar image tanoshimi · Apr 03, 2015 at 01:10 PM 0
Share

So you want the material to have both a baked lightmap and to be affected by realtime lighting?

avatar image raziel999 · Apr 03, 2015 at 01:37 PM 0
Share

Well, i have 2 Texture, and 1 Lightmap Texture.

I need them to be affected by Light (Pointlight,dirrection light). If i select Diffuse shader, the image will be very simple, and bad looking, but will accept light. I will attack 2 pictures, one with my custom shader, and one with diffuse shader.

https://www.dropbox.com/s/6ai2epm0tur5e1p/BumpedDiffuse.png?dl=0

https://www.dropbox.com/s/6bk9p7fg6yw3ant/CustomShader%20BlendingTextures.png?dl=0

https://www.dropbox.com/s/2my4z33xc8w6tcy/CustomShaderBlendingTexture2.png?dl=0

Thanks! Hope you will understand.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Logical BlendOp not working 0 Answers

cast shadow - export lightmap from 3ds max to unity 2 Answers

Alpha blending with more than one pass 0 Answers

Terrain texture pixelated,Terrain texture pixelated on mali400 1 Answer

bake error 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