- Home /
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
}
}
}
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)
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!
So you want the material to have both a baked lightmap and to be affected by realtime lighting?
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.
Your answer
Follow this Question
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