how do you update RGBA textures realtime in the 3DEngine?

Just starting out? Need help? Post your questions and find answers here.
jayagopal
User
User
Posts: 35
Joined: Thu Oct 02, 2008 11:22 am
Location: india

how do you update RGBA textures realtime in the 3DEngine?

Post by jayagopal »

Hi, i just started using purebasic like 3 days ago. please help me if you can.

i already searched through the topics looking for an answer but couldn't find one. i am using the 3Dengine and my textures are all loaded from TGA files with alpha channels. i got the effect i wanted so far... very nice. but now i want to do real-time updates of the textures.

the problem is, if i try to use

StartDrawing(TextureOutput(0))
.
.
.
StopDrawing()

then wherever i change the color it turns to 0% opacity. try it out. it will recognize exactly where you are updating the texture but it will just make those pixels 0% opacity. and there is no obvious way to plot a 32-bit pixel with 2D drawing functions (without using DrawingBuffer() which doesn't work in the context of the 3Dengine).

so the solution i am looking for is either:

1) is there some way to plot the pixels successfully... with an additional alpha byte? (i can't find it)

2) and i prefer this one, just as DrawingBuffer() returns the memory address for direct screen drawing... how can i find the starting memory address for the texture data? that is ideal cuz then i can use peek and poke to update the texture real-time which is probably faster.

3) i have to learn ogre... and i don't want to. :?

please help someone!
:shock: :D :(
Thalius
Enthusiast
Enthusiast
Posts: 711
Joined: Thu Jul 17, 2003 4:15 pm
Contact:

Post by Thalius »

To get a pointer to teh texture data - thats not possible as all the Texture Data is in the GPU memory not the CPU Memory. Theres a copy there but oyu cannot directly access the GPU Memory without the use of shaders ( which i recommend anyway for any texture operation as its about 100x faster than doing this on the cpu ).

Theres a few nice tools (also click and go see: http://ati.amd.com/developer/rendermonk ... loads.html) to create your own shader .program then check the OGRE Manual how to Register it
here:
http://www.ogre3d.org/docs/manual/manual_18.html#SEC101
Then you need to define the vars which need to be fed into the GPU Program:
http://www.ogre3d.org/docs/manual/manual_23.html#SEC119
...and create a Material script which utilizes the shader:
http://www.ogre3d.org/docs/manual/manual_14.html

However, i havent had much time to play with the current version yet ( actually i hadnt much time for anything personal *snif* ... ) but what happens if you create an RGBA imagte in memory and then modify it -> update to GPU - dunno what you want to achieve but with not too big modifications a CPU should be able to do this with reasonable fps still also.

EDIT: You could also try using 2 n^2 sized textures one with 24 bit color information - the other with 8 bit grayscale alfa infos and blend them together in a material script - that way you would also just have to update the 8 bit alpha texturespace which should be alot faster.

Cheers,
Thalius
"In 3D there is never enough Time to do Things right,
but there's always enough Time to make them *look* right."
"psssst! i steal signatures... don't tell anyone! ;)"
jayagopal
User
User
Posts: 35
Joined: Thu Oct 02, 2008 11:22 am
Location: india

Post by jayagopal »

wow, thanks homie.

you seem like you know a lot about implementing ogre functions in purebasic.

i started looking at some of those links... it seems they are all c++.

i can switch to c++, but it seems you are suggesting i can use these ogre tools with purebasic.

can you give me any hint about how to implement these shader GPU programs through purebasic?

:)

--so with parse3dscripts i make a script to handle the materials... that's cool... but then:

i have 256 materials, each one is 256x256. i need to update the materials with specific pixel modifications. for instance, material #100 might be totally empty (and see-through), and i just need to add a red circle with a hazy edge at a specific location.

aren't the scripts static? how would i go about this?
Thalius
Enthusiast
Enthusiast
Posts: 711
Joined: Thu Jul 17, 2003 4:15 pm
Contact:

Post by Thalius »

Actually its not C++ - Rendermonkey produces a bit similar looking code that runs on the Graphics Processor ( GPU ). ( GLSL for OpenGL then you also can convert to HLSL DirectX ). Depending on the Subsystem you use ( CG ) run on both but generally are a bit less powerful.

Theese under OGRE so called ".program" files define basically the technique the shader produces - the program can be fed with data thru OGRE with Informations such as the world matrix projection coordinates - light positions and other things ( see the list above ) and can produce results on Geometry ( vertex ) and Pixel base. Theese functions are described in the .program files and produce for example a texture image inside the gpu memory on the GPU itself. There can also be multiple Instances of the same shader used.

Depending on what you would like to achieve its surely the more performant route than recreating several textures in memory on the cpu each frame. Besides the still bit lacking RGBA() Issue with Drawing Functions iirc.

However, whenever you can use a lets say 1024x1024 texture to clip all the Materials that need updating to one Texture ( like a carpet ... heh ) - and then update that - its generally faster to have one big texture in the scene than several hundred small ones. Note - todays cards in teh average support up to 4096x4096 - but 1024 is safe even on a bit older cards with 32 mb. vram.

So, assuming you re trying the cpu road ( as its alot simpler too :)
I would play a bit with a .material script and see if you can get an 8 bit texture as separate alpha in... check the ogre boards too - i recall somone had a similar problem way back. Only other Option would be to probably manually create an RGBA() via custom function, either from separate image ( the 8 bit grayscale as mentioned and appending the 8 bit gray infos after the 24bit on a resized buffer) or for simple transparency a color mask which you mask into the alfa bits.

Tho personally id go the Shader Route. Altho i need to check out the new OGRE myself as how to pass the values. Ill try with a simple GLSL Water Shader which produces vertex + pixel data to create the waves.
...and then i should do some more conversions on the weekend! Anyone selling free time ? :lol:

Cheers,
Thalius
"In 3D there is never enough Time to do Things right,
but there's always enough Time to make them *look* right."
"psssst! i steal signatures... don't tell anyone! ;)"
jayagopal
User
User
Posts: 35
Joined: Thu Oct 02, 2008 11:22 am
Location: india

material script

Post by jayagopal »

Thalius, you are being very kind by helping me like this.

i've downloaded the ogre SDK and i'm contemplating switching to c++... but i like purebasic a lot. i have to reveal my utter ignorance now. i'm having trouble figuring out how to:

1) write a material script so each pixel is calculated by simple x,y coords (for example make a gradient texture so r=x, g=0, b=0, alpha=y)
2) apply it to my entity
3) add new pixel-data to the materials on the fly (let's say, for example you click on the gradient somewhere and it adds a blue radial gradient at that spot)

i store the pixel data in a 2D array in PB for each material. but if i click somewhere i want to pass specific pixel updates to the material... realtime:

just an example (i just wrote it for this post... i don't know if it's correct code):

Code: Select all

circleRadius = 20
clickXpos = 58
clickYpos = 32

for y = 0 to 255
 for x = 0 to 255
  r = sqr((clickXpos-x)^2+(clickYpos-y)^2)
  if r<circleRadius
   newR = 255 - r/circleRadius*255
   newG = 0
   newB = 0
   newA = newR+newG+newB
   modifyMaterialXY (x, y, newR, newG, newB, newA)
   texArray(0,x,y).R = newR
   texArray(0,x,y).G = newG
   texArray(0,x,y).B = newB
   texArray(0,x,y).A = newA
  endif
 next
next
...i am feeling so grateful for your help that i am almost about to send some screenshots of what i'm working on. i think you might like the idea. but i am hesitant because i want the first few implementations of this technique to be in relation to a particular subject matter... after that it can be as public as anyone wants.

i am actually an artist more than a programmer... my application is for use in a movie production and since i am a gaudiya vaisnava monk, the content is the pastimes of sri caitanya mahaprabhu and srimad bhagavatam...

my technique has very beautiful results... it is not a standard 3D technique. you get smooth and soft things with volume 8) instead of hard cold edges and empty objects. the realtime update aspect is because it is an "object" editor (sorta).

please help me a little more. i am totally ignorant about how to implement the material scripts and the dynamic updates. actually i don't even know how to get the most basic material script working in purebasic with my simple meshes. it's hurting my head looking through all the documentation and not finding a single example of linking an ogre material script to purebasic code with parse3dscripts... or what code applies the material to the mesh.?

if you help me i will be exceedingly grateful. if you want to see screenshots i will send some privately for now :oops: :shock:
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post by djes »

There's no special code to apply a material. When you call parse3dscripts, all the materials file associated with the meshes (in the same directory) are parsed by ogre and assigned to the surfaces you've created in your modeler. It's written in the doc... I don't know how to alter such a material dynamically. I think nobody on this forum has ever written an ogre shader, as the new 3d engine has less than a week ;)
jayagopal
User
User
Posts: 35
Joined: Thu Oct 02, 2008 11:22 am
Location: india

Post by jayagopal »

thank you djes.

but i can't find even one simple example of how this works. i am making a mesh from scratch (it's just a plane). so i don't know how to associate this mesh with the material script... so i can't even begin to test out the scripts.

thalius suggested a good technique: use a 24-bit texture for color and an 8-bit texture for alpha; blend them in a script; and then update the textures separately. but i can't even get started. i am too ignorant. :(

how do i assign the script to my mesh?
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post by djes »

A lot of people did that because they don't know how to create a mesh. I think it'll be easier to create a plane with an associated material. Fred will need some testers for this kind of stuff. Badly, I think you don't have enough experience. Do you know how to create a mesh? What is your 3d favorite program?
Thalius
Enthusiast
Enthusiast
Posts: 711
Joined: Thu Jul 17, 2003 4:15 pm
Contact:

Post by Thalius »

Ill try to play with this idea a bit on the weekend, maybe i get something working - no promises tho :)

Its all still beta so lets see. ;)
"In 3D there is never enough Time to do Things right,
but there's always enough Time to make them *look* right."
"psssst! i steal signatures... don't tell anyone! ;)"
jayagopal
User
User
Posts: 35
Joined: Thu Oct 02, 2008 11:22 am
Location: india

Post by jayagopal »

thalius:

yay!

woot woot!




p.s. (if you want some screen shots of what i'm up to please give me a way to send them to you privately).
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

Isn't this what pixel shaders are for? You send a small instruction to the GPU and have it process the image for you rather than moving it to the cpu and then copying it back.
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post by djes »

Mistrel wrote:Isn't this what pixel shaders are for? You send a small instruction to the GPU and have it process the image for you rather than moving it to the cpu and then copying it back.
It's what I say from the start :?
jayagopal
User
User
Posts: 35
Joined: Thu Oct 02, 2008 11:22 am
Location: india

Post by jayagopal »

@ djes & mistrel:

pixel shaders sound appropriate :D , do you have an example?

@djes:

my mesh is just a single plane, but there are 256 instances of it with different materials. i need each material to be updated according to user-input.

my 3D program is Cinema4D.
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post by djes »

jayagopal wrote:@ djes & mistrel:

pixel shaders sound appropriate :D , do you have an example?

@djes:

my mesh is just a single plane, but there are 256 instances of it with different materials. i need each material to be updated according to user-input.

my 3D program is Cinema4D.
Ok, so if you're exporting your objects with cinema4d, you certainly have material files associated with your meshes. You may try to modify them. I don't have examples by now as it's so new to us, but I'll surely do tests in the next days.
jayagopal
User
User
Posts: 35
Joined: Thu Oct 02, 2008 11:22 am
Location: india

Post by jayagopal »

if anyone wants to see screenshots of what i'm working on, please provide email addresses.

you can send them to sirvntuvgod@gmail.com
Post Reply