≡
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: "Intern?tional"
(you are not logged in)
Text:
[quote][b]Specularmap[/b] wrote: Does not work. Black material.*cry* What is wrong here ?! [code] var vertexShader = "varying vec3 LightDir;\n" + "varying vec3 EyeDir;\n" + "varying vec3 Normal;\n" + "uniform vec3 LightPosition;\n" + "uniform float Scale;\n" + "void main(void) \n" + "{\n" + "vec4 pos = gl_ModelViewMatrix * gl_Vertex;\n" + "gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" + "vec3 eyeDir = vec3(pos);\n" + "gl_TexCoord[0] = gl_MultiTexCoord0;\n" + "vec3 n = normalize(gl_NormalMatrix * gl_Normal);\n" + "vec3 t = normalize(cross(vec3(1.141, 2.78, 3.14), n));\n" + "vec3 b = cross(n, t);\n" + "vec3 v;\n" + "v.x = dot(LightPosition, t);\n" + "v.y = dot(LightPosition, b);\n" + "v.z = dot(LightPosition, n);\n" + "LightDir = normalize(v);\n" + "v.x = dot(eyeDir, t);\n" + "v.y = dot(eyeDir, b);\n" + "v.z = dot(eyeDir, n);\n" + "EyeDir = normalize(v);\n" + "}"; var fragmentShader = "varying vec3 LightDir;\n" + "varying vec3 EyeDir;\n" + "varying vec3 Normal;\n" + "const vec3 color = vec3(0.7, 0.6, 0.18);\n" + "//const float Density = 16.0;\n" + "//const float Size = 0.25;\n" + "uniform float Density;\n" + "uniform float Size;\n" + "//uniform float Scale;\n" + "const float SpecularFactor = 0.5;\n" + "void main (void)\n" + "{\n" + " vec3 litColor;\n" + " vec2 c = Density * (gl_TexCoord[0].xy);\n" + " vec2 p = fract(c) - vec2(0.5);\n" + " float d = (p.x * p.x) + (p.y * p.y);\n" + " if (d >= Size)\n" + " p = vec2(0.0);\n" + " vec3 normDelta = vec3(-p.x, -p.y, 1.0);\n" + " litColor = color * max(0.0, dot(normDelta, LightDir));\n" + " float t = 2.0 * dot(LightDir, normDelta);\n" + " vec3 reflectDir = t * normDelta;\n" + " reflectDir = LightDir - reflectDir;\n" + "// vec3 reflectDir = LightDir - 2.0 * dot(LightDir, normDelta) * normDelta;\n" + " float spec = max(dot(EyeDir, reflectDir), 0.0);\n" + " spec = spec * spec;\n" + " spec = spec * spec;\n" + " spec *= SpecularFactor;\n" + " litColor = min(litColor + spec, vec3(1.0));\n" + " gl_FragColor = vec4(litColor, 1.0);\n" + "// gl_FragColor = vec4(Scale);\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] And should be like this: [img]http://i.imgur.com/cHATmv9.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