How would I program this shader?

So what I want to do is, a shader where each triangle has a texture inside of it.

So what I was thinking of doing was, somehow using the vertices positions, to get x-y coordinates to sample the texture.

Something like this:
3017616--225335--upload_2017-4-3_13-26-54.png

Your plan will work. You can make UV’s out of anything and then supply them in your tex2D(blahblah, myCustomUVs) sample.

World position, screen position, etc are all fair game.

So here I have a really basic sprite shader, that I think I could use as a base for what I want.

I chose a sprite shader as a base, because well my game is in 2d, and pretty much everything I have in the game is a sprite ( so my guess is, this will avoid some depth-transparency issues etc).

I also commented out some of the code that this shader wont use it.

Shader "Unlit/Celestial-Body"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
    }
    
SubShader {
        Tags{
        "Queue" = "Transparent"
        "IgnoreProjector" = "True"
        "RenderType" = "Transparent"
        "PreviewType" = "Plane"
        "CanUseSpriteAtlas" = "True"
    }

        Cull Off
        Lighting Off
        ZWrite Off
        Blend One OneMinusSrcAlpha

        Pass{
        CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#pragma multi_compile _ ETC1_EXTERNAL_ALPHA
#include "UnityCG.cginc"

    struct appdata_t {
        float4 vertex   : POSITION;
        //float4 color    : COLOR; I wont use color ( for now atleast)
        float2 texcoord : TEXCOORD0;
        UNITY_VERTEX_INPUT_INSTANCE_ID
    };

    struct v2f {
        float4 vertex   : SV_POSITION;
        //fixed4 color : COLOR; I wont use color ( for now atleast)
        float2 texcoord  : TEXCOORD0;
        UNITY_VERTEX_OUTPUT_STEREO
    };

    fixed4 _Color;

    v2f vert(appdata_t IN) {
        v2f OUT;
        UNITY_SETUP_INSTANCE_ID(IN);
        UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
        OUT.vertex = UnityObjectToClipPos(IN.vertex);
        OUT.texcoord = IN.texcoord;
        //OUT.color = IN.color * _Color; I wont use color ( for now atleast)

        return OUT;
    }

    sampler2D _MainTex;

    fixed4 SampleSpriteTexture(float2 uv)
    {
        fixed4 color = tex2D(_MainTex, uv);

        // Removed the alpha thing, because I wont use transparency in this shader

        return color;
    }

    fixed4 frag(v2f IN) : SV_Target{
        fixed4 c = SampleSpriteTexture(IN.texcoord);// *IN.color; I wont use color ( for now atleast)

        //c.rgb *= c.a; // This shader wont use transparency so I dont use alpha

        return c;
    }
        ENDCG
    }
    }
}

Now what I would need to figure out is, how to get the texture coordinates from the triangles…

If your triangles object-space vertex positions are normal to their center (xy ranging from -0.5 to 0.5 with the origin at the center), then you can just shift them into UV space and pass them to your fragment shader.

// shift object-space positions to (0-1) UV coordinates
OUT.texcoord = IN.vertex.xy + 0.5;

If your range differs, perhaps -1 to 1 then you’ll need to scale them to the normalized range. In this case, you’d divide them by 2.

 // scale and shift object-space positions to (0-1) UV coordinates
OUT.texcoord = IN.vertex.xy * 0.5 + 0.5;