I am using the Irrlicht3D engine to develop a Visualization application for my current research. However, since I am developing on a mac I am using OpenGL rendering with Irrlicht. I have written my own, basic shader to use with irrlicht but I am not quite sure how I communicate from within the program, to the shader. Essentially I want to be able to draw a 3d cube (or sphere) and control the color and alpha value of it from within my program. Does anyone know how I do this?
Here are my working vertex and fragment shaders, and everything looks exactly how I would like it to, all that is left is figureing out how to mesh it with my code.
Vertex Shader:
Code: Select all
void main() {
vec3 normal, lightDir;
vec4 diffuse;
float NdotL;
/* first transform the normal into eye space and normalize the result */
normal = normalize(gl_NormalMatrix * gl_Normal);
/* now normalize the light's direction. Note that according to the
OpenGL specification, the light is stored in eye space. Also since
we're talking about a directional light, the position field is actually
direction */
lightDir = normalize(vec3(gl_LightSource[0].position));
/* compute the cos of the angle between the normal and lights direction.
The light is directional so the direction is constant for every vertex.
Since these two are normalized the cosine is the dot product. We also
need to clamp the result to the [0,1] range. */
NdotL = max(dot(normal, lightDir), 0.0);
/* Compute the diffuse term */
diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;
gl_FrontColor = NdotL * diffuse;
gl_Position = ftransform();
}
Code: Select all
void main()
{
gl_FragColor = gl_Color;
}
Also, which matricies do I have to set. I notice in the irrlicht tutorial they set the mInvWorld, mWorldViewProj, mLightPos, mLightColor, mTransWorld. What are the neccessary, analogous matricies I must send for GLSL?
Here is my ShaderCallBack class, with all the highlevel checking removed since I know I am going to use it, and have to use OpenGL.
Code: Select all
class MyShaderCallBack : public video::IShaderConstantSetCallBack
{
public:
virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
{
video::IVideoDriver* driver = services->getVideoDriver();
// set inverted world matrix
// if we are using highlevel shaders (the user can select this when
// starting the program), we must set the constants by name.
core::matrix4 World = driver->getTransform(video::ETS_WORLD);
services->setVertexShaderConstant("mInvWorld", &invWorld.M[0], 16);
// set clip matrix
core::matrix4 worldViewProj;
worldViewProj = driver->getTransform(video::ETS_PROJECTION);
worldViewProj *= driver->getTransform(video::ETS_VIEW);
worldViewProj *= driver->getTransform(video::ETS_WORLD);
services->setVertexShaderConstant("mWorldViewProj", &worldViewProj.M[0], 16);
// set camera position
core::vector3df pos = device->getSceneManager()->
getActiveCamera()->getAbsolutePosition();
services->setVertexShaderConstant("mLightPos", reinterpret_cast<f32*>(&pos), 3);
// set light color
video::SColorf col(0.0f,1.0f,1.0f,0.0f);
services->setVertexShaderConstant("mLightColor", reinterpret_cast<f32*>(&col), 4);
// set transposed world matrix
core::matrix4 world = driver->getTransform(video::ETS_WORLD);
world = world.getTransposed();
services->setVertexShaderConstant("mTransWorld", &world.M[0], 16);
}
};
I assume here I am not seting the correct matrix constants.... I just need the basic ones to get this working so a little help in that department would be awesome.
Thanks all,