While generating Face Objects - What shader to use to get them appear 0.5f alpha?
Been trying find ways to add alpha value 0.333f or so but I have been having problems of many kinds. I wish there was easy way of doing this. Component where this script, part of it is doesn't have renderers or anything like that added - instead created from scratch since the "generation" script that I can use from editor view.
I am not sure what shader to look for that has alpha value - Shader.Find("what path?"); Been having hard times finding any info from which paths these shaders can be found in code.
GameObject GenerateFaceObject(BSPFace face)
{
GameObject faceObject = new GameObject("BSPface");
faceObject.transform.parent = gameObject.transform;
Mesh faceMesh = new Mesh();
faceMesh.name = "BSPmesh";
// grab our verts
Vector3[] verts = new Vector3[face.num_ledges];
int edgestep = face.ledge_index;
for (int i = 0; i < face.num_ledges; i++)
{
if (map.edgeLump.ledges[face.ledge_index + i] < 0)
{
verts[i] = map.vertLump.verts[map.edgeLump.edges[Mathf.Abs(map.edgeLump.ledges[edgestep])].vert1];
}
else
{
verts[i] = map.vertLump.verts[map.edgeLump.edges[map.edgeLump.ledges[edgestep]].vert2];
}
edgestep++;
}
// whip up tris
int[] tris = new int[(face.num_ledges - 2) * 3];
int tristep = 1;
for (int i = 1; i < verts.Length - 1; i++)
{
tris[tristep - 1] = 0;
tris[tristep] = i;
tris[tristep + 1] = i + 1;
tristep += 3;
}
// whip up uvs
float scales = map.miptexLump.textures[map.texinfoLump.texinfo[face.texinfo_id].miptex].width * 0.03f;
float scalet = map.miptexLump.textures[map.texinfoLump.texinfo[face.texinfo_id].miptex].height * 0.03f;
Vector2[] uvs = new Vector2[face.num_ledges];
for (int i = 0; i < face.num_ledges; i++)
{
uvs[i] = new Vector2((Vector3.Dot(verts[i], map.texinfoLump.texinfo[face.texinfo_id].vec3s) + map.texinfoLump.texinfo[face.texinfo_id].offs) / scales, (Vector3.Dot(verts[i], map.texinfoLump.texinfo[face.texinfo_id].vec3t) + map.texinfoLump.texinfo[face.texinfo_id].offt) / scalet);
}
faceMesh.vertices = verts;
faceMesh.triangles = tris;
faceMesh.uv = uvs;
faceMesh.RecalculateNormals();
faceObject.AddComponent<MeshFilter>();
faceObject.GetComponent<MeshFilter>().mesh = faceMesh;
faceObject.AddComponent<MeshRenderer>();
// We make a material and then use shared material to work around a leak in the editor
Material mat;
if (lightMapsEnabled)
{
// Lightmap wankery
mat = new Material(Shader.Find("Legacy Shaders/Lightmapped/Diffuse"));
int pointer = face.lightmap;
if (pointer != -1)
{
int size = 10;
Texture2D lightmap = new Texture2D(size, size);
Color[] colors = new Color[size * size];
for (int i = 0; i < size * size; i++)
{
if (i >= map.lightLump.RawMaps.Length)
break;
var temp = map.lightLump.RawMaps[pointer + i];
colors[i] = new Color32(temp, temp, temp, 255);
}
lightmap.SetPixels(colors);
mat.SetTexture("_LightMap", lightmap);
}
}
else
{
mat = new Material(Shader.Find("Diffuse"));
}
// Set the texture we made above, after possible lightmapping circlejerk
mat.mainTexture = map.miptexLump.textures[map.texinfoLump.texinfo[face.texinfo_id].miptex];
/*
mat.SetOverrideTag("RenderType", "");
mat.SetInt("_SrcBlend", (int) UnityEngine.Rendering.BlendMode.One);
mat.SetInt("_DstBlend", (int) UnityEngine.Rendering.BlendMode.Zero);
mat.SetInt("_ZWrite", 1);
mat.DisableKeyword("_ALPHATEST_ON");
mat.DisableKeyword("_ALPHABLEND_ON");
mat.DisableKeyword("_ALPHAPREMULTIPLY_ON");
mat.renderQueue = -1;
*/
///*
mat.SetOverrideTag("RenderType", "Transparent");
mat.SetInt("_SrcBlend", (int) UnityEngine.Rendering.BlendMode.SrcAlpha);
mat.SetInt("_DstBlend", (int) UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
mat.SetInt("_ZWrite", 0);
mat.DisableKeyword("_ALPHATEST_ON");
mat.EnableKeyword("_ALPHABLEND_ON");
mat.DisableKeyword("_ALPHAPREMULTIPLY_ON");
mat.renderQueue = (int) UnityEngine.Rendering.RenderQueue.Transparent;
//*/
mat.SetColor("_Color", new Color (1f, 1f, 1f, 0.333f));
// Set the material
faceObject.GetComponent<Renderer>().sharedMaterial = mat;
// Turn off the renderer if the face is part of a trigger brush
string texName = map.miptexLump.textures[map.texinfoLump.texinfo[face.texinfo_id].miptex].name;
if (texName == "trigger")
{
faceObject.GetComponent<Renderer>().enabled = false;
}
// Skip any textures that show a sky, if we want
if (skipSky && texName.StartsWith("sky"))
faceObject.GetComponent<Renderer>().enabled = false;
faceObject.AddComponent<MeshCollider>();
faceObject.isStatic = true;
return faceObject;
}
#endregion
Your answer
Follow this Question
Related Questions
How to get pixel color back during game play,How to get pixel color during game play 0 Answers
What is wrong with my script to change shader on all GameObjects? 1 Answer
Tint Multiple Textures Separately 1 Answer
Error with Bolt on 2021.1.0f1 0 Answers
Shader makes other objects transparent aswell,Shader Makes everything transparent 0 Answers