Hello guys,
I'm with a difficult here:
I want a shader that can project one image on a textured object.
I want to add this projection to a EMT_SOLID or another Irrlicht default material type.
But, I don't want to "reinvent the wheel" and I would be happy if I can use the Irrlicht E_MATERIAL_TYPE as basis and only add new features to them. I have two questions:
- Can I "mix" my shader with one default shader?
- Where is the default Irrlicht shaders? So I can copy them and add my lines.
Thanks for the help!
Using default shaders as base [SOLVED AGAIN]
-
- Posts: 260
- Joined: Thu Apr 17, 2008 1:38 pm
- Location: Brasopolis - Brazil
Using default shaders as base [SOLVED AGAIN]
Last edited by Auradrummer on Thu Aug 25, 2011 7:32 pm, edited 3 times in total.
Professional Software Developer and Amateur Game Designer
-
- Posts: 1215
- Joined: Tue Jan 09, 2007 7:03 pm
- Location: Leuven, Belgium
-
- Posts: 260
- Joined: Thu Apr 17, 2008 1:38 pm
- Location: Brasopolis - Brazil
-
- Posts: 260
- Joined: Thu Apr 17, 2008 1:38 pm
- Location: Brasopolis - Brazil
Hello guys.
I almost reproduced the EMT_SOLID. Is not exactly, but is too nearby. You can use it to develop your shader over, I think would be useful for someone, as it was for me.
I used the references from Lighthouse3D http://www.lighthouse3d.com/tutorials/g ... /lighting/
And the OpenGL Shading Language Course from Typhoon Labs (the PDF's are inside the OpenGL official site).
Here is the shaders:
That's it.
I almost reproduced the EMT_SOLID. Is not exactly, but is too nearby. You can use it to develop your shader over, I think would be useful for someone, as it was for me.
I used the references from Lighthouse3D http://www.lighthouse3d.com/tutorials/g ... /lighting/
And the OpenGL Shading Language Course from Typhoon Labs (the PDF's are inside the OpenGL official site).
Here is the shaders:
Code: Select all
//VERTEX SHADER
uniform mat4 mTransWorld;
void main()
{
float dotP, NdotHV, dist, att;
vec3 normal, lightDir;
vec4 diffuse, ambient, globalAmbient, specular;
dist = length(gl_LightSource[0].position.xyz - gl_Vertex.xyz);
att = 1.0 / (gl_LightSource[0].constantAttenuation +
gl_LightSource[0].linearAttenuation * dist+
gl_LightSource[0].quadraticAttenuation * dist * dist);
normal = gl_Normal;
lightDir = vec4(gl_LightSource[0].position * mTransWorld);
lightDir = normalize(lightDir);
dotP = max(dot(normal,lightDir),0.0);
diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse * att;
ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
globalAmbient = gl_LightModel.ambient * gl_FrontMaterial.ambient;
if (dotP > 0.0)
{
NdotHV = max(dot(normal,gl_LightSource[0].halfVector.xyz),0.0);
specular = gl_FrontMaterial.specular * gl_LightSource[0].specular * pow(NdotHV, gl_FrontMaterial.shininess);
};
gl_FrontColor = dotP * diffuse + globalAmbient + ambient + specular;
gl_Position = ftransform();
}
Code: Select all
//FRAGMENT SHADER
sampler2D tex0 : register(s0);
void main()
{
vec4 tex = texture2D(tex0,gl_TexCoord[0]);
vec4 Color = tex * gl_Color;
Color.a = 1.0;
gl_FragColor = Color;
}
Professional Software Developer and Amateur Game Designer
Auradrummer, that's slightly wrong. You should pass the variables you need to the fragment shader and do the calculations there. The variables will get automatically interpolated and you will get per pixel lighting, whereas now you get only per vertex. The difference in the looks is vast, and the cost compared to your current code minimal(could e even faster under some circumstances).
So, technically, there's nothing wrong with your code, but why have per vertex lighting when you can get per pixel?
So, technically, there's nothing wrong with your code, but why have per vertex lighting when you can get per pixel?
irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps
Step back! I have a void pointer, and I'm not afraid to use it!
Height2Normal v. 2.1 - convert height maps to normal maps
Step back! I have a void pointer, and I'm not afraid to use it!
-
- Posts: 260
- Joined: Thu Apr 17, 2008 1:38 pm
- Location: Brasopolis - Brazil
Re: Using default shaders as base (unnoticed problem)
I'm having a problem, that I passed over it last time.
I made two balls, one EMT_SOLID and another with my "SOLID" shader.
When the light orbits around the two balls, everything is ok, both of them are almost identical.
But, when the camera orbits, the lighting of my shader spins two and the "EMT_SOLID" keeps lighting from the same place.
I know is some transformation, but I cannot figure out what is the transformation I have to do.
Where I can learn about this?
Thanks!
I made two balls, one EMT_SOLID and another with my "SOLID" shader.
When the light orbits around the two balls, everything is ok, both of them are almost identical.
But, when the camera orbits, the lighting of my shader spins two and the "EMT_SOLID" keeps lighting from the same place.
I know is some transformation, but I cannot figure out what is the transformation I have to do.
Where I can learn about this?
Thanks!
Professional Software Developer and Amateur Game Designer
-
- Posts: 260
- Joined: Thu Apr 17, 2008 1:38 pm
- Location: Brasopolis - Brazil
Re: Using default shaders as base (unnoticed problem)
I'm discovering new things:
- The gl_lightsource[0].position is transformed byt the view matrix.
As I'm noticing, this value has been transformed two times, and should be only one.
I'll keep looking for, but I'm making some progress.
- The gl_lightsource[0].position is transformed byt the view matrix.
As I'm noticing, this value has been transformed two times, and should be only one.
I'll keep looking for, but I'm making some progress.
Professional Software Developer and Amateur Game Designer
-
- Posts: 260
- Joined: Thu Apr 17, 2008 1:38 pm
- Location: Brasopolis - Brazil
Re: Using default shaders as base [SOLVED AGAIN]
Searching around I found in the Clockwork Coders tutorial something nice:
http://www.opengl.org/sdk/docs/tutorial ... ghting.php
This is a simple "EMT_SOLID" material made by fragment shader. Worke very well in my tests.
This appears to solve my problems and implements what ent1ty said. Really, seems good.
http://www.opengl.org/sdk/docs/tutorial ... ghting.php
This is a simple "EMT_SOLID" material made by fragment shader. Worke very well in my tests.
This appears to solve my problems and implements what ent1ty said. Really, seems good.
Professional Software Developer and Amateur Game Designer