How to paint on texture?

Started by
2 comments, last by Fingers_ 16 years, 6 months ago
hello all, i`m writing toolset for my engine now, but i have a difficulty that i can`t overcome. i want level designer to have possibility to simply paint on terrain wherever he want. in neverwinter nights 2 toolset it has been done nicely. i know that they can have only six different textures in each tile and therefore i`m quite sure they are using texture splatting(http://www.gamedev.net/reference/articles/article2238.asp). however i have really no idea how to edit texture in such way. i need to create circle around some point in one texture channel. i was thinking about doing it in pixel shader but it would be too complicated. and if i lock texture on cpu i can only rewrite whole texture or rectangle(i think), and it would be slow and complicated. is there some elegant way how to edit texture? for example if i could do something like setTexelColor(x, y, color) on cpu. it would be totally great.
Advertisement
If you're doing this in OpenGL, you can keep a copy of the texture in RAM to draw onto it and update the changed portion with glTexSubImage2D... At least this is how I'd do it. (I'm sure D3D has an equivalent function but I'm not familiar with it.)

Btw, even updating the whole texture should not take a noticable amount of time on any halfway modern hardware. I remember doing procedural animated textures this way on a GeForce2.
tnx for reply, that sounds good. but how do i store texture in ram? i don`t mean setting something like d3dpool_systemram, becouse it wouldn`t solve anything. maybe something like array?
Any image is just an array of pixels in whatever format you're using. For example, 32-bit RGBA textures have one byte for each component per pixel so the array size is width*height*4 bytes and the component bytes are arranged in RGBA order.

If you want to use DX functions, you can probably create a DX surface of some kind in system memory and access its pixel data array directly. It should be the same pixel format that you use for the texture in VRAM.

This topic is closed to new replies.

Advertisement