forked from BKcore/Shdr
-
Notifications
You must be signed in to change notification settings - Fork 5
Help
Ansley Chen edited this page Dec 13, 2016
·
5 revisions
This is the help page for Shdr
This update mode will recompile your shaders and update the viewer upon every keystroke in the editor. Choose auto update if you would like to see your changes immediately. If you are experiencing delays or lags in this mode, please use a less demanding update mode.
This mode will update the viewer everytime the key is used in the editor.
This mode will update the viewer everytime the key combination and is used in the editor.
uniform mat3 normalMatrix;
uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
uniform vec2 resolution;
uniform float time;
attribute vec3 position;
attribute vec3 normal;
precision highp float;
attribute vec3 position;
attribute vec3 normal;
uniform mat3 normalMatrix;
uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
varying vec3 fNormal;
varying vec3 fPosition;
void main()
{
fNormal = normalize(normalMatrix * normal);
vec4 pos = modelViewMatrix * vec4(position, 1.0);
fPosition = pos.xyz;
gl_Position = projectionMatrix * pos;
}
precision highp float;
uniform float time;
uniform vec2 resolution;
varying vec3 fPosition;
varying vec3 fNormal;
uniform vec3 MatAmb;
uniform vec3 MatDif;
uniform vec3 MatSpec;
uniform float shine;
void main()
{
vec3 lightColor = vec3(1.0, 1.0, 1.0);
vec3 lightPos = vec3(1.0, 1.0, 1.0);
float diffuseDot = dot(normalize(fNormal), normalize(lightPos));
vec3 diffuse = MatDif * max(0.0, diffuseDot) * lightColor;
vec3 reflectance = normalize(normalize(-lightPos) + (2.0 * diffuseDot * normalize(fNormal)));
float specularDot = dot(normalize(-fPosition), reflectance);
vec3 specular = MatSpec * pow(max(0.0, specularDot), shine) * lightColor;
vec3 ambient = MatAmb * lightColor;
vec3 fragColor = ambient + specular + diffuse;
gl_FragColor = vec4(fragColor, 1.0);
}
vec3 MatAmb = vec3(0.24725, 0.1995, 0.0745);
vec3 MatDif = vec3(0.75164, 0.60648, 0.22648);
vec3 MatSpec = vec3(0.628281, 0.555802, 0.366065);
float shine = 0.4;
You can add vec3, vec2, float, and boolean type variables as a uniform.