I want to access the texture “G” in my shader, and use it as a sampler 2D, so that I can access the RGBA values in my shader: how can I make sure I can use this texture G in my shader? In this case, both my shader and the create texture script (texture G) are attached to the same gameObject.
//Forexample, create the following Texture G
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class calculator : MonoBehaviour {
// Use this for initialization
void Start () {
Texture2D G = new Texture2D(128, 128);
GetComponent<Renderer>().material.mainTexture = G;
for (int y = 0; y < G.height; y++)
{
for (int x = 0; x < G.width; x++)
{
Color color = ((x & y) != 0 ? Color.white : Color.gray);
G.SetPixel(x, y, color);
}
}
G.Apply();
}
// Update is called once per frame
void Update () {
}
}
https://docs.unity3d.com/ScriptReference/Material.SetTexture.html
– donutLaserDev