Problem with Gloss Map Mode

Hi, I have a problem with Gloss Map Mode: I can’t set it.

Hi have this program:

import direct.directbase.DirectStart
from panda3d.core import Spotlight, TextureStage

base.disableMouse()

base.camera.set_pos(0, -10, 8)
base.camera.look_at(0, 0, 5)

slight = Spotlight('slight')
slight.setColor((1, 1, 1, 1))
slnp = render.attachNewNode(slight)
slnp.setPos(0, -10, 10)
slnp.lookAt(0, 0, 5)
render.setLight(slnp)

render.setShaderAuto()

m1 = loader.loadModel('gloss')
m1.reparent_to(render)
m1.setPos(-.2, 0, 5)

ts = TextureStage('ts')
ts.setMode(TextureStage.MGloss)
m1.setTexture(ts, loader.loadTexture('gloss.jpg'))

m2 = loader.loadModel('nogloss')
m2.reparent_to(render)
m2.setPos(.2, 0, 5)

base.run()

There are two models, I’m trying to set the gloss map on the left one, but I can’t: they look identical. Here is an excerpt from the egg file of the model:

...
<Texture> gloss {
  "gloss.jpg"
  <Scalar> envtype { GLOSS }
  <Scalar> format { alpha }
  <Scalar> minfilter { LINEAR_MIPMAP_LINEAR }
  <Scalar> magfilter { LINEAR_MIPMAP_LINEAR }
  <Scalar> wrap { REPEAT }
}
...

What am I missing? Thank you very much!

PS I’ve attached models and textures to this post.
gloss.zip (81.9 KB)

The gloss map is read from the alpha channel. If you don’t have it in the alpha channel, you can do this:

loader.loadTexture('gloss.jpg', 'gloss.jpg')

Or this in .egg:

<Scalar> alpha-filename { gloss.jpg }

Hi rdb, thank you for the support!

I’m sorry, I tried to apply your suggestions, but I can’t see differences.

I’ve added this code to the previous one:

...
ts = TextureStage('ts')
ts.setMode(TextureStage.MGloss)
m1.setTexture(ts, loader.loadTexture('gloss.jpg', 'gloss.jpg'))
...

And I’ve modified the texture in the egg file:

...
<Texture> gloss {
  "gloss.jpg"
  <Scalar> envtype { GLOSS }
  <Scalar> alpha-file { gloss.jpg }
  <Scalar> minfilter { LINEAR_MIPMAP_LINEAR }
  <Scalar> magfilter { LINEAR_MIPMAP_LINEAR }
  <Scalar> wrap { REPEAT }
}
...

What am I missing? Thank you very much!

PS I have attached the new files to this post.
gloss.zip (82 KB)

I think there must be a bug in the shader generator. This is the Cg code dumped with dump-generated-shaders 1:

//Cg
/* Generated shader for render state:
  LightAttrib:on
    render/slight
  MaterialAttrib:Material Material.001 a(0.8 0.8 0.8 1) d(0.8 0.8 0.8 1) s(0 0 0 1) e(0 0 0 1) s12.5 l0 t0
  RescaleNormalAttrib:none
  ShaderAttrib
  TextureAttrib:on ts:gloss^1 default:diffuse gloss:gloss
*/
void vshader(
	 in float4 vtx_texcoord : TEXCOORD0,
	 out float4 l_texcoord : TEXCOORD0,
	 uniform float4x4 trans_model_to_view,
	 out float4 l_eye_position : TEXCOORD1,
	 uniform float4x4 tpose_view_to_model,
	 out float4 l_eye_normal : TEXCOORD2,
	 in float3 vtx_normal : NORMAL,
	 float4 vtx_position : POSITION,
	 out float4 l_position : POSITION,
	 uniform float4x4 mat_modelproj
) {
	 l_position = mul(mat_modelproj, vtx_position);
	 l_eye_position = mul(trans_model_to_view, vtx_position);
	 l_eye_normal.xyz = mul((float3x3)tpose_view_to_model, vtx_normal);
	 l_eye_normal.w = 0;
	 l_texcoord = vtx_texcoord;
}

void fshader(
	 in float4 l_eye_position : TEXCOORD1,
	 in float4 l_eye_normal : TEXCOORD2,
	 in float4 l_texcoord : TEXCOORD0,
	 uniform sampler2D tex_0,
	 uniform sampler2D tex_1,
	 uniform sampler2D tex_2,
	 uniform float4x4 slight_slight0_rel_view,
	 uniform float4   satten_slight0,
	 uniform float4x4 attr_material,
	 out float4 o_color : COLOR0,
	 uniform float4 attr_color,
	 uniform float4 attr_colorscale
) {
	 float4 result;
	 float4 texcoord0 = l_texcoord;
	 float4 texcoord1 = l_texcoord;
	 float4 texcoord2 = l_texcoord;
	 // Fetch all textures.
	 float4 tex0 = tex2D(tex_0, texcoord0.xy);
	 float4 tex1 = tex2D(tex_1, texcoord1.xy);
	 float4 tex2 = tex2D(tex_2, texcoord2.xy);
	 // Correct the surface normal for interpolation effects
	 l_eye_normal.xyz = normalize(l_eye_normal.xyz);
	 // Begin view-space light calculations
	 float ldist,lattenv,langle;
	 float4 lcolor,lspec,lvec,lpoint,latten,ldir,leye,lhalf;
	 float4 tot_diffuse = float4(0,0,0,0);
	 // Spot Light 0
	 lcolor = slight_slight0_rel_view[0];
	 lspec  = slight_slight0_rel_view[1];
	 lpoint = slight_slight0_rel_view[2];
	 ldir   = slight_slight0_rel_view[3];
	 latten = satten_slight0;
	 lvec   = lpoint - l_eye_position;
	 ldist  = length(float3(lvec));
	 lvec /= ldist;
	 langle = saturate(dot(ldir.xyz, lvec.xyz));
	 lattenv = 1/(latten.x + latten.y*ldist + latten.z*ldist*ldist);
	 lattenv *= pow(langle, latten.w);
	 if (langle < ldir.w) lattenv = 0;
	 lcolor *= lattenv * saturate(dot(l_eye_normal.xyz, lvec.xyz));
	 tot_diffuse += lcolor;
	 // Begin view-space light summation
	 result = float4(0,0,0,0);
	 result += tot_diffuse * attr_material[1];
	 result = saturate(result);
	 // End view-space light calculations
	 result.rgb *= tex1.rgb;
	 result *= attr_colorscale;
	 o_color = result * 1.000001;
}

tex0 and tex1 have no effect on the value written by the shader.

Probably because either your light or material has no specular color.