/**
* Example Fragment Shader
* Sets the color and alpha of the pixel by setting gl_FragColor
*/
// Set the precision for data types used in this shader
precision highp float;
precision highp int;
// Default THREE.js uniforms available to both fragment and vertex shader
uniform mat4 modelMatrix;
uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform mat3 normalMatrix;
// Default uniforms provided by ShaderFrog.
uniform vec3 cameraPosition;
uniform float time;
// A uniform unique to this shader. You can modify it to the using the form
// below the shader preview. Any uniform you add is automatically given a form
uniform vec3 albedoColor;
uniform vec3 lightPosition;
uniform vec3 sunColor;
uniform float sunStrength;
uniform samplerCube iblCube;
uniform vec3 iblColor;
uniform float iblStrength;
uniform vec3 rimColor;
uniform float rimStrength;
uniform float rimWidth;
// Example varyings passed from the vertex shader
varying vec3 vPosition;
varying vec3 vNormal;
varying vec2 vUv;
varying vec2 vUv2;
void main()
{
vec3 worldPosition = ( modelMatrix * vec4( vPosition, 1.0 )).xyz;
vec3 worldNormal = normalize( vec3( modelMatrix * vec4( vNormal, 0.0 ) ) );
vec3 lightVector = normalize( lightPosition - worldPosition );
vec3 viewVector = normalize(cameraPosition - worldPosition);
float rimndotv = max(0.0, rimWidth - clamp(dot(worldNormal, viewVector), 0.0, 1.0));
vec3 rimLight = rimndotv * rimColor * rimStrength;
vec3 reflection = reflect(-viewVector, worldNormal);
vec3 iblLight = iblColor * textureCube(iblCube, reflection).rgb * iblStrength;
float ndotl = max(0.0, dot(worldNormal, lightVector));
vec3 sunLight = sunColor * sunStrength * ndotl;
vec3 finalLight = rimLight + iblLight + sunLight;
// Fragment shaders set the gl_FragColor, which is a vector4 of
// ( red, green, blue, alpha ).
gl_FragColor = vec4( albedoColor * finalLight, 1.0 );
}
This shader has no description
This shader has no tags.
No comments
Add a comment