For example, I’ve this texture named _MyTex, how do I read a particular color(pixel)?
Sorry, Im kinda used to this img.GetPixel() thingy
need proper clarifications of concepts.
TIA.
For example, I’ve this texture named _MyTex, how do I read a particular color(pixel)?
Sorry, Im kinda used to this img.GetPixel() thingy
need proper clarifications of concepts.
TIA.
Assuming you are talking about Shaders (as suggested by the Shader tag and the underscore in front of the variable name), you can use the tex2D function. It takes a sampler2D as its first argument, and a float2 with uv coordinates as its second parameter. The uv coordinates range from 0 to 1.
half4 c=tex2D(_MyTex,float2(0.5,0.5));//Get the pixel at the middle of a texture.
I’m not sure what concepts you need clarifying about GetPixel() - it pretty much does what it says on the tin…
public var texture : Texture2D;
function Start () {
var c = texture.GetPixel(100,100);
Debug.Log("The pixel at 100,100 has RGB (" + c.r + "," + c.g + "," + c.b +")");
}
Thanks for the support, but I was talking about shaders. So, the above answer seems to be my answer :)
– DaKocha
Could you expand that clarification part a bit?
– ArkaneXGetPixeljust returns an instance of aPixelclass, having r,g,b,a + a few other properties, nothing fancy there...I'm so sorry, I'm talking about that GetPixel() in java/swing.. I even forgot what did it really return :/ clarification means.. well, something like a normal java GetPixel() to shader equivalent etc.
– DaKocha