Simple Shader fails on PC

I’ve got a shader which runs 2 passes to isolate the specular and multiply by a specular map using GLES1.1 on iPhone.

The same shader works fine on the Mac, but not on my PC. I’ve now been asked to supply a demo on PC, but this broken shader is causing me a problem!

Essentially, I’m getting no specular at all. I’ve minimised the shader to the bare minimum :-

Shader “iPhone/SpecDetail” {
Properties {
_Color (“Main Color”, Color) = (1,1,1,1)
_SpecColor (“Spec Color”, Color) = (1,1,1,1)
_Shininess (“Shin”, Range (0,1)) = 0.7
_MainTex (“Base (RGB)”, 2D) = “white” {}
_SpecTex (“Base (RGB)”, 2D) = “white” {}
}
SubShader {

Pass{
Blend Off

Material{
Specular [_SpecColor]
Shininess [_Shininess]
}
Lighting On

SetTexture [_SpecTex] { combine texture * primary, texture}
}
}
}

which should show me JUST my specular component. But I just get black. (Light Colour is set to white, specular white, and my SpecTex texture is gray scale)

Anyone know why this might not be working?

What is the reason for not storing it in an alpha channel then?

I don’t have a PC to test with, but fixed function ShaderLab seems to have more bugs on the PC than on the Mac, from what I’ve seen on the forum. It’s probably due to the multitude of GPUs out there, and the general superiority of the Windows GPU scene, where support for fixed function shaders probably isn’t a priority. You’d be better off writing a Cg SubShader.

Also, is a texture map actually necessary for this? Wouldn’t the specular map be better served by vertex colors (vertex alpha even)? This used to be easily doable with ColorMaterial Specular, but that has been removed, in a rather obnoxious fashion.

P.S. Please wrap code in code tags.

It’s a gray texture as it’s better to have it compressed on iOS. (The full effect is to have detailed specular map to simulate a certain type of surface). As you can’t extract the specular part of the lighting on ES1.1, it has to be 2 passes anyway. Just using the alpha channel would work, but you’d need a 32bit texture for decent results, as PVR4 bit with alpha doens’t look great. You get much nicer results using 1 compressed 4bit RGB texture for the main texture, and additioanlly compressing the specular map.

I was hoping not to have to write a brand new shader specifically for a demo on PC… but guess I’ll have to unless anyone knows a way of gettin git working. Can’t just be my graphics card, as I’ve tried it on about 4 PCs and they’re all the same!

Of course you do. But the devices that your shader is intended for may not have memory for that entire extra texture. (I’m sure that you’ve tested this for your own case; I’m speaking about general practice.) Have you tried at least using the Dot3 combiner to isolate a channel from a compressed RGB texture? You can get three greyscale textures that way, but I haven’t tested yet to see how much of a performance cost it is.

Yeah, if I needed more than one specular map that would be the way to go if memory became and issue. There’s only one asset that needs this shader however so memory’s not an issue here. Would need 2 combiner instructions as opposed to 1, and I’ve not benchmarked that on iOS either TBH.

You lose half the bit depth of the texture, too.