Jump to content

Texture mapping

SilicateWielder

Hello, I am currently attempting to learn who to perform software-rendering, or rendering without the use of an API such as DX, or OpenGL, and I have a question

 

How do you map textures to polygons, or even whole objects? I'm not quite sure how to effectively do this and as a result I've had to come up with this solution on my own. I'm sure it's not the most elegent or efficient method of doing thing but it seems to work. All textures are generated on the fly currently.

 

1. Scan through the polygon on the Y-axis, throwing the Y-coordinates into a buffer and sorting from least to greatest and ignoring duplicate values..

1. Calculate the height of the polygon, using the absolute value of the formula sqrt(A^2 - B^2)

2. Starting at the first line, scan through all lines, sorting out all coordinates on the X-axis in the buffer.

4. Starting again at the first line calculate the width between two lines on the polygon by scanning through the coordinates again on the X axis

5. erase the original poly and begin writing lines that contain color information. 

6. Add the poly onto the model that you are generating OR pass it into the world for rendering.

 

I'm bad with words so I'll just provide this; I'm currently writing it in Scratch because that's literally the only thing I can program in at school, I plan to re-write this under the Sphere JS API once texture mapping is implemented.

 

(Faster) Phosporus link: http://phosphorus.github.io/#134808454

(Slower) Scratch Link: https://scratch.mit.edu/projects/134808454/

My procrastination is the bane of my existence.

I make games and stuff in my spare time.

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Lookup UV mapping. It basically maps a 3d polygone to a 2d space so that you can effectively create and map a texture that accurately fits each face of the polygon.

CPU: Intel i7 - 5820k @ 4.5GHz, Cooler: Corsair H80i, Motherboard: MSI X99S Gaming 7, RAM: Corsair Vengeance LPX 32GB DDR4 2666MHz CL16,

GPU: ASUS GTX 980 Strix, Case: Corsair 900D, PSU: Corsair AX860i 860W, Keyboard: Logitech G19, Mouse: Corsair M95, Storage: Intel 730 Series 480GB SSD, WD 1.5TB Black

Display: BenQ XL2730Z 2560x1440 144Hz

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, trag1c said:

Lookup UV mapping. It basically maps a 3d polygone to a 2d space so that you can effectively create and map a texture that accurately fits each face of the polygon.

Okay, however is there a more efficient method of applying the texture to the model than the method I am using? Or is filling my polys with tons of points containg color information about as efficient as i'm gonna get?

My procrastination is the bane of my existence.

I make games and stuff in my spare time.

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

4 hours ago, UnbrokenMotion said:

Okay, however is there a more efficient method of applying the texture to the model than the method I am using? Or is filling my polys with tons of points containg color information about as efficient as i'm gonna get?

Don't worry about efficiency till you have to. You could use a texture atlas tp use less memory as well as less state changes but that is useful in a limited number of circumstances as well as it still uses a UV of some sort. Basically there is no getting around texture coordinates. You could also do things like mapping the same faces ontop of each other to generate less coordinates for faces that share the same texture space.

CPU: Intel i7 - 5820k @ 4.5GHz, Cooler: Corsair H80i, Motherboard: MSI X99S Gaming 7, RAM: Corsair Vengeance LPX 32GB DDR4 2666MHz CL16,

GPU: ASUS GTX 980 Strix, Case: Corsair 900D, PSU: Corsair AX860i 860W, Keyboard: Logitech G19, Mouse: Corsair M95, Storage: Intel 730 Series 480GB SSD, WD 1.5TB Black

Display: BenQ XL2730Z 2560x1440 144Hz

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×