Skip to content

Commit 86a80c6

Browse files
committed
minimal renderer, p5 and td dist
1 parent 0e4b81c commit 86a80c6

10 files changed

+50131
-11
lines changed

dist/shader-park-TouchDesigner.js

Lines changed: 45528 additions & 0 deletions
Large diffs are not rendered by default.

dist/shader-park-core.cjs.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Version: 0.1.38 - February 9, 2023 22:09:18 */
1+
/* Version: 0.1.39 - May 16, 2023 13:01:44 */
22
'use strict';
33

44
Object.defineProperty(exports, '__esModule', { value: true });
@@ -95961,7 +95961,7 @@ function sculptToRawSDF4Meshing(source) {
9596195961
*/
9596295962

9596395963
var TDHeader = "\nuniform float uShadowStrength;\nuniform vec3 uShadowColor;\nuniform vec4 uBaseColor;\nuniform float uMetallic;\nuniform float uRoughness;\nuniform float uSpecularLevel;\nuniform float uAmbientOcclusion;\nuniform vec3 cameraPosition;\nuniform sampler2D sBaseColorMap;\nuniform float useTDLighting;\n\n\nin Vertex\n{\n\tvec4 color;\n\tvec3 worldSpacePos;\n\tvec3 worldSpaceNorm;\n\tflat int cameraIndex;\n\tvec2 texCoord0;\n\tvec3 sculptureCenter;\n} iVert;\n\n#define sculptureCenter iVert.sculptureCenter;\n#define worldPos iVert.worldSpacePos\nlayout(location = 0) out vec4 oFragColor[TD_NUM_COLOR_BUFFERS];\nout float depthTexture;\n";
95964-
var TDFooter = "\nvoid main()\n{\n\t// This allows things such as order independent transparency\n\t// and Dual-Paraboloid rendering to work properly\n\tTDCheckDiscard();\n\n\t// Raymarching\n\tvec3 rayOrigin = worldPos.xyz-sculptureCenter;\n\tvec3 rayDirection = getRayDirection();\n\trayOrigin -= rayDirection*2.0;\n\tfloat t = intersect(rayOrigin, rayDirection, stepSize);\n depthTexture = t;\n\n\tvec4 outcol = vec4(0.0, 0.0, 0.0, 0.0);\n\tvec3 diffuseSum = vec3(0.0, 0.0, 0.0);\n\tvec3 specularSum = vec3(0.0, 0.0, 0.0);\n\n\tvec3 worldSpaceNorm = normalize(iVert.worldSpaceNorm.xyz);\n\tShadedMaterial col;\n vec3 outputColor = vec3(0.);\n\n\t// vec3 normal = normalize(worldSpaceNorm.xyz);\n\tif(t < 2.5) {\n\t\tvec3 p = (rayOrigin + rayDirection*t);\n\t\tvec3 normal = calcNormal(p);\n\t\t\n\t\tcol = shade(p, normal);\n outputColor = col.color;\n\n\n\t\tvec3 reflectionCoefficient = col.mat.reflectiveAlbedo;\n\t\t#ifdef MAX_REFLECTIONS\n\t\n\t\t#if MAX_REFLECTIONS > 0\n\t\tfor(int i = 0; i < MAX_REFLECTIONS; i++) {\n\t\t\tif(length(reflectionCoefficient) < .001) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\trayOrigin = (rayOrigin + rayDirection*t);\n\t\t\tvec3 normal = calcNormal(rayOrigin);\n\t\t\trayDirection = reflect(rayDirection, normal);\n\t\t\trayOrigin += .001 * rayDirection;\n\t\t\tt = intersect(rayOrigin, rayDirection, stepSize);\n\t\t\tvec3 p = (rayOrigin + rayDirection * t);\n\t\t\t\n\t\t\tShadedMaterial col;\n\t\n\t\t\tif(t < max_dist) {\n\t\t\t\tnormal = calcNormal(p);\n\t\t\t\tcol = shade(p, normal);\n\t\t\t} else {\n\t\t\t\t//outputColor = mix(outputColor, col.backgroundColor, reflectionCoefficient);\n\t\t\t\t// TODO col is undefined\n\t\t\t\t//outputColor += col.backgroundColor * reflectionCoefficient;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\t//outputColor = mix(outputColor, col.color, reflectionCoefficient);\n\t\t\t// outputColor += col.mat.albedo;\n\t\t\toutputColor += col.color * reflectionCoefficient;\n\t\t\t\n\t\t\treflectionCoefficient *= col.mat.reflectiveAlbedo ;\n\t\n\t\t\t\n\t\t}\n\t\t#endif\n\t\t#endif\n\t\t\n\t\toutputColor = outputColor / (outputColor + vec3(1.0));\n\t\toutputColor = pow(outputColor, vec3(1.0/2.2));\n\t\tvec3 raymarchedColor = outputColor;\n\t\n\t\tvec3 baseColor = uBaseColor.rgb;\n\n\t\t// 0.08 is the value for dielectric specular that\n\t\t// Substance Designer uses for it's top-end.\n\t\tfloat specularLevel = 0.08 * uSpecularLevel;\n\t\tfloat metallic = uMetallic;\n\n\t\tfloat roughness = uRoughness;\n\n\t\tfloat ambientOcclusion = uAmbientOcclusion;\n\n\t\tvec3 finalBaseColor = baseColor.rgb * iVert.color.rgb;\n\n\t\tvec2 texCoord0 = iVert.texCoord0.st;\n\t\tvec4 baseColorMap = texture(sBaseColorMap, texCoord0.st);\n\t\tfinalBaseColor *= baseColorMap.rgb;\n\n\n\t\t// A roughness of exactly 0 is not allowed\n\t\troughness = max(roughness, 0.0001);\n\n\t\tvec3 pbrDiffuseColor = finalBaseColor * (1.0 - metallic);\n\t\tvec3 pbrSpecularColor = mix(vec3(specularLevel), finalBaseColor, metallic);\n\n\t\tvec3 viewVec = normalize(uTDMats[iVert.cameraIndex].camInverse[3].xyz - iVert.worldSpacePos.xyz );\n\n\n\t\t// Your shader will be recompiled based on the number\n\t\t// of lights in your scene, so this continues to work\n\t\t// even if you change your lighting setup after the shader\n\t\t// has been exported from the Phong MAT\n\t\tfor (int i = 0; i < TD_NUM_LIGHTS; i++)\n\t\t{\n\t\t\tTDPBRResult res;\n\t\t\tres = TDLightingPBR(i,\n\t\t\t\t\t\t\t\tpbrDiffuseColor,\n\t\t\t\t\t\t\t\tpbrSpecularColor,\n\t\t\t\t\t\t\t\tiVert.worldSpacePos.xyz,\n\t\t\t\t\t\t\t\tnormal,\n\t\t\t\t\t\t\t\tuShadowStrength, uShadowColor,\n\t\t\t\t\t\t\t\tviewVec,\n\t\t\t\t\t\t\t\troughness);\n\t\t\tdiffuseSum += res.diffuse;\n\t\t\tspecularSum += res.specular;\n\t\t}\n\n\t\t// Environment lights\n\t\tfor (int i = 0; i < TD_NUM_ENV_LIGHTS; i++)\n\t\t{\n\t\t\tTDPBRResult res;\n\t\t\tres = TDEnvLightingPBR(i,\n\t\t\t\t\t\tpbrDiffuseColor,\n\t\t\t\t\t\tpbrSpecularColor,\n\t\t\t\t\t\tnormal,\n\t\t\t\t\t\tviewVec,\n\t\t\t\t\t\troughness,\n\t\t\t\t\t\tambientOcclusion);\n\t\t\tdiffuseSum += res.diffuse;\n\t\t\tspecularSum += res.specular;\n\t\t}\n\t\t// Final Diffuse Contribution\n\t\tvec3 finalDiffuse = diffuseSum;\n\t\toutcol.rgb += finalDiffuse;\n\n\t\t// Final Specular Contribution\n\t\tvec3 finalSpecular = vec3(0.0);\n\t\tfinalSpecular += specularSum;\n\n\t\toutcol.rgb += finalSpecular;\n\n\n\t\t// Apply fog, this does nothing if fog is disabled\n\t\toutcol = TDFog(outcol, iVert.worldSpacePos.xyz, iVert.cameraIndex);\n\n\t\t// Alpha Calculation\n\t\tfloat alpha = uBaseColor.a * iVert.color.a ;\n\n\t\t// Dithering, does nothing if dithering is disabled\n\t\toutcol = TDDither(outcol);\n\n\t\toutcol.rgb *= alpha;\n\n\t\t// Modern GL removed the implicit alpha test, so we need to apply\n\t\t// it manually here. This function does nothing if alpha test is disabled.\n\t\tTDAlphaTest(alpha);\n\n\t\toutcol.a = alpha;\n\t\toutcol = mix(vec4(raymarchedColor, 1.0), outcol, useTDLighting);\n\t\toFragColor[0] = TDOutputSwizzle(outcol);\n\n\n\t\t// TD_NUM_COLOR_BUFFERS will be set to the number of color buffers\n\t\t// active in the render. By default we want to output zero to every\n\t\t// buffer except the first one.\n\t\tfor (int i = 1; i < TD_NUM_COLOR_BUFFERS; i++)\n\t\t{\n\t\t\toFragColor[i] = vec4(0.0);\n\t\t}\n\t} else {\n\t\tdiscard;\n\t}\n}\n";
95964+
var TDFooter = "\nvoid main()\n{\n\t// This allows things such as order independent transparency\n\t// and Dual-Paraboloid rendering to work properly\n\tTDCheckDiscard();\n\n vec3 camPos = uTDMats[iVert.cameraIndex].camInverse[3].xyz;\n\n // Raymarching\n vec3 rayOrigin = iVert.worldSpacePos.xyz - sculptureCenter;\n vec3 rayDirection = normalize(iVert.worldSpacePos.xyz-camPos);\n\trayOrigin -= rayDirection*2.0;\n\tfloat t = intersect(rayOrigin, rayDirection, stepSize);\n depthTexture = t;\n\n\tvec4 outcol = vec4(0.0, 0.0, 0.0, 0.0);\n\tvec3 diffuseSum = vec3(0.0, 0.0, 0.0);\n\tvec3 specularSum = vec3(0.0, 0.0, 0.0);\n\n\tvec3 worldSpaceNorm = normalize(iVert.worldSpaceNorm.xyz);\n\tShadedMaterial col;\n vec3 outputColor = vec3(0.);\n\n\t// vec3 normal = normalize(worldSpaceNorm.xyz);\n\tif(t < 2.5) {\n\t\tvec3 p = (rayOrigin + rayDirection*t);\n\t\tvec3 normal = calcNormal(p);\n\t\t\n\t\tcol = shade(p, normal);\n outputColor = col.color;\n\n\n\t\tvec3 reflectionCoefficient = col.mat.reflectiveAlbedo;\n\t\t#ifdef MAX_REFLECTIONS\n\t\n\t\t#if MAX_REFLECTIONS > 0\n\t\tfor(int i = 0; i < MAX_REFLECTIONS; i++) {\n\t\t\tif(length(reflectionCoefficient) < .001) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\trayOrigin = (rayOrigin + rayDirection*t);\n\t\t\tvec3 normal = calcNormal(rayOrigin);\n\t\t\trayDirection = reflect(rayDirection, normal);\n\t\t\trayOrigin += .001 * rayDirection;\n\t\t\tt = intersect(rayOrigin, rayDirection, stepSize);\n\t\t\tvec3 p = (rayOrigin + rayDirection * t);\n\t\t\t\n\t\t\tShadedMaterial col;\n\t\n\t\t\tif(t < max_dist) {\n\t\t\t\tnormal = calcNormal(p);\n\t\t\t\tcol = shade(p, normal);\n\t\t\t} else {\n\t\t\t\t//outputColor = mix(outputColor, col.backgroundColor, reflectionCoefficient);\n\t\t\t\t// TODO col is undefined\n\t\t\t\t//outputColor += col.backgroundColor * reflectionCoefficient;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\t//outputColor = mix(outputColor, col.color, reflectionCoefficient);\n\t\t\t// outputColor += col.mat.albedo;\n\t\t\toutputColor += col.color * reflectionCoefficient;\n\t\t\t\n\t\t\treflectionCoefficient *= col.mat.reflectiveAlbedo ;\n\t\n\t\t\t\n\t\t}\n\t\t#endif\n\t\t#endif\n\t\t\n\t\toutputColor = outputColor / (outputColor + vec3(1.0));\n\t\toutputColor = pow(outputColor, vec3(1.0/2.2));\n\t\tvec3 raymarchedColor = outputColor;\n\t\n\t\tvec3 baseColor = uBaseColor.rgb;\n\n\t\t// 0.08 is the value for dielectric specular that\n\t\t// Substance Designer uses for it's top-end.\n\t\tfloat specularLevel = 0.08 * uSpecularLevel;\n\t\tfloat metallic = uMetallic;\n\n\t\tfloat roughness = uRoughness;\n\n\t\tfloat ambientOcclusion = uAmbientOcclusion;\n\n\t\tvec3 finalBaseColor = baseColor.rgb * iVert.color.rgb;\n\n\t\tvec2 texCoord0 = iVert.texCoord0.st;\n\t\tvec4 baseColorMap = texture(sBaseColorMap, texCoord0.st);\n\t\tfinalBaseColor *= baseColorMap.rgb;\n\n\n\t\t// A roughness of exactly 0 is not allowed\n\t\troughness = max(roughness, 0.0001);\n\n\t\tvec3 pbrDiffuseColor = finalBaseColor * (1.0 - metallic);\n\t\tvec3 pbrSpecularColor = mix(vec3(specularLevel), finalBaseColor, metallic);\n\n\t\tvec3 viewVec = normalize(uTDMats[iVert.cameraIndex].camInverse[3].xyz - iVert.worldSpacePos.xyz );\n\n\n\t\t// Your shader will be recompiled based on the number\n\t\t// of lights in your scene, so this continues to work\n\t\t// even if you change your lighting setup after the shader\n\t\t// has been exported from the Phong MAT\n\t\tfor (int i = 0; i < TD_NUM_LIGHTS; i++)\n\t\t{\n\t\t\tTDPBRResult res;\n\t\t\tres = TDLightingPBR(i,\n\t\t\t\t\t\t\t\tpbrDiffuseColor,\n\t\t\t\t\t\t\t\tpbrSpecularColor,\n\t\t\t\t\t\t\t\tiVert.worldSpacePos.xyz,\n\t\t\t\t\t\t\t\tnormal,\n\t\t\t\t\t\t\t\tuShadowStrength, uShadowColor,\n\t\t\t\t\t\t\t\tviewVec,\n\t\t\t\t\t\t\t\troughness);\n\t\t\tdiffuseSum += res.diffuse;\n\t\t\tspecularSum += res.specular;\n\t\t}\n\n\t\t// Environment lights\n\t\tfor (int i = 0; i < TD_NUM_ENV_LIGHTS; i++)\n\t\t{\n\t\t\tTDPBRResult res;\n\t\t\tres = TDEnvLightingPBR(i,\n\t\t\t\t\t\tpbrDiffuseColor,\n\t\t\t\t\t\tpbrSpecularColor,\n\t\t\t\t\t\tnormal,\n\t\t\t\t\t\tviewVec,\n\t\t\t\t\t\troughness,\n\t\t\t\t\t\tambientOcclusion);\n\t\t\tdiffuseSum += res.diffuse;\n\t\t\tspecularSum += res.specular;\n\t\t}\n\t\t// Final Diffuse Contribution\n\t\tvec3 finalDiffuse = diffuseSum;\n\t\toutcol.rgb += finalDiffuse;\n\n\t\t// Final Specular Contribution\n\t\tvec3 finalSpecular = vec3(0.0);\n\t\tfinalSpecular += specularSum;\n\n\t\toutcol.rgb += finalSpecular;\n\n\n\t\t// Apply fog, this does nothing if fog is disabled\n\t\toutcol = TDFog(outcol, iVert.worldSpacePos.xyz, iVert.cameraIndex);\n\n\t\t// Alpha Calculation\n\t\tfloat alpha = uBaseColor.a * iVert.color.a ;\n\n\t\t// Dithering, does nothing if dithering is disabled\n\t\toutcol = TDDither(outcol);\n\n\t\toutcol.rgb *= alpha;\n\n\t\t// Modern GL removed the implicit alpha test, so we need to apply\n\t\t// it manually here. This function does nothing if alpha test is disabled.\n\t\tTDAlphaTest(alpha);\n\n\t\toutcol.a = alpha;\n\t\toutcol = mix(vec4(raymarchedColor, 1.0), outcol, useTDLighting);\n\t\toFragColor[0] = TDOutputSwizzle(outcol);\n\n\n\t\t// TD_NUM_COLOR_BUFFERS will be set to the number of color buffers\n\t\t// active in the render. By default we want to output zero to every\n\t\t// buffer except the first one.\n\t\tfor (int i = 1; i < TD_NUM_COLOR_BUFFERS; i++)\n\t\t{\n\t\t\toFragColor[i] = vec4(0.0);\n\t\t}\n\t} else {\n\t\tdiscard;\n\t}\n}\n";
9596595965
function glslToTouchDesignerShaderSource(source) {
9596695966
return {
9596795967
uniforms: baseUniforms(),
@@ -95990,7 +95990,7 @@ function sculptToTouchDesignerShaderSource(source) {
9599095990
};
9599195991
}
9599295992

95993-
console.log('using shader-park-core version: 0.1.38'); /// Generate code for various targets
95993+
console.log('using shader-park-core version: 0.1.39'); /// Generate code for various targets
9599495994

9599595995
exports.baseUniforms = baseUniforms;
9599695996
exports.bindStaticData = bindStaticData;

0 commit comments

Comments
 (0)