Transparency with Lighting
by Richard Taylor · in Torque Game Engine Advanced · 12/07/2007 (8:12 pm) · 7 replies
Hi everyone,
An artist friend and I grabbed a Torque license a few days ago for some work we're going to be doing in the near future. We've done a few pipeline tests, getting various assets created and in-engine with the relevant script requirements. So far, everything has gone well with the exception of transparent objects.
We've successfully exported a cube with opacity data stored in the alpha channel of the diffuse texture. The cube shows up with holes in it, so it's correct as far as that is concerned. However, now only ambient lighting effects it. The crossbow bolts don't light it up as they streak past as they do with our other models (which include both specular and normal maps, so those are fine), and moving a light source around it doesn't work either.
Is there some reason that lighting doesn't effect objects with opacity? I'm wondering if it's something to do with multi-pass rendering, as I've little experience with that. So far, even if there are no other effects at all, as soon as "translucency = true;" is applied all dynamic lighting on the object is disabled. I've got specular to work on the transparent cube by applying it in a second pass, and I'm going to continue experimenting with it, but any pointers would be great.
Cheers,
Richard
EDIT: On further experimentation, it seems that transparent objects just ignore dynamic lights. We've got a low-poly car body we're using for testing and the body shows correct specular from both the sun and an sglight which we're moving around it, but the windshield part stays unlit and shows specular only from the sun.
An artist friend and I grabbed a Torque license a few days ago for some work we're going to be doing in the near future. We've done a few pipeline tests, getting various assets created and in-engine with the relevant script requirements. So far, everything has gone well with the exception of transparent objects.
We've successfully exported a cube with opacity data stored in the alpha channel of the diffuse texture. The cube shows up with holes in it, so it's correct as far as that is concerned. However, now only ambient lighting effects it. The crossbow bolts don't light it up as they streak past as they do with our other models (which include both specular and normal maps, so those are fine), and moving a light source around it doesn't work either.
Is there some reason that lighting doesn't effect objects with opacity? I'm wondering if it's something to do with multi-pass rendering, as I've little experience with that. So far, even if there are no other effects at all, as soon as "translucency = true;" is applied all dynamic lighting on the object is disabled. I've got specular to work on the transparent cube by applying it in a second pass, and I'm going to continue experimenting with it, but any pointers would be great.
Cheers,
Richard
EDIT: On further experimentation, it seems that transparent objects just ignore dynamic lights. We've got a low-poly car body we're using for testing and the body shows correct specular from both the sun and an sglight which we're moving around it, but the windshield part stays unlit and shows specular only from the sun.
#2
I thnk if you look a tthe matrial doc for TGEA you will find it I would post the link directly but it seems that TDN is down right now
12/27/2007 (10:49 am)
I had something similar to this happen to me . I think there is a variable that you ahve to add to the shader.I thnk if you look a tthe matrial doc for TGEA you will find it I would post the link directly but it seems that TDN is down right now
#3
12/27/2007 (1:02 pm)
OK can one of you point me in the direction of how to do a shader for a transparent texture? I am new to writing these things. Just got TGEA Christmas.
#4
Or use that and the one you get from shadergen when you create a working light material
and compare them, try to merge them.
But there is one thing one should point out: perhaps thats just our team but dynamic light bork quite seriously. we only get projectile lights on terrains (legacy) to work on 1 of 4 systems for example (8800GTS, even though we have an 8600GT based with the same drivers! and same specs side a side)
so potentially this whole issue is just a massive bug in the shaders for dynamic lights.
12/27/2007 (1:39 pm)
Create a procedural texture that uses alpha and take that one to base your own shader on. That surely would be a good thing :)Or use that and the one you get from shadergen when you create a working light material
and compare them, try to merge them.
But there is one thing one should point out: perhaps thats just our team but dynamic light bork quite seriously. we only get projectile lights on terrains (legacy) to work on 1 of 4 systems for example (8800GTS, even though we have an 8600GT based with the same drivers! and same specs side a side)
so potentially this whole issue is just a massive bug in the shaders for dynamic lights.
#5
First, in creating the texture you need to make sure that the alpha channel is stored correctly. If you're using Gimp then you're fine out-of-the-box. However, new versions of Photoshop do stuff differently and the alpha doesn't work in Torque. Theres a plugin called SuperPNG that does it right, so track that down using the search function (plenty of people around here have links to it). You want the original SuperPNG, not the new version, by the way.
Once you've got your texture you have to write a material script. Here's one of mine with working transparency:
baseTex[x]: this tells Torque what texture to use for the diffuse and alpha components. The alpha component of this should include your opacity information. The x indicates what render pass this texture is to be used for, with 0 indicating the first pass. As there's nothing particularly fancy going on here this is just a single pass material.
translucent: this tells Torque that the material should be rendered with translucency.
And, in its simplest form, that's really all there is to it. If you take a look here there's a list of other properties that you can experiment with.
12/27/2007 (3:04 pm)
Quote:Create a procedural texture that uses alpha and take that one to base your own shader on. That surely would be a good thing :)I'm confident that if I have to I'll be able to do that without too many problems, but I'd simply rather not. We've got some custom shaders I'll have to write myself anyway, I'd simply prefer that the procedural shaders handled these more generic cases so that I could concentrate my efforts elsewhere.
Or use that and the one you get from shadergen when you create a working light material
and compare them, try to merge them.
Quote:perhaps thats just our team but dynamic light bork quite seriously. we only get projectile lights on terrains (legacy) to work on 1 of 4 systems for example (8800GTS, even though we have an 8600GT based with the same drivers! and same specs side a side)That sounds nasty. I certainly hope it isn't a bug of any kind. Our legacy terrains here are working just fine though, lighting and all. The only problem we're having with them at the moment is the ugly low texture resolution (as a detail overlay isn't suitable for what we're after).
so potentially this whole issue is just a massive bug in the shaders for dynamic lights.
Quote:OK can one of you point me in the direction of how to do a shader for a transparent texture?Sure thing. :-)
First, in creating the texture you need to make sure that the alpha channel is stored correctly. If you're using Gimp then you're fine out-of-the-box. However, new versions of Photoshop do stuff differently and the alpha doesn't work in Torque. Theres a plugin called SuperPNG that does it right, so track that down using the search function (plenty of people around here have links to it). You want the original SuperPNG, not the new version, by the way.
Once you've got your texture you have to write a material script. Here's one of mine with working transparency:
new Material(material_testOpacity)
{
mapTo = "testOpacity.png";
baseTex[0] = "~/data/shapes/test/testOpacity.png";
translucent = true; // Enables the opacity mapping
};mapto: this tells Torque the name of the texture that the material should be mapped to. This must match the name of the material in your exported model. If you export from Maya you need the file extension, if you export from 3DS Max you don't. In some cases it's not required at all, but I include it all the time.baseTex[x]: this tells Torque what texture to use for the diffuse and alpha components. The alpha component of this should include your opacity information. The x indicates what render pass this texture is to be used for, with 0 indicating the first pass. As there's nothing particularly fancy going on here this is just a single pass material.
translucent: this tells Torque that the material should be rendered with translucency.
And, in its simplest form, that's really all there is to it. If you take a look here there's a list of other properties that you can experiment with.
#6
12/27/2007 (3:15 pm)
Richard you rock!! Thanks that is everything I needed to know. Yeah I already have SuperPNG.
#7
Now, back to the issue at hand regarding procedural shaders, transparency and dynamic lighting, anyone out there able to shed some light on the situation for me?
Cheers.
12/27/2007 (4:22 pm)
You're welcome, Ron, glad to have been of assistance :-)Now, back to the issue at hand regarding procedural shaders, transparency and dynamic lighting, anyone out there able to shed some light on the situation for me?
Cheers.
Torque Owner Richard Taylor
I've been doing more experimentation with this today and have got little further. I've looked into writing my own shaders and have learned a fair bit about HLSL. I'm confident that if I have to write my own that I'll be able to, but I really don't want to have to do that for every combination of effects where we may need both dynamic lighting and translucency.
I've taken a close lok at the demo app and I've noticed that, at least in their default forms, everything that's transparent also only takes account of the sun and not the various dynamic lights.
I've fiddled around with doing things in various different passes to get lighting working in procedural shaders, and as soon as the dynamic lighting is working the transparency stops. I've done graphics programming, but I'm no expert in the area (yet ;-) ), so it could still be something I'm missing.
My question is, can the procedural shader system provide transparency and dynamic lighting both at once?
Cheers for any pointers.