Using a separate alpha channel for a repeating texture

Sage
Posts: 1,232
Joined: 2002.10
Post: #16
With crossbar, you could actually do this using only two units, interpolating between TEXTURE0, TEXTURE1 using TEXTURE2 as the interpolator. But because you need three textures, your hardware still has to support three units. You could fold some other effect into the first unit in the setup I gave above though, like vertex color modulation.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #17
I'm going to give this a shot. Interestingly, I *am* using NSImage for all my other textures, but the colormap and mixmap are being procedurally generated in my game. So, I'll procedurally generate them for the test as well.

I didn't know NSImage premultiplied... Is there any way to prevent that?

Addendum: Are you sure about the alpha premultiplcation? My texture loading code reports RGBA PNG images as having four channels, as I'd expect, and all blending using such textures using GL_SRC_ALPHA and GL_ONE_MINUS_SRC_ALPHA *seems* to work.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #18
Yes, I'm sure that NSImage premultiplies the RGB. As of Panther, there's no way to turn it off. It expects that you are going to always be drawing the image to the display, not treating the data as four separate channels.

Double check your PNG data (in hex) after it is loaded to see that the RGB is what you expect. Sometimes it's hard to notice the double-multiplied case, depending on your alpha ranges.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #19
arekkusu Wrote:Yes, I'm sure that NSImage premultiplies the RGB. As of Panther, there's no way to turn it off. It expects that you are going to always be drawing the image to the display, not treating the data as four separate channels.

Double check your PNG data (in hex) after it is loaded to see that the RGB is what you expect. Sometimes it's hard to notice the double-multiplied case, depending on your alpha ranges.

Thanks to all your help, I've gotten it working! My terrain system can now interpolate across two different textures, in my implementation based on the normal of the surface. It works beautifully. Plus, I've implemented a fallback for older cards with two texture units to just use the surface texture and colormap.

Anyway, I really appreciate the help. Thanks!
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #20
Pics? Smile
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #21
Here:

[Image: mixmapped.jpg]

[Image: mixmapped2.jpg]

[Image: mixmapped3.jpg]

I think it looks pretty sweet, if I do say so myself. Notice, if you will, the self-shadowing terrain Wink I'm pretty proud of that part.

The coolest part, which I implemented this morning, is the delegation from the Terrain class itself of colormap/mixmap generation to a factory generated object, I'm calling a TerrainShader. I'm going to implement a few, for example: desert, snow, etc. The TerrainShaders can do the dirty work in a situation appropriate manner.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #22
Nice. This inspires me to write an interior generator (one more distraction for the pile...)

For your shadowing, I'm guessing it's a heightmap/raycaster? Do you update the colormap dynamically with sun rotation?
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #23
Mine is a ray caster, in fact. However, it's static. It's not that the performance is bad -- it's able to calculate the shadowmap in less than a second. I could in principle have a separate thread recalculate the shadowmap once every minute or so in accordance to movement of the sun. But I don't Wink Sounds like an interesting diversion, but at the moment I've got bigger fish to fry -- regarding threading, in fact.

My implementation of the raycaster is simple; since I'm modelling the terrain using the OpenDynamicsEngine, I just cast rays and calculate their intersection with the terrain geometry. I pass the occluder position and distance from the surface to my shader so it can make soft shadows, too. The nice part about using ODE is that I can also include static level geometry in my shadow calculations.

What do you mean by an interior generator? Are you talking about a renderer? Or something which can actually generate interior geometry?
Quote this message in a reply
DoG
Moderator
Posts: 869
Joined: 2003.01
Post: #24
Wow, that stuff looks neat.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #25
DoG Wrote:Wow, that stuff looks neat.

Thanks,

I *really* wanted to have an entry in this year's contest, but I knew I wouldn't make it in time. And right now, my enemies are still 2-d only in a separate testbed. Boo.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #26
TomorrowPlusX Wrote:What do you mean by an interior generator?
I mean generating Silent Hill rooms programatically, including all textures, models, layout, and radiosity.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #27
arekkusu Wrote:I mean generating Silent Hill rooms programatically, including all textures, models, layout, and radiosity.

That sounds like a serious bit of work. I assume your radiosity will be done via shadow maps? I can't imagine that people have real-time radiosity yet via fragment shaders.

By the way, I consider Silent Hill 2 to be The Best Game of All Time.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #28
Yes, much work. I'm still fiddling with various ideas, but currently I'm aiming low-- run on a GF2MX. So a statically solved radiosity solution for a generated room layout, using vertex coloring for the lighting and two texture units for base and decal. A third unit for detail, if available.

There is some interesting radiosity work in fragment shaders now, as in Half Life 2's "radiosity normal mapping". I think this is still a static solution though.

Silent Hill series is good, but the best game of all time is still Super Metroid... Wink
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGL Alpha Channel Problem Moganza 1 3,169 Jan 19, 2013 08:25 AM
Last Post: sealfin
  Pasting an image with alpha mask on a texture Najdorf 10 5,941 Jun 24, 2008 03:23 PM
Last Post: Najdorf
  Trouble writing PNGs with 16 bits per channel using libpng flash 2 3,867 Aug 28, 2006 11:01 AM
Last Post: flash
  Using 8-bit greyscale texture as an alpha channel? TomorrowPlusX 12 5,009 Apr 10, 2006 08:43 AM
Last Post: TomorrowPlusX
  Alpha Channel Woes GraySupreme 5 4,283 Jul 26, 2005 01:24 PM
Last Post: NYGhost