#Changing the surface color of a Gameobject

1 messages · Page 1 of 1 (latest)

small citrus
#

I'm trying to color the side of a clue in the color red when it's clicked. As seen in the picture, the left cube is showing the front surface as being colored red, but the right cube is kind of transparent/see-through, and isn't showing up correctly. I think it's because of the material being used, but I can't find one that works correctly.

Any ideas on how to fix this?

vivid lintel
#

How are you doing this ?
Are you changing the vertex color of the cube or something like this ?
If it is the case like I'm guessing, the sprite default shader which renders as a transparent material will not sort the faces based on depth, and just render them as is, overwriting "older" ones, which in this case is probably the red one.

#

If you specifically want to change the color of a face of the cube, the easiest is probably to split the cube into 6 sub meshes and change the material per face.

small citrus
#

Although it overwrites, I have the script saving the current vertex colors, and only overwriting one side.

small citrus
vivid lintel
#

If you want to stick to using the vertex color method, you'll need a acustom shader that renders it.

vivid lintel
small citrus
#

I'll try using a material with a custom shader first. Give me a bit.

#

Well that works...

#

Thank you so much

small citrus
#

I'm now trying to color the vertex surface/side of another cube, which I think uses a shared mesh, and it doesn't work. Any ideas?

vivid lintel
#

You should share a bit the code used to change the color of the cube at that point, because if the shader is working on a cube but not on an other one, the vertex color is probably the issue.

small citrus
#

I'm trying to see if I can use ProBuilder to make a Cube into a ramp, and see if I can color it.

#

I believe this is working for me. As I made a cube into a ramp, and can color it fine.

small citrus
#

I'm trying to figure out and fix the issue seen in the picture, with the prism being a dark side, which I can't change the color of.

I'm using ProBuilder to create basic shapes, such as changing the vertex's of this cube to a prism.

I am also using a custom shader as a material on them, which is white and allows light and shadow.

Both gameobjects are the same, except that the prism has the modified vertex's.

Any idea why the prisms side is black, and how to fix it?

vivid lintel
#

It would help if you could share also the custom shader used to understand.
I might me some lack of ambient lighting.

small citrus
#
Shader "Custom/White2"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        #pragma surface surf Standard fullforwardshadows

        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
            float4 color : COLOR;
        };

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
            o.Albedo = tex.rgb * IN.color.rgb;
            o.Alpha = tex.a * IN.color.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}
vivid lintel
#

And, it's not caused by the vertex color, like, if you remove the vertex color influence in the shader and only output pure white in albedo, it's still dark on one side ?

#

It could be that it's the normal of the mesh that causes bad lighting

rough lynx
#

Changing the one material of a mesh renderer is the first logical step to changing one of many material slots
A submesh / material slot is created when a new material is assigned to specific polygons of a mesh