I have already seen the another post about multiple textures in shaders setup, which has not helped me resolve my problem so far.
My question is about how do I have to setup my material for an object to currectly use the shader for rendering and how to correctly pass the required data from Irrlicht to the shader.
My current approach:
Code: Select all
psFileName = "earth.frag";
vsFileName = "earth.vert";
newMaterialType1 = gpu.AddHighLevelShaderMaterialFromFiles(
vsFileName, "main", VertexShaderType._2_a,
psFileName, "main", PixelShaderType._2_a,
earthCallBack, MaterialType.Solid, 0);
// load base texture
mSphere.SetMaterialType((MaterialType)newMaterialType1);
Texture earthDiffuse = driver.GetTexture("Earth.jpg");
mSphere.SetMaterialTexture(0, earthDiffuse);
Texture earthNight = driver.GetTexture("EarthNight.jpg");
mSphere.SetMaterialTexture(1, earthNight);
mSphere.SetMaterialFlag(MaterialFlag.Lighting, false);
Code: Select all
public static void OnSetEarthConstants(MaterialRendererServices services, int userData)
{
Vector3D lightVec = mSphere.Position - mLight.Position;
lightVec.Normalize();
//device.Logger.Log("LightVector: " + lightVec.ToString());
if (UseHighLevelShaders)
{
services.SetVertexShaderConstant("pLightVec", vectorToArray(lightVec), 3);
float[] tex = new float[1];
tex[0] = (float)0; //Set sampler2D variable to texture stage of Earth-Day texture
services.SetPixelShaderConstant("Earth", tex, 1);
tex[0] = (float)1; //Set sampler2D variable to texture stage of Earth-Night texture
services.SetPixelShaderConstant("EarthNight", tex, 1);
}
}
I looked at the TSM Shaderpack for getting the info on how to setup
the sampler2D values, however I am unsure whether they are correct.
The fragment shader code variable definition starts like the following
Code: Select all
uniform sampler2D Earth, EarthNight;
varying float Diffuse;
varying vec3 Specular;
varying vec2 TexCoord;
The image I get with my Irrlicht application:
The white square is just an untextured billboard to indicate the light's current position.
The image I get with Rendermonkey
Another problem might be the fact that I am relying on OpenGL defined matrices in my shader like gl_ModelViewMatrix.
I read in a GLSL introduction that these variables are known in GLSL code scope. However possibly thats only the fact for GL2
shaders? What version of GLSL is actually supported in Irrlicht?
Thanks in advance
Silbermünze