ok, first of all: THANKS a lot Spike for your help!
FTE crashes when loading your defaultwall.glsl. I tried loading also old defaultwall, eg_defaultwall, and eg_drawflat_wall and they all crash. The others work.
Now, after a lot of study, thanks to your files, I understood (hopefully!) how passes work in GLSL and FTE
when you declare a texture 2d
That will be the first in the shader block from the top, s_t1 will be the second, s_t2 the third and so on.
That's how I re-managed your file to make it work
Code: Select all
#include "sys/defs.h"
varying vec3 eyevector;
varying mat3 invsurface;
varying vec2 tc;
#ifdef VERTEX_SHADER
void main ()
{
vec3 eyeminusvertex = e_eyepos - v_position.xyz;
eyevector.x = dot(eyeminusvertex, v_svector.xyz);
eyevector.y = dot(eyeminusvertex, v_tvector.xyz);
eyevector.z = dot(eyeminusvertex, v_normal.xyz);
invsurface[0] = v_svector;
invsurface[1] = v_tvector;
invsurface[2] = v_normal;
tc = v_texcoord;
gl_Position = ftetransform();
}
#endif
#ifdef FRAGMENT_SHADER
//samplers
uniform sampler2D s_t0;//diffuse pass
uniform sampler2D s_t1;//cubemask pass - mask to choose which part cubemap affects
uniform samplerCube s_t2;//cubemap pass
void main ()
{
gl_FragColor = texture2D(s_t0, tc);//yay, regular texture!
vec3 norm = vec3(0, 0, 1); //specular lighting expects this to exist.
vec3 rtc = reflect(-eyevector, norm);
rtc = rtc.x*invsurface[0] + rtc.y*invsurface[1] + rtc.z*invsurface[2];
rtc = (m_model * vec4(rtc.xyz,0.0)).xyz;
gl_FragColor.rgb += texture2D(s_t1, tc).rgb * textureCube(s_t2, rtc).rgb;
gl_FragColor = gl_FragColor * e_colourident;
}
#endif
Now, the shader
Code: Select all
textures/wall/wallfoo
{
program ton_cubemaps
{
map textures/wall/wallfoo.tga //diffuse texture
}
{
map textures/wall/wallfoo_reflect.tga //mask to choose which part cubemap affects
}
{
map $cube:textures/cubes/sky //cubemap
}
}
With your great shader now I can make very cool effect: you were right, cubemask (especially when colored) permits to simulate metal! Cool!
The only thing it doesn't work it's $lightmap. If I add:
It removes cubemap. I tried to add another pass s_t3 copying from your glsl file
Code: Select all
varying vec2 lm0;
vec3 lightmaps = (texture2D(s_t3 , lm0) * e_lmscale).rgb;
gl_FragColor.rgb *= lightmaps.rgb;
But engine yells a warning that it can't find v_lmcoord and e_lmscale
The only thing I don't understand it's why earlier you wrote this shader like this
program defaultwall
//diffusemap $blackimage //default is textures/world/wall_foobar2000.tga of course
normalmap $identitynormal //identity ensures that we get a perfect reflection for this example (otherwise it'll default to something based upon the shader name, or possibly even generate one from the 8bit data in a q1bsp).
//specularmap $blackimage
//fullbrightmap $blackimage
reflectcube textures/cubes/sky //your cubemap image(s) to display
reflectmask $whiteimage //texture that says which parts of the texture should show the reflection. white for on, black for off. tint for various types of metal.
"normalmap" for example, doesn't not exist in FTE source code, "reflectcube" neither. In your defaultwall.glsl there were s_reflectcube and s_normalmap. Are they related to those directive you wrote in the shader?
Thanks again for your huge help!