Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (768)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (854)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  compress 2 bytes into 1 byte  (Read 2921 times)
0 Members and 1 Guest are viewing this topic.
Offline orange451

JGO Kernel


Medals: 438
Projects: 7
Exp: 7 years


Your face? Your ass? What's the difference?


« Posted 2016-04-06 04:08:40 »

Hello! I had an idea earlier today, don't worry about what it's for; just a test I want to do for my game Smiley I already got the "dont do this" from TheAgentD Tongue

When reading texture data from 2 files, I only use the red channel, and I want to compress the red values of both textures into 1 byte (2 bytes --> 1 byte).

I tried:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
byte b1 = (byte) 200;
byte b2 = (byte) 255;

int i = ((b1 << 8) | (b2 & 0xFF));
System.out.println(i);

int val1 = i >> 8 & 0xFF;
int val2 = i & 0xFF;
System.out.println("b1: " + val1);
System.out.println("b2: " + val2);


Which... well... works, but not exactly, as the variable i is an integer, not a byte.

I know there will be some precision loss by doing this, but it's for texture data that doesn't need to be 100% accurate, just close.

How do I do this properly? and how would I extract the two bytes back out.

--

The only other thing I've thought of, is have one texture limited to 0, 1, or 2; and have the other limited to 0 to 55.

First Recon. A java made online first person shooter!
Offline orange451

JGO Kernel


Medals: 438
Projects: 7
Exp: 7 years


Your face? Your ass? What's the difference?


« Reply #1 - Posted 2016-04-06 05:46:18 »

I was thinking about it the wrong way.

If I limit both of the values from 0-255 to 0-15, I can easily pack them Smiley

Result:


I packed the specular texture and gloss texture into the alpha channel of the normalmap Smiley
Reduces texture swaps by half! Cheesy

First Recon. A java made online first person shooter!
Offline elect

JGO Knight


Medals: 59



« Reply #2 - Posted 2016-04-06 07:00:53 »

If you read from two textures only the red component I'd say the best optimization is to merge the two of them in one using red and green.

In general GPUs likes 16/32b chunck.. everything in between will be padded..

Anyway as usually, profile  Wink
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline orange451

JGO Kernel


Medals: 438
Projects: 7
Exp: 7 years


Your face? Your ass? What's the difference?


« Reply #3 - Posted 2016-04-06 17:52:57 »

That was my first thought too, but that would still have an extra state-change on the GPU. Since there would be three textures to bind when drawing a material, instead of 2.

Since the math to get the values back (on the GPU) is super simple, it unrolls quite nicely.

[edit]
Just did a small test in my engine. I drew the model above 16 * 16 times. Using the compression thing I get 185 fps. If I send in 3 textures then I get 160 fps, and if I send in 4 then I get 150 fps.

First Recon. A java made online first person shooter!
Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (1340 views)
2018-06-10 19:43:48

EgonOlsen (1230 views)
2018-06-10 19:43:44

EgonOlsen (939 views)
2018-06-10 19:43:20

DesertCoockie (1380 views)
2018-05-13 18:23:11

nelsongames (1112 views)
2018-04-24 18:15:36

nelsongames (1375 views)
2018-04-24 18:14:32

ivj94 (2120 views)
2018-03-24 14:47:39

ivj94 (1269 views)
2018-03-24 14:46:31

ivj94 (2286 views)
2018-03-24 14:43:53

Solater (808 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!