≡
Products
▼
Support
▼
Company
▼
Forum
Ambiera Forum
Discussions, Help and Support.
Create a new account
,
Search
, or Login:
Create reply in
Examples shaders
Posted by:
(you are not logged in)
Enter the missing letter in: "?nternational"
(you are not logged in)
Text:
[quote][b]Specularmap[/b] wrote: Unfortunately, there is only one light source, even of only two. Phong [code] var vertexShader = "varying vec3 normal;\n" + "varying vec3 vpos;\n" + "void main()\n" + "{\n" + " // vertex normal\n" + " normal = normalize(gl_NormalMatrix * gl_Normal);\n" + " // vertex position\n" + " vpos = vec3(gl_ModelViewMatrix * gl_Vertex);\n" + " // vertex position\n" + " gl_Position = ftransform();\n" + "}"; var fragmentShader = "varying vec3 normal;\n" + "varying vec3 vpos;\n" + "uniform float shininess;\n" + "void main()\n" + "{\n" + "float shininess = 40;\n" + " vec3 n = normalize(normal);\n" + " vec4 diffuse = vec4(0.0);\n" + " vec4 specular = vec4(0.0);\n" + " // the material properties are embedded in the shader (for now)\n" + " vec4 mat_ambient = vec4(1.0, 1.0, 1.0, 1.0);\n" + " vec4 mat_diffuse = vec4(1.0, 1.0, 1.0, 1.0);\n" + " vec4 mat_specular = vec4(1.0, 1.0, 1.0, 1.0);\n" + " // ambient term\n" + " vec4 ambient = mat_ambient * gl_LightSource[0].ambient;\n" + " // diffuse color\n" + " vec4 kd = mat_diffuse * gl_LightSource[0].diffuse;\n" + " // specular color\n" + " vec4 ks = mat_specular * gl_LightSource[0].specular;\n" + " // diffuse term\n" + " vec3 lightDir = normalize(gl_LightSource[0].position.xyz - vpos);\n" + " float NdotL = dot(n, lightDir);\n" + " if (NdotL > 0.0)\n" + " diffuse = kd * NdotL;\n" + " // specular term\n" + " vec3 rVector = normalize(2.0 * n * dot(n, lightDir) - lightDir);\n" + " vec3 viewVector = normalize(-vpos);\n" + " float RdotV = dot(rVector, viewVector);\n" + " if (RdotV > 0.0)\n" + " specular = ks * pow(RdotV, shininess);\n" + " gl_FragColor = ambient + diffuse + specular;\n" + "}"; var newMaterial = ccbCreateMaterial(vertexShader, fragmentShader, 0, null); var soldier = ccbGetSceneNodeFromName('soldier'); ccbSetSceneNodeMaterialProperty(soldier, 0, 'Type', newMaterial); ccbSetSceneNodeMaterialProperty(soldier, 1, 'Type', newMaterial); ccbSetSceneNodeMaterialProperty(soldier, 2, 'Type', newMaterial); ccbSetSceneNodeMaterialProperty(soldier, 4, 'Type', newMaterial); [/code] [img]http://i.imgur.com/3Aln5ED.jpg[/img][/quote]
Possible Codes
Feature
Code
Link
[url] www.example.com [/url]
Bold
[b]bold text[/b]
Image
[img]http://www.example.com/image.jpg[/img]
Quote
[quote]quoted text[/quote]
Code
[code]source code[/code]
Emoticons
Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact