- Home /
How to update texture during runtime to display damage?
A certain attack emits a bright flash that "sunburns" a character. That is, the pixels in the characters's surface that were touched by the flash should, e.g., turn red.
The first problem is to find out what pixels were touched by the flash. I should be able to find out via a fragment shader associated with a material on the character. The shader could return a constant color. If, at the moment of the attack, I render that material from the player's perspective to a RenderTexture, I should get a texture containing the silhouette of the damaged part of the character.
The real question is, how do I use the silhouette texture to update the character's texture? I need to translate the "on" pixels in the silhouette texture to the appropriate places in the character's texture.
(The silhouette texture only has information about x and y, and I probably also need z. Maybe I could encode z in the color, or use a different shader to render a different texture with information about z).
im sure the terrain painting feature or something similar could be implemented onto other objects.. it couldnt be that hard.. it can be done in blender, and nearly anything is possible in unity. Does it have to be a certain spot? you could have an alpha map that makes it appear to get more damage.. but all over the body :S
I'm not sure of your approach, but to give an answer to the specific question asked, if you Raycast() the point on your character, the RaycastHit returned contains a textureCoord which is the UV point in texture that maps to the hit point. Not sure how you would handle the seams.
Your answer
Follow this Question
Related Questions
Converting a RenderTexture to a Texture2D for use in a shader 2 Answers
Multiple materials on same object 0 Answers
How to apply different textures to one model? 1 Answer
Tracing in Unity3D 2 Answers
What is wrong with my shader? 1 Answer