Game Development Community

Light on translucent object...

by Tobias Niva · in Torque Game Engine Advanced · 10/30/2007 (6:36 pm) · 8 replies

Hi.

I'm having some troubles with an object that has som transperent parts.
My problem is that this object is not lit...

This is what I have in my material:

new Material(matPodium)
{
baseTex[0] = "podium";
translucent = true;
translucentBlendOp = LerpAlpha;
translucentZWrite = true;
alphaTest = true;
alphaRef = 20;
};

I tried with different blend op's but with no good results.
Earlier I had the emissive flag set to true - and sure - the object is lit or rather self illuminated.
But I want the object to still "react" to light and shading as it would if it wasn't translucent.
Do I have to get into making a custom material or shader to get what I want?!

#1
10/31/2007 (3:18 am)
Split the object into a translucent and non translucent material.
Having it mixed might cause problems (especially depth sorting)

Is the material a DTS or part of a DIF?
#2
11/17/2007 (7:34 am)
The object is a dts.

I'm not sure that splitting it up will solve my problem?! I still want the part with the translucent material to recieve light and to shade "properly"...

Is this possible...or do I have to get into some serious shader hacking to get into this?!
#3
11/17/2007 (7:42 am)
Is your material set to be double sided when you export the DTS?
This have a tendency to mess up the normals which in turn makes the lighting incorrect.
#4
11/17/2007 (7:50 am)
Hi Magnus.

No, the material is not 2-sided.
(I noticed this NON lightning/shading with the 2-sided mat - so I'm sure that my object is using 1-sided mat)

My problem now (as stated above) is that my trans. mat. doesn't get lighted at all...if I not set the emissive flag to true - which I also understand IGNORE the lightning and makes the object/material self illuminated (fully lit).

So the problem still stands - how to get a trans. mat. to recieve light/shading a "basic" material, and still use the alpha for transparency.
#5
11/19/2007 (10:22 am)
OK, just use alpha channel in custommaterial (called alpha pipe transaction in SM 1.4).
For example: this is Phong Diffuse + Ambient mapping WORKING, i did it for 15 minutes,just decided to help
//**************diffuseV.hlsl*************************
#define IN_HLSL
#include "shdrConsts.h"

struct VertData
{ float4 texCoord : TEXCOORD0;
float4 normal1 : NORMAL;
float4 position : POSITION; };

struct ConnectData
{ float4 hpos : POSITION;
float4 texCoord : TEXCOORD0;
float4 shading : COLOR; };

//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
ConnectData main( VertData IN,
uniform float4x4 modelview : register(VC_WORLD_PROJ),
uniform float3 inLightVec : register(C24) )
{ ConnectData OUT;
OUT.hpos = mul(modelview, IN.position); // vertex transformation
OUT.texCoord = IN.texCoord; // use same texture coords
OUT.shading = saturate(dot(-inLightVec, IN.normal1)); // Phong SM Formula
return OUT; }


//*************diffuseP.hlsl*************************************
struct ConnectData
{ float4 texCoord : TEXCOORD0;
float4 shading : COLOR; };

struct Fragout
{float4 col : COLOR0;};


//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
Fragout main( ConnectData IN,
uniform float4 ambient : register(C2) )
{ Fragout OUT;
OUT.col = IN.shading + ambient;
return OUT; }
//***********************************


then use custommaterial :
//********************

new CustomMaterial(DiffuseMaterial)
{
version = 2.0; // hardware limit
mapTo = "flag"; // assign the texel render

// your alpha modulation
translucent = true;
translucentBlendOp = LerpAlpha;
translucentZWrite = true;
alphaTest = true;
alphaRef = 20;

// diffuse map
texture[0] = "~/data/shapes/cube/briks";
shader = TempShader; // shaderdata

};
//*******************

new ShaderData( TempShader )
{
DXVertexShaderFile = "shaders/diffuseV.hlsl";
DXPixelShaderFile = "shaders/diffuseP.hlsl";
pixVersion = 2.0; // soft SM usage
};

//*******************************

addMaterialMapping("flag", "material: DiffuseMaterial");

You just need a few HLSL skills, pal. It is not difficult at all.
#6
02/05/2008 (4:10 pm)
Hmm...ok.
Not to sound too rude...but I'm not that good of a coder, so believing that I'll be able create this effect coding HLSL seems quite unlikely to me.

Any hints on good resources to get to understand HLSL? Or anyone who have a shader that is quite near of what I'm after?

Like I'm saying here, I'm more of an artist than a programmer...

Thanx anyways!
#7
02/05/2008 (6:26 pm)
Picasso, I just tried your shaders for this alpha lighting and it didnt work. The whole texture was clear and it had a blue colour to it.
#8
02/05/2008 (10:30 pm)
*sigh*

I fiddled around with this....trying to understand shaders...with no direct luck (sad non-coder as I am).

Anyone who had a go at a shader that handles both translucency and "shading" on top of it?!

Seems like there's something GG just put on ice....since it's no logic in having the emissive-flag to be set to true - isn't this that "disregard" ALL shading what so ever?!