Laser Shader (with pictures)

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
nathanf534
Posts: 199
Joined: Tue Dec 09, 2008 2:55 am

Laser Shader (with pictures)

Post by nathanf534 »

It uses glsl, so its only for openGl, sorry.

Image

Image

Fragment Shader

Code: Select all

varying vec3 normal;
void main (void){
    vec3 n,lightDir;
    lightDir=vec3(0,0,1);
    float d;
    n = normalize(normal);
    d = abs(dot(n,normalize(lightDir)));
    d=d/270.0;
    gl_FragColor = vec4(d*d*65536.0,max(d*d*524288.0,50),d*d*65536.0,255);
}

Vertex Shader

Code: Select all

varying vec3 normal;
void main(void){
    normal = normalize(gl_NormalMatrix * gl_Normal);				
    gl_Position = ftransform();
}
Just make a cylinder mesh, and set this as the material.

example:

Code: Select all

laserMaterial=gpu->addHighLevelShaderMaterialFromFiles(vertexShader,"vertexMain",video::EVST_VS_1_1,pixelShader,"pixelMain", video::EPST_PS_1_1,sc,video::EMT_TRANSPARENT_ADD_COLOR);
ISceneNode* laser=smgr->addMeshSceneNode(mesh,0,0,vector3df(0,100,0),vector3df(0),vector3df(1,10,1),false);
	laser->setMaterialFlag(EMF_LIGHTING,false);
	laser->setMaterialType((E_MATERIAL_TYPE)laserMaterial);
Last edited by nathanf534 on Mon Jul 19, 2010 8:30 pm, edited 3 times in total.
while(signatureEmpty){cout<<wittyComment();}
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

Screenshots for those of us who aren't sitting in front of our compiler?
nathanf534
Posts: 199
Joined: Tue Dec 09, 2008 2:55 am

Post by nathanf534 »

The screenshots should be working now.
Last edited by nathanf534 on Mon Jul 19, 2010 8:03 pm, edited 1 time in total.
while(signatureEmpty){cout<<wittyComment();}
ent1ty
Competition winner
Posts: 1106
Joined: Sun Nov 08, 2009 11:09 am

Post by ent1ty »

They work, but they take about 5 minutes to load :?
Edit: or maybe you already fixed them
Edit2: it looks quite nice, good work! :)
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!
Post Reply