- Home /
Draw triangles on texture
What's the best way to draw a triangle (with a specific uv) from a texture on another texture? I know I could use SetPixel, but this would mean that I would have to iterate over the pixels and apply a transformation matrix on each point to get the source texture's pixel position. Is there a better way to do this? Maybe using GL and draw the results to a texture?
Thanks!
"draw a triangle (with a specific uv) from a texture on another texture" confuses me. Please clarify.
Answer by Peter G · Jan 30, 2011 at 12:38 AM
It sounds like you want to do that in a shader, if the texture is not going to change any at any point in your game, you might want to bake the two together in your image editor, or you might want to combine the textures on the scene load using the method you suggested using Get/SetPixel(), otherwise, it makes sense to combine them in a shader.
//Straight from the docs
Shader "Examples/2 Alpha Blended Textures" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_BlendTex ("Triangle Tex ", 2D) = "white" {}
}
SubShader {
Pass {
// Apply base texture
SetTexture [_MainTex] {
combine texture
}
// Blend in a second texture using the alpha from that texture
SetTexture [_BlendTex] {
//You could use a rotation/transformation Matrix if you want to
//shift the texture
matrix[_YourRotationMatrix]
combine texture lerp (texture) previous
}
}
}
}
http://unity3d.com/support/documentation/Components/SL-SetTexture.html