[Interest] ADDING LIGHTING EFFECT TO AN EXISTING Qt PROJECT

Amey Patil amey.patil at sjsu.edu
Thu Jun 26 23:59:30 CEST 2014


Hello Sir,Ma'am,

I have a Qt project of a rotating cube using shaders. I want to add the
light effect to it.
How do I combine the two shader files into one mainWindow?

also these fragment and vertex files are in .frag and .vs while, the one
which I have are in .glsl (both). Is it a problem?

Attaching the lighting code which i got online with this mail.

thanks in advance.

Sincere Regards,
Amey Patil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140626/ba67d0f2/attachment.html>
-------------- next part --------------
//http://www.youtube.com/user/thecplusplusguy
//GLSL tutorial - per-fragment (per-pixel lighting)
//fragment.frag
#version 120
varying vec3 position;
varying vec3 normal;

uniform vec3 lightPos;

uniform vec3 mambient;	//gl_FrontMaterial
uniform vec3 mdiffuse;
uniform vec3 mspecular;
uniform float shininess;

uniform vec3 lambient;	//gl_LightSource[0]
uniform vec3 ldiffuse;
uniform vec3 lspecular;


void main()
{
	float dist=length(position-lightPos);	//distance from light-source to surface
	float att=1.0/(1.0+0.1*dist+0.01*dist*dist);	//attenuation (constant,linear,quadric)
	vec3 ambient=mambient*lambient;	//the ambient light
	
	vec3 surf2light=normalize(lightPos-position);
	vec3 norm=normalize(normal);
	float dcont=max(0.0,dot(norm,surf2light));
	vec3 diffuse=dcont*(mdiffuse*ldiffuse);
	
	vec3 surf2view=normalize(-position);
	vec3 reflection=reflect(-surf2light,norm);
	
	float scont=pow(max(0.0,dot(surf2view,reflection)),shininess);
	vec3 specular=scont*lspecular*mspecular;
	
	gl_FragColor=vec4((ambient+diffuse+specular)*att,1.0);	//<- don't forget the paranthesis (ambient+diffuse+specular)
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: glsl_tutorial_4_-_main.cpp.cpp
Type: text/x-c++src
Size: 4783 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140626/ba67d0f2/attachment.cpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: glsl_tutorial_4_-_vertex.vs.cpp
Type: text/x-c++src
Size: 498 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140626/ba67d0f2/attachment-0001.cpp>


More information about the Interest mailing list