Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Hi how would you texture a object without using the texture object command Advanced Coders

Author
Message
darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 25th Oct 2012 20:43
Hi guys,

How would you texture a object without the texture object command and using a memblock to hold the image and texture the object with vertexdata or something.

From what I have understood the uv is just how it tiles on the object. However, it doesn't exactly texture the object.

Does anyone know how to do this?

darkvee
Sergey K
22
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 25th Oct 2012 20:49
why do u want to texture via memblocks?

you always can use .x files to import the model WITH the texture already.

Advanced Updater for your games!
darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 25th Oct 2012 20:59 Edited at: 25th Oct 2012 20:59
Hi Sergey K,

I have a point cloud converter that takes your 3d model and converts it. The idea is to be able to texture this point cloud just like a 3d model. In order to be able to do that I have to use a different way of texturing it.

darkvee
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 25th Oct 2012 21:00
I was going to suggest shaders but I'm thinking that won't work for this...
Brendy boy
20
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 25th Oct 2012 21:06
use vertex diffuse color

darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 25th Oct 2012 21:30 Edited at: 25th Oct 2012 21:34
Hi Brendy boy,

I didn't even realize this command. haha Thanks for showing me this.

However, I coded an example as you can see it's not detecting the colors.



darkvee
Brendy boy
20
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 25th Oct 2012 21:40
Quote: "However, I coded an example as you can see it's not detecting the colors."

you need to set them first with set vertexdata diffuse command to be able to detect them

darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 25th Oct 2012 21:51 Edited at: 25th Oct 2012 21:52
Quote: "you need to set them first with set vertexdata diffuse command to be able to detect them"


Ok I coded another example that sets it first then gets it. It
still isn't working.

However, it doesn't make sense why you would have to set it first before you can get it. If I texture a object I should be able to use the get vertexdata diffuse command to get the colors from the object.



darkvee
Brendy boy
20
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 25th Oct 2012 22:18 Edited at: 25th Oct 2012 22:20
Quote: "still isn't working. "

you need to have the vertices in the format which contains diffuse color
you need to convert fvf format of your object to 338

Quote: "However, it doesn't make sense why you would have to set it first before you can get it. If I texture a object I should be able to use the get vertexdata diffuse command to get the colors from the object."

diffuse commands are not used to get colors from texture

Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 25th Oct 2012 22:26
So you are trying to read the texture colour from an object at its vertices? That should be quite easy. You would just have to loop through the vertices, read the UV data, multiply the UV values by the image dimensions to get a pixel co-ordinate and then use an image memblock of the object's texture to read the colour at that point.

How are you rendering your point cloud? Because you could potentially then set the vertexdata's diffuse value with the colour you pulled from the image memblock.


Previously TEH_CODERER.
darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 26th Oct 2012 04:06 Edited at: 26th Oct 2012 04:40
Hi Andrew,

How do you use set vertexdata diffuse coomand to be able to texture at each vertex index that will fill the whole triangle?

I have the logic in in this code from what I understood from you.

Here is my code:



darkvee
Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 26th Oct 2012 10:34
I'm at work at the moment so I can't write a full example, but this is closer to what I meant.



This obviously can't produce a full resolution textured object because that just wouldn't be possible without applying a texture either directly or through a shader. This will sample the texture used at each vertex and use that as a diffuse colour for the vertex. The triangle will then be filled with a gradient of the 3 colours set to each of its vertices.

For a point cloud of course you would have to do something clever to work out what colour the inner vertices should be. Whether you would need a 3d texture or just to ray cast the outer colours through to the center...


Previously TEH_CODERER.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 26th Oct 2012 11:23
Couldn't you just add the texture to your point cloud shader? That would save you having to do this.

TheComet

- The codebase
Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 26th Oct 2012 16:32
This is why I asked how he is rendering the point cloud. I don't even know if his point cloud has UV data for that to work.


Previously TEH_CODERER.
darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 26th Oct 2012 17:14 Edited at: 26th Oct 2012 17:23
Hi guys,

Thanks for all your help.

Andrew_Neale,
Ok I will try something like this. Thanks

Quote: "
Couldn't you just add the texture to your point cloud shader? That would save you having to do this."


TheComet,
I don't want this done on a shader. I want this working without a shader.

Andrew_Neale,

I'm trying to learn how do this texture thing without texture object command or by shaders. This way I should be able to figure out how to map the texture to the point cloud with this logic.

darkvee
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 26th Oct 2012 18:52 Edited at: 27th Oct 2012 18:06
Quote: "I don't want this done on a shader. I want this working without a shader."


So you decided not to use the shader from your other thread?

Well, I guess doing it the hard, slow way can work as well. What you need to do is the following.

1) Load your texture into a memblock
2) Load your object into a memblock
3) Go through all vertices and get the UV data
4) Use the UV data to get a pixel of your texture from the memblock
5) Go back to your vertices and set their diffuse colour to the pixel colour in your texture.

Here's some code off the top of my head (don't have a DBP compiler right now):



The above will not work if you're using the shader, and you're just not telling us about it.

TheComet

- The codebase
darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 26th Oct 2012 19:11 Edited at: 26th Oct 2012 22:01
Hi TheComet,

Thanks for the help. I should be able to figure out how you correctly map the texture now.

I have the vertex diffuse color finally showing up on the object with out texture object command or shader. It's not perfect yet but I should now be able to figure it out. In the demo it gets the color but it picks random color bytes.

Here is the code:



darkvee
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 26th Oct 2012 19:54
And now how do you convert that to a point cloud without a shader and still keep the vertex colours?

This shader should work:



It's much faster than whatever method you're using.

TheComet

- The codebase
Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 26th Oct 2012 20:43
Quote: "
1) Load your texture into a memblock
2) Load your object into a memblock
3) Go through all vertices and get the UV data
4) Use the UV data to get a pixel of your texture from the memblock
5) Go back to your vertices and set their diffuse colour to the pixel colour in your texture.
"


Exactly what I was saying and gave rough code for.


Previously TEH_CODERER.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 26th Oct 2012 21:25
@ Andrew_Neale - Sorry Andrew, I jumped straight to the point and didn't take the time to read all of the replies.

TheComet

- The codebase
darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 27th Oct 2012 15:43 Edited at: 27th Oct 2012 16:31
Hi guys,

Well I dunno if you can actually convert the uvs to pixels. I checked the memblock on just 1 plane and it only counted 6 uvs in it. The way uv mapping works is it takes the width,height of the image and that whole image is in the range of 0.0 to 1.0 in both u,v directions.

I need a way that it can store each pixel from the texture by a fraction of 0.001 in u and v. You can't add the uv data correctly if the memblock only holds 6 slots for it. I need the memblock to hold 1024 * 768 uv values so I can convert the uv to pixel coords and put them in the memblock. Does anyone know how to do this?

darkvee
Brendy boy
20
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 27th Oct 2012 17:22
Quote: "Does anyone know how to do this?"

using interpolation?

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 27th Oct 2012 17:39
@darkvee

You've lost me now. Up to now I thought you were working with a high poly/vertex object so that there would be a reasonable match between pixels and vertices. Are you now saying that your object only has 6 vertices - or that a much larger number of vertices use only 6 different pairs of UV values? If that's the case, why not change the UV values?

What are you intending to do with your memblock?
darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 27th Oct 2012 17:57 Edited at: 27th Oct 2012 18:02
Hi Green Gandalf,

I'm using a plane that has 6 vertices for now until I get this working. By doing this I start with a very simple object to work with. The idea is to texture the object with your image using set vertexdata uv with set vertexdata diffuse.

I'm having some problems trying to get this to work. If this doesn't work how would you make some memblocks do all of this?

darkvee
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 27th Oct 2012 18:06 Edited at: 27th Oct 2012 18:08
@darkvee

I gave you working code, I gave you a working shader... What's not working for you?

I'm sick of this, you don't seem to acknowledge any help you're getting, and you're doing something way over the top of your own head when the solution is so simple with a shader (which I gave you just above and you didn't even see).

Have a nice day.

TheComet

- The codebase
darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 27th Oct 2012 18:32 Edited at: 27th Oct 2012 18:40
TheComet the code you gave didn't work. I just didn't want to tell you about it. You load it up and if it worked it wouldn't of had out of memblock position issues but thanks for the help though.

Again, I told you i'm not wanting to use a shader to be able to do this.I have very good reasons for this.

Here is my code. It should tell you what i'm trying to do. I commented it really good. I'm basically trying to make a custom system to uv map the image and map it to the vertex difuse colors




darkvee
darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 27th Oct 2012 19:05 Edited at: 27th Oct 2012 19:11
Hi TheComet,

I just re-ran your code it seems to work now. Did you recently update it? Anyways it runs now without memblock issues. However, it's still not texturing the complete image to it.

I modified your code to show you. Run the code and notice the cube doesn't have that whole image displayed on it.

here is a screenshot of it.



Here is the code:



darkvee
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 27th Oct 2012 19:41 Edited at: 27th Oct 2012 19:42
Well of course it won't, you're colouring the vertices of the object to make up the pixels, and all you have is 6 vertices. How is that supposed to hold the information of that huge image?

Increasing the polygon count gives you more resolution.





TheComet

- The codebase
darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 27th Oct 2012 20:08 Edited at: 27th Oct 2012 20:18
Hi TheComet,

That does indeed work. Thank you your help. You have been very helpful. It's very blurry though.

It seems you can only increase the segments if it's less than the number of indices. This means you can make it look good as the texture with the indices being a problem.

here is the image with the most segments I can have with out indices error.



Can't you just make a plain with 2 polygons and texture the whole image to it? Using the texture object command with a plain it textures the whole image.

darkvee
Brendy boy
20
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 27th Oct 2012 20:28
Quote: "Can't you just make a plain with 2 polygons and texture the whole image to it?"

didn't you said you don't want to use texture object command?

qoute from the 1st post
Quote: "How would you texture a object without the texture object command"


darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 27th Oct 2012 20:31 Edited at: 27th Oct 2012 20:34
Hi Brendy boy,

Yes this is correct. Can't we get the same results as texture object command without using it?

Brendy boy i,m trying to get the same quality as the texture object command.

darkvee
Brendy boy
20
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 27th Oct 2012 20:34
Quote: "Can't we get the same results as texture object command without using it?"

no, what would be the purpose of texture object command if we could?

Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 27th Oct 2012 20:36
Quote: "Can't you just make a plain with 2 polygons and texture the whole image to it?"


Umm...yes...you use the texture object command like you said. There is no other way. Behind the scenes, DBPro has to pass a mesh and a texture to DirectX for rendering. DirectX requires the mesh to have UV data so it knows how to map the texture to the object. That UV data can either come from the object directly or from a shader which generates UV data in real-time, such as when applying a cube map or doing a projection.

Why are you trying to find a different way of doing it? It sounds like you don't have anywhere near enough understanding of 3d rendering to attempt what you are attempting. If you're really set on this then maybe do some reading up on how DirectX handles rendering.


Previously TEH_CODERER.
darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 27th Oct 2012 20:37
Hi Brendy boy,

I thought anything is possible in code? Your saying we can not get this kind of quality no matter what we do?

darkvee
Brendy boy
20
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 27th Oct 2012 20:40
Quote: "I thought anything is possible in code? Your saying we can not get this kind of quality no matter what we do?"

read what Andrew_Neale wrote. If you want a texture on your object you need to send it to directX, there's no other way

darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 27th Oct 2012 20:42 Edited at: 27th Oct 2012 20:44
Hi Andrew_Neale,

I agree with not understanding that much about 3d rendering. I havn't gotten to study directx with c++ yet. I should though this would be very helpful for the needs i'm wanting.

The texture quality won't be great enough for the point clouds. This is a big blow. I'm going to have to learn how to send it to directx in order to progress on this issue.

darkvee
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 28th Oct 2012 01:14
You don't seem to understand... texture object does send it to DirectX...

What you're doing is pointless and a waste of time, why re-invent the wheel?

TheComet

- The codebase
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 28th Oct 2012 07:06 Edited at: 28th Oct 2012 07:21
@darkvee
It becomes a little more complex than just mapping to pixels. UV maps are generally per-face. In your custom 3d to 2d plotting, you will most likely have to keep track of the faces because the textures are interpolated, or stretched, across the individual faces. So in order to accomplish what you want with custom mapping, you have to keep track of the faces and the vertex indeces that are applied to each face.

You then interpolate between the vertices and ultimately the screen pixels, that are shared by that face. If you just want the cloud of pixels textured and not the in-betweens, you use the UVs for a specific vertex as a percentage of the image texture.

If vertex 10, for example had UVs of (.1,.5) and you had a texture of 256x256, then the pixel color from the texture would be at the pixel positions:

Xposition = (255 * .1) = 26
Yposition = (255 * .5) = 128

You should read up on 3D graphics to understand how the texture is converted from 2d into 3d space so you can map it to the screen how you want. The proper interpolation of the texture on screen is what you are after, I believe. This can get pretty complex depending on the smoothing, use of mipmaps, blending, face culling, etc.


Kevin Picone posted some amazing code written for DBC many years ago where he made a Doom/Wolfenstein engine out of 2D without any 3D commands. He textured the walls and floors and even a background image that scrolled in parallax. What you are after is possible, and learning something new is never a waste of time.

Enjoy your day.
darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 28th Oct 2012 16:42 Edited at: 28th Oct 2012 16:46
Hi there Latch. It's good to see you again .

Hi Andrew, TheComet, Brendy you guys have been very helpful to me. Thank you for all of your honest work you guys are great.

TheComet,

What i'm wanting to do i'm going to have to kind of re-invent the wheel a litte bit to get what I need. I got to learn some new things in 3d rendering with directx. The idea is learn what I need and make a custom dll I can use in dbp for this.

Latch I can't thank you enough man. Wish me luck Would anyone care to maybe help me out in directx with c++ getting me started? If possible could someone like help me on msn messager or something?

darkvee
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 28th Oct 2012 19:01
I still don't understand what your problem is exactly.

In particular I don't see why you can't use texture object as everyone has been suggesting and then just adjust the filter settings. Your comments suggest that your problem is simply one of getting blurred pixels.

Could you post a screenshot of one of your objects textured with one of your images and tell us exactly what is wrong?
paul5147
20
Years of Service
User Offline
Joined: 11th Jan 2006
Location: Hot & Sunny
Posted: 28th Oct 2012 20:16
Have you looked at using the D3D plugin for the rendering?
The Weeping Corpse
14
Years of Service
User Offline
Joined: 19th Sep 2011
Location: United Kingdom
Posted: 28th Oct 2012 21:16
Is the OP trying to implement voxel rendering?

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 28th Oct 2012 21:52
From what I understand he's trying to draw a textured object using only 2D commands.

TheComet

- The codebase
Dar13
18
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 29th Oct 2012 02:05
Quote: "Is the OP trying to implement voxel rendering?"

Pretty much.

darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 29th Oct 2012 03:29 Edited at: 29th Oct 2012 03:33
Hi Green Gandalf,

Quote: "Could you post a screenshot of one of your objects textured with one of your images and tell us exactly what is wrong? "


Don't you see the blurry image on the plane on the forums?

Hi paul,

I don't know if that will even work. The memblock stores the color values. So I don't see how this could be any better than this unless your accessing directx and sending the texture. I will try it out see what results I get.

My idea about this issue is want Latch said about it.

darkvee
darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 29th Oct 2012 03:57 Edited at: 29th Oct 2012 03:59
Hi paul,

Cool demo you have there.

I tried the idea you had and it's a no go. The texture is still blurry like my last screenshot on the 1st page. I notice when I try to re-run the program it crashes. I'm guessing this is to do with the plugin?

I changed out the code
dot x,y,rgb(setColorR,setColorG,setColorB) with
d3d_dot x, y,rgb(setColorR,setColorG,setColorB)

here is the code:



darkvee
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Oct 2012 11:40
Quote: "The texture is still blurry like my last screenshot on the 1st page"


As I suggested before, why don't you try changing the object's filter settings?



Try the different options 0, 1 and 2 for flag and see what happens. If you still have problems please post code, media and a clear statement of what's wrong. At the moment it seems your only problem is that you are using the default filtering option.
darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 29th Oct 2012 18:14 Edited at: 29th Oct 2012 18:17
Hi Green Gandalf,

Noop it doesn't work either. I took screenshots of each filter setting and also the code for you to see for yourself.

filter 0


filter 1


filter 2


Here is the code:



Well guys yesterday I learned how to register a window 32 in c++ That was a big step for me. I need to learn directx but I want to make some buttons and stuff see what the window 32 api offers.



darkvee
paul5147
20
Years of Service
User Offline
Joined: 11th Jan 2006
Location: Hot & Sunny
Posted: 29th Oct 2012 20:04 Edited at: 29th Oct 2012 20:08
Hi Darkvee,glad you like the demo but im not sure you got the point of it,it was to use the d3d dots to actually render the object not just a texture.Try this modified code with the atattched image or any image 101x101 pixels to see the efect i was trying to get across to you.


This code does not even create any objects it simply uses the dots to draw one.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Oct 2012 20:15 Edited at: 29th Oct 2012 20:16
@DarkVee

You've missed the point again. There's no need to do anything other than texture the object and set the filter.


I still don't understand why you won't do this.

Code:



Here's the screenshot I get:

Login to post a reply

Server time is: 2026-07-07 10:13:27
Your offset time is: 2026-07-07 10:13:27