OpenGL high level shader setup with more than one texture

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Silbermünze
Posts: 34
Joined: Thu Sep 15, 2005 12:27 pm
Location: Stuttgart, Germany

OpenGL high level shader setup with more than one texture

Post by Silbermünze »

I am currently trying to get my shader working in IrrlichtNETCP. However, as the mechanism within IrrlichtNETCP is the same as in Irrlicht, I post my question here.
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);
An the associated callback function

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);
            }               
        }
Earth and Earth night are the names for the sampler2D variables of the fragment shader(see below)

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 shader is verified to work in Rendermonkey.

The image I get with my Irrlicht application:
Image
The white square is just an untextured billboard to indicate the light's current position.

The image I get with Rendermonkey
Image

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
Post Reply