VuoShader implementation.
- Copyright
- Copyright © 2012–2014 Kosada Incorporated. This code may be modified and distributed under the terms of the MIT License. For more information, see http://vuo.org/license.
|
#define | VUOSHADER_GLSL_FRAGMENT_LIGHTING_HEADER " \ uniform mat4 modelviewMatrix; \ \ uniform vec3 cameraPosition; \ \ uniform vec4 ambientColor; \ uniform float ambientBrightness; \ \ struct PointLight \ { \ vec4 color; \ float brightness; \ vec3 position; \ float range; \ float sharpness; \ }; \ uniform PointLight pointLights[16]; \ uniform int pointLightCount; \ \ struct SpotLight \ { \ vec4 color; \ float brightness; \ vec3 position; \ vec3 direction; \ float cone; \ float range; \ float sharpness; \ }; \ uniform SpotLight spotLights[16]; \ uniform int spotLightCount; \ \ varying vec4 vertexPosition; \ varying mat3 vertexPlaneToWorld; \ \ void calculateLighting( \ in float specularPower, \ in vec3 normal, \ out vec3 ambientContribution, \ out vec3 diffuseContribution, \ out vec3 specularContribution \ ) \ { \ ambientContribution = ambientColor.rgb * ambientColor.a * ambientBrightness; \ diffuseContribution = specularContribution = vec3(0.); \ \ vec3 normalDirection = normalize(vertexPlaneToWorld * normal); \ \ int i; \ for (i=0; i<pointLightCount; ++i) \ { \ float lightDistance = distance(pointLights[i].position, vertexPosition.xyz); \ float range = pointLights[i].range; \ float sharpness = pointLights[i].sharpness; \ float lightRangeFactor = 1. - smoothstep(range*sharpness, range*(2-sharpness), lightDistance); \ \ vec3 scaledLightColor = lightRangeFactor * pointLights[i].color.rgb * pointLights[i].color.a * pointLights[i].brightness; \ \ vec3 incidentLightDirection = normalize(pointLights[i].position - vertexPosition.xyz); \ diffuseContribution += scaledLightColor * max(dot(normalDirection, incidentLightDirection), 0.); \ \ vec3 reflection = reflect(-incidentLightDirection, normalDirection); \ vec3 cameraDirection = normalize(cameraPosition.xyz - vertexPosition.xyz); \ specularContribution += scaledLightColor * pow(max(dot(reflection, cameraDirection), 0.), specularPower); \ } \ \ for (i=0; i<spotLightCount; ++i) \ { \ float lightDistance = distance(spotLights[i].position, vertexPosition.xyz); \ float range = spotLights[i].range; \ float sharpness = spotLights[i].sharpness; \ float lightRangeFactor = 1. - smoothstep(range*sharpness, range*(2-sharpness), lightDistance); \ \ vec3 incidentLightDirection = normalize(spotLights[i].position - vertexPosition.xyz); \ float cosSpotDirection = dot(-incidentLightDirection, spotLights[i].direction); \ float cone = spotLights[i].cone; \ float lightDirectionFactor = smoothstep(cos(cone*(2-sharpness)/2), cos(cone*sharpness/2), cosSpotDirection); \ \ vec3 scaledLightColor = lightRangeFactor * lightDirectionFactor * spotLights[i].color.rgb * spotLights[i].color.a * spotLights[i].brightness; \ \ diffuseContribution += scaledLightColor * max(dot(normalDirection, incidentLightDirection), 0.); \ \ vec3 reflection = reflect(-incidentLightDirection, normalDirection); \ vec3 cameraDirection = normalize(cameraPosition.xyz - vertexPosition.xyz); \ specularContribution += scaledLightColor * pow(max(dot(reflection, cameraDirection), 0.), specularPower); \ } \ } \" |
| Defines the uniforms passed by VuoSceneRenderer, the varyings provided by lightingVertexShaderSource , and the calculateLighting() function.
|
|
#define | VUOSHADER_GLSL_FRAGMENT_SOURCE_WITH_LIGHTING(source) "#version 120\n" VUOSHADER_GLSL_FRAGMENT_LIGHTING_HEADER "\n" #source |
| Quotes source into a C string constant, prefixed with VUOSHADER_GLSL_FRAGMENT_LIGHTING_HEADER .
|
|
|
void | VuoShader_free (void *shader) |
| Decrements the retain count of the OpenGL Texture Object associated with the specified VuoImage , and frees the texture VuoImage struct.
|
|
void | VuoShader_printProgramInfoLog (CGLContextObj cgl_ctx, GLuint obj) |
| Prints GLSL debug information to the console.
|
|
VuoShader | VuoShader_make (const char *summary, const char *vertexShaderSource, const char *fragmentShaderSource) |
| Compiles, links, and uploads the specified shader sources.
|
|
VuoShader | VuoShader_valueFromJson (json_object *js) |
| Decodes the JSON object js , expected to contain a 64-bit integer (memory address or 0), to create a new VuoShader .
|
|
json_object * | VuoShader_jsonFromValue (const VuoShader value) |
| Encodes value as a JSON object.
|
|
char * | VuoShader_summaryFromValue (const VuoShader value) |
| Returns a summary of the shader: the text description provided to VuoShader_make() , and the number of textures associated with the shader.
|
|
void | VuoShader_setUniformFloat (VuoShader shader, VuoGlContext glContext, const char *uniformIdentifier, float value) |
| Sets a float uniform value on the specified shader .
|
|
void | VuoShader_setUniformFloatArray (VuoShader shader, VuoGlContext glContext, const char *uniformIdentifier, const float *value, int length) |
| Sets a float [] uniform value on the specified shader .
|
|
void | VuoShader_setUniformPoint2d (VuoShader shader, VuoGlContext glContext, const char *uniformIdentifier, VuoPoint2d value) |
| Sets a vec2 uniform value on the specified shader .
|
|
void | VuoShader_setUniformPoint3d (VuoShader shader, VuoGlContext glContext, const char *uniformIdentifier, VuoPoint3d value) |
| Sets a vec3 uniform value on the specified shader .
|
|
void | VuoShader_setUniformPoint4d (VuoShader shader, VuoGlContext glContext, const char *uniformIdentifier, VuoPoint4d value) |
| Sets a vec4 uniform value on the specified shader .
|
|
const char * | VuoShader_getDefaultVertexShader (void) |
| Returns the default vertex shader, which projects verties and passes through texture coordinates.
|
|
VuoPoint2d | VuoShader_samplerCoordinatesFromVuoCoordinates (VuoPoint2d vuoCoordinates, VuoImage image) |
| Converts the provided vuoCoordinates into GLSL Sampler Coordinates relative to the provided image.
|
|
VuoReal | VuoShader_samplerSizeFromVuoSize (VuoReal vuoSize) |
| Converts an x-axis distance in Vuo Coordinates into GLSL Sampler Coordinates.
|
|
VuoShader | VuoShader_makeImageShader (void) |
| Returns a shader that renders objects with an image (ignoring lighting), specified by uniform texture .
|
|
void | VuoShader_resetTextures (VuoShader shader) |
| Empties the list of textures associated with shader .
|
|
void | VuoShader_addTexture (VuoShader shader, VuoGlContext glContext, const char *uniformIdentifier, VuoImage texture) |
| Adds to shader an association between texture and uniformIdentifier .
|
|
void | VuoShader_activateTextures (VuoShader shader, VuoGlContext glContext) |
| Assigns each of the shader's textures to a texture unit, and passes the texture unit number along to the shader.
|
|
void | VuoShader_deactivateTextures (VuoShader shader, VuoGlContext glContext) |
| Unbinds the texture units used by this shader.
|
|
VuoShader | VuoShader_makeColorShader (VuoColor color) |
| Returns a shader that renders a solid color .
|
|
VuoShader | VuoShader_makeLitColorShader (VuoColor diffuseColor, VuoColor highlightColor, VuoReal shininess) |
| Returns a shader that renders a color with lighting.
|
|
VuoShader | VuoShader_makeLitImageShader (VuoImage image, VuoReal alpha, VuoColor highlightColor, VuoReal shininess) |
| Returns a shader that renders an image with lighting.
|
|
VuoShader | VuoShader_makeLitImageDetailsShader (VuoImage image, VuoReal alpha, VuoImage specularImage, VuoImage normalImage) |
| Returns a shader that renders an image with lighting and surface details.
|
|
VuoShader | VuoShader_makeLinearGradientShader (VuoList_VuoColor colors, VuoPoint2d start, VuoPoint2d end) |
| Returns a shader that renders a linear gradient using the provided colors and start and end coordinates.
|
|
VuoShader | VuoShader_makeRadialGradientShader (VuoList_VuoColor colors, VuoPoint2d center, VuoReal radius, VuoReal width, VuoReal height) |
| Returns a shader that renders a radial gradient using the provided colors, center point, and radius.
|
|