- Home /
Double side texture, data retrived from binary file
Hey guys,
I've got loaded image (parsed binary data, byte by byte) into Texture2D object. Also I'm using double side shader which I found somewhere in the Internet. When I'm testing if image is loaded correctly by GUI.DrawTexture(), everything looks right. Sadly to said, Unity renders black color on plane instead of my texture.
Plane class:
public class Plane
{
public Mesh mesh;
public Texture texture;
...
Texture setup:
MeshFilter meshFilter = plane.GetComponent<MeshFilter> () as MeshFilter;
meshFilter.mesh = planeObj.mesh;
MeshRenderer renderer = plane.GetComponent<MeshRenderer>() as MeshRenderer;
renderer.material = new Material (Shader.Find ("Custom/DoubleSide"));
if (planeObj.texture != null) {
renderer.material.mainTexture = planeObj.texture;
//renderer.material.SetTexture("MainTexture", planeObj.texture);
renderer.material.shader = Shader.Find ("Custom/DoubleSide");
}
Shader:
Shader "Custom/DoubleSide" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
//_BumpMap ("Bump (RGB) Illumin (A)", 2D) = "bump" {}
}
SubShader {
//UsePass "Self-Illumin/VertexLit/BASE"
//UsePass "Bumped Diffuse/PPL"
// Ambient pass
Pass {
Name "BASE"
Tags {"LightMode" = "Always" /* Upgrade NOTE: changed from PixelOrNone to Always */}
Color [_PPLAmbient]
SetTexture [_BumpMap] {
constantColor (.5,.5,.5)
combine constant lerp (texture) previous
}
SetTexture [_MainTex] {
constantColor [_Color]
Combine texture * previous DOUBLE, texture*constant
}
}
// Vertex lights
Pass {
Name "BASE"
Tags {"LightMode" = "Vertex"}
Material {
Diffuse [_Color]
Emission [_PPLAmbient]
Shininess [_Shininess]
Specular [_SpecColor]
}
SeparateSpecular On
Lighting On
Cull Off
SetTexture [_BumpMap] {
constantColor (.5,.5,.5)
combine constant lerp (texture) previous
}
SetTexture [_MainTex] {
Combine texture * previous DOUBLE, texture*primary
}
}
}
FallBack "Diffuse", 1
}
Can anyone help me? I don't know if this is shader problem or just I'm missing some setting method.
What's weird, that renderer.material.SetTexture("MainTexture", planeObj.texture); makes my plane invisible.
What about material.SetTexture("_$$anonymous$$ainTex", planeObj.texture);
?
Still nothing. I'm checking material/shader preview, just at the bottom of inspector. That sphere has my texture, but it's rotated about 90degrees. Anyway my plane is still black. I think it's a problem related with my shader.
Is there some fitting/uv mapping needed?