├── .gitignore ├── plugins ├── cloth.spv ├── yTwistNode.spv ├── yTwistNode_ocl │ ├── yTwistNode.suo │ ├── README.md │ ├── yTwistNode.sln │ ├── yTwistNode.cpp │ └── yTwistNode.vcxproj ├── README.md ├── yTwistSharp │ └── compute.comp ├── yTwistNode.comp ├── clothDemo.py ├── cloth.comp ├── yTwistNode_ocl.py └── yTwistNode_ogl.py ├── shaders ├── bricks2.jpg ├── brickwall.jpg ├── bricks2_disp.jpg ├── bricks2_normal.jpg ├── brickwall_normal.jpg ├── README.md ├── frontBackFaceColor.shader ├── simple_wood.ogsfx ├── discard.shader ├── reflectionMap.fx ├── frontBackFaceColor.fx ├── lambert.ogsfx ├── lambert.fx ├── texture.fx ├── outline_geometryShader.shader ├── discard.fx ├── fresnel.fx ├── fresnel.ogsfx ├── transparent.fx ├── phong.fx ├── vertexAnimation.fx ├── toon.fx ├── outline_geometryShader.fx ├── normalMap.fx ├── normalMap.ogsfx ├── reflectionMap.sfx ├── lambert.sfx ├── parallaxMapping_01.ogsfx ├── parallaxMapping.ogsfx ├── texture.sfx ├── fresnel.sfx └── vertexAnimation.sfx ├── README.md ├── LICENSE ├── reverseNormalFaces.py ├── uvOverlap.py ├── intersectCmd.py └── cmdReporterHighlighter.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.pyo 3 | 4 | .mayaSwatches/ 5 | .vscode/ 6 | -------------------------------------------------------------------------------- /plugins/cloth.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mackst/myRandomStuff/HEAD/plugins/cloth.spv -------------------------------------------------------------------------------- /shaders/bricks2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mackst/myRandomStuff/HEAD/shaders/bricks2.jpg -------------------------------------------------------------------------------- /shaders/brickwall.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mackst/myRandomStuff/HEAD/shaders/brickwall.jpg -------------------------------------------------------------------------------- /plugins/yTwistNode.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mackst/myRandomStuff/HEAD/plugins/yTwistNode.spv -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Random Stuff 2 | ======================== 3 | random tools, random scripts, random shaders 4 | -------------------------------------------------------------------------------- /shaders/bricks2_disp.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mackst/myRandomStuff/HEAD/shaders/bricks2_disp.jpg -------------------------------------------------------------------------------- /shaders/bricks2_normal.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mackst/myRandomStuff/HEAD/shaders/bricks2_normal.jpg -------------------------------------------------------------------------------- /shaders/brickwall_normal.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mackst/myRandomStuff/HEAD/shaders/brickwall_normal.jpg -------------------------------------------------------------------------------- /plugins/yTwistNode_ocl/yTwistNode.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mackst/myRandomStuff/HEAD/plugins/yTwistNode_ocl/yTwistNode.suo -------------------------------------------------------------------------------- /shaders/README.md: -------------------------------------------------------------------------------- 1 | DX11 Shaders for Maya 2 | ======================== 3 | lambert.fx wrote in code. lambert.sfx was created using ShaderFX in Maya. 4 | 5 | Other shaders[.fx] were export from ShaderFX. 6 | 7 | .shader are unity version. -------------------------------------------------------------------------------- /plugins/yTwistNode_ocl/README.md: -------------------------------------------------------------------------------- 1 | yTwistNode_ocl 2 | ======================== 3 | The yTwistNode in the maya devkit samples implement with OpenCL. 4 | Implement with OpenCL C++ wrap. 5 | You need to download cl.hpp from https://www.khronos.org/opencl/. 6 | -------------------------------------------------------------------------------- /plugins/README.md: -------------------------------------------------------------------------------- 1 | Maya Plugins 2 | ======================== 3 | yTwistNode_ocl - The yTwistNode in the maya devkit samples implement with OpenCL 4 | 5 | yTwistNode_ocl.py - python version. http://schi.iteye.com/blog/1895279 6 | 7 | yTwistNode_ogl - The yTwistNode in the maya devkit samples implement with pyopengl and compute shader 8 | -------------------------------------------------------------------------------- /plugins/yTwistSharp/compute.comp: -------------------------------------------------------------------------------- 1 | #version 450 2 | #extension GL_ARB_separate_shader_objects : enable 3 | #extension GL_ARB_shading_language_420pack : enable 4 | 5 | 6 | layout(local_size_x = 256) in; 7 | layout(binding = 0) buffer InputBuffer{ vec4 inPos[]; }; 8 | layout(binding = 1) buffer OutputBuffer{ vec4 outPos[]; }; 9 | layout(binding = 2) uniform UBO{ 10 | float numVert; 11 | float angle; 12 | float envelope; 13 | } ubo; 14 | 15 | 16 | void main() 17 | { 18 | uint index = gl_GlobalInvocationID.x; 19 | if (index >= uint(ubo.numVert)) 20 | return; 21 | vec4 pos = inPos[index]; 22 | vec4 oPos = pos; 23 | float ff = ubo.angle * pos.y * ubo.envelope; 24 | if (ff != 0.0f) 25 | { 26 | float cct = cos(ff); 27 | float cst = sin(ff); 28 | oPos.x = pos.x * cct - pos.z * cst; 29 | oPos.z = pos.x * cst + pos.z * cct; 30 | } 31 | outPos[index] = oPos; 32 | } -------------------------------------------------------------------------------- /plugins/yTwistNode.comp: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #extension GL_ARB_separate_shader_objects : enable 4 | #extension GL_ARB_shading_language_420pack : enable 5 | 6 | layout(local_size_x = 256) in; 7 | 8 | layout(binding = 0) buffer InputBuffer{ vec4 inPos[]; }; 9 | layout(binding = 1) buffer OutputBuffer{ vec4 outPos[]; }; 10 | 11 | layout(binding = 2) uniform UBO{ 12 | int numVert; 13 | float angle; 14 | float envelope; 15 | } ubo; 16 | 17 | void main() 18 | { 19 | uint index = gl_GlobalInvocationID.x; 20 | if (index >= ubo.numVert) 21 | return; 22 | 23 | vec4 pos = inPos[index]; 24 | vec4 oPos = pos; 25 | float ff = ubo.angle * pos.y * ubo.envelope; 26 | if (ff != 0.0f) 27 | { 28 | float cct = cos(ff); 29 | float cst = sin(ff); 30 | oPos.x = pos.x * cct - pos.z * cst; 31 | oPos.z = pos.x * cst + pos.z * cct; 32 | } 33 | outPos[index] = oPos; 34 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Mack Stone 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /plugins/yTwistNode_ocl/yTwistNode.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 11.00 2 | # Visual C++ Express 2010 3 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "yTwistNode", "yTwistNode.vcxproj", "{81E3D1FA-C047-8180-F155-CBC13B1D45C7}" 4 | EndProject 5 | Global 6 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 7 | Debug|x64 = Debug|x64 8 | Release|x64 = Release|x64 9 | ReleaseDebug|x64 = ReleaseDebug|x64 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {81E3D1FA-C047-8180-F155-CBC13B1D45C7}.Debug|x64.ActiveCfg = Debug|x64 13 | {81E3D1FA-C047-8180-F155-CBC13B1D45C7}.Debug|x64.Build.0 = Debug|x64 14 | {81E3D1FA-C047-8180-F155-CBC13B1D45C7}.Release|x64.ActiveCfg = Release|x64 15 | {81E3D1FA-C047-8180-F155-CBC13B1D45C7}.Release|x64.Build.0 = Release|x64 16 | {81E3D1FA-C047-8180-F155-CBC13B1D45C7}.ReleaseDebug|x64.ActiveCfg = ReleaseDebug|x64 17 | {81E3D1FA-C047-8180-F155-CBC13B1D45C7}.ReleaseDebug|x64.Build.0 = ReleaseDebug|x64 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /shaders/frontBackFaceColor.shader: -------------------------------------------------------------------------------- 1 | Shader "Custom/frontBackFaceColor" { 2 | Properties { 3 | _frontColor ("Front Color", Color) = (1.0, 0., 0., 1.0) 4 | _backColor ("Back Color", Color) = (0.0, 0., 1., 1.0) 5 | } 6 | SubShader { 7 | Pass { 8 | // set culling mode 9 | Cull Off 10 | 11 | CGPROGRAM 12 | #pragma vertex vert 13 | #pragma fragment frag 14 | 15 | uniform float4 _frontColor; 16 | uniform float4 _backColor; 17 | 18 | // input from application 19 | struct APPDATA 20 | { 21 | float4 position : POSITION; 22 | }; 23 | 24 | // output to fragment shader 25 | struct SHADERDATA 26 | { 27 | float4 position : SV_POSITION; 28 | }; 29 | 30 | // vertex shader function 31 | SHADERDATA vert(APPDATA IN) 32 | { 33 | SHADERDATA OUT; 34 | OUT.position = mul(UNITY_MATRIX_MVP, IN.position); 35 | return OUT; 36 | } 37 | 38 | // fragment shader 39 | float4 frag(SHADERDATA IN, bool frontFace : SV_IsFrontFace) : COLOR 40 | { 41 | float4 outColor; 42 | 43 | if (frontFace) 44 | outColor = _frontColor; 45 | else 46 | outColor = _backColor; 47 | 48 | return outColor; 49 | } 50 | 51 | ENDCG 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /shaders/simple_wood.ogsfx: -------------------------------------------------------------------------------- 1 | #version 410 2 | 3 | // from shadertoy 4 | // https://www.shadertoy.com/view/lss3WN 5 | 6 | // transform object vertices to world-space: 7 | uniform mat4 wvp : WorldViewProjection < string UIWidget="None"; >; 8 | 9 | uniform float destiny = 40.0; 10 | 11 | uniform float trunk_x = 10.0; 12 | 13 | uniform float trunk_y = 10.0; 14 | 15 | uniform vec3 color_1 : Diffuse 16 | < 17 | string UIWidget = "Color"; 18 | > = {0.88, 0.72, 0.5}; 19 | 20 | uniform vec3 color_2 : ambient = {0.76, 0.54, 0.26}; 21 | 22 | // data from maya 23 | attribute appIn 24 | { 25 | vec3 inPos : POSITION; 26 | vec2 inUV : TEXCOORD0; 27 | } 28 | 29 | // output from vertex shader 30 | // input to fragment shader 31 | attribute vsOut 32 | { 33 | vec2 uv : TEXCOORD0; 34 | } 35 | 36 | // output from fragment shader 37 | attribute pixelOut 38 | { 39 | vec4 outColor : COLOR0; 40 | } 41 | 42 | 43 | GLSLShader VS 44 | { 45 | void main() 46 | { 47 | uv = inUV; 48 | gl_Position = wvp * vec4(inPos, 1.0); 49 | } 50 | } 51 | 52 | 53 | GLSLShader FS 54 | { 55 | void main() 56 | { 57 | // destiny 58 | vec2 pos = uv.xy * destiny; 59 | 60 | // Center of trunk 61 | pos += vec2(trunk_x, trunk_y); 62 | 63 | float x = sqrt(pos.x * pos.x + pos.y * pos.y); 64 | x = fract(x); 65 | 66 | vec3 cl = mix(color_1, color_2, x); 67 | outColor = vec4(cl, 1.0); 68 | } 69 | } 70 | 71 | 72 | // Techniques. 73 | technique Main 74 | { 75 | pass p0 76 | { 77 | VertexShader (in appIn, out vsOut) = VS; 78 | PixelShader (in vsOut, out pixelOut) = FS; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /shaders/discard.shader: -------------------------------------------------------------------------------- 1 | Shader "Custom/discardShader" { 2 | Properties { 3 | _frontColor ("Front Color", Color) = (1.0, 0., 0., 1.0) 4 | _backColor ("Back Color", Color) = (0.0, 0., 1., 1.0) 5 | _discardU ("Discard U", Range(0.0, 1.0)) = .5 6 | _discardV ("Discard V", Range(0.0, 1.0)) = .5 7 | } 8 | SubShader { 9 | Pass { 10 | // set culling mode 11 | Cull Off 12 | 13 | CGPROGRAM 14 | #pragma vertex vert 15 | #pragma fragment frag 16 | 17 | uniform float4 _frontColor; 18 | uniform float4 _backColor; 19 | uniform float _discardU; 20 | uniform float _discardV; 21 | 22 | // input from application 23 | struct APPDATA 24 | { 25 | float4 position : POSITION; 26 | float2 uv : TEXCOORD0; 27 | }; 28 | 29 | // output to fragment shader 30 | struct SHADERDATA 31 | { 32 | float4 position : SV_POSITION; 33 | float2 uv : TEXCOORD0; 34 | }; 35 | 36 | // vertex shader function 37 | SHADERDATA vert(APPDATA IN) 38 | { 39 | SHADERDATA OUT; 40 | OUT.uv = IN.uv; 41 | OUT.position = mul(UNITY_MATRIX_MVP, IN.position); 42 | return OUT; 43 | } 44 | 45 | // fragment shader 46 | float4 frag(SHADERDATA IN, bool frontFace : SV_IsFrontFace) : COLOR 47 | { 48 | float4 outColor; 49 | 50 | if (all(IN.uv < float2(_discardU, _discardV))) 51 | discard; 52 | else 53 | { 54 | if (frontFace) 55 | outColor = _frontColor; 56 | else 57 | outColor = _backColor; 58 | } 59 | 60 | return outColor; 61 | } 62 | 63 | ENDCG 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /reverseNormalFaces.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # The MIT License (MIT) 4 | # 5 | # Copyright (c) 2014 Mack Stone 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | # this software and associated documentation files (the "Software"), to deal in 9 | # the Software without restriction, including without limitation the rights to 10 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | # the Software, and to permit persons to whom the Software is furnished to do so, 12 | # subject to the following conditions: 13 | # 14 | # The above copyright notice and this permission notice shall be included in all 15 | # copies or substantial portions of the Software. 16 | # 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | # How to use it 25 | # 26 | # faces = getReversNormalFaces("pSphereShape1") 27 | # cmds.select(faces, r=1) 28 | 29 | import maya.api.OpenMaya as om 30 | 31 | def getReverseNormalFaces(meshName): 32 | '''get reverse normal faces from given ploygon mesh base on uv projection. 33 | If the uv projection was not correct you may get uncorrect result''' 34 | revFaces = [] 35 | selList = om.MSelectionList() 36 | selList.add(meshName) 37 | mesh = om.MFnMesh(selList.getDependNode(0)) 38 | 39 | for fid in range(mesh.numPolygons): 40 | count = 0 41 | numVert = len(mesh.getPolygonVertices(fid)) 42 | for i in range(numVert): 43 | j = (i + 1) % numVert 44 | k = (i + 2) % numVert 45 | uv1 = mesh.getPolygonUV(fid, i) 46 | uv2 = mesh.getPolygonUV(fid, j) 47 | uv3 = mesh.getPolygonUV(fid, k) 48 | v1 = om.MPoint(uv2[0], uv2[1]) - om.MPoint(uv1[0], uv1[1]) 49 | v2 = om.MPoint(uv3[0], uv3[1]) - om.MPoint(uv1[0], uv1[1]) 50 | w = v1 ^ v2 51 | if w.z > 0: 52 | count += 1 53 | elif w.z < 0: 54 | count -= 1 55 | 56 | if count < 0: 57 | revFaces.append('%s.f[%i]' % (meshName, fid)) 58 | 59 | return revFaces -------------------------------------------------------------------------------- /shaders/reflectionMap.fx: -------------------------------------------------------------------------------- 1 | // ----------------------------------- Per Frame -------------------------------------- 2 | cbuffer UpdatePerFrame : register(b0) 3 | { 4 | float4x4 viewI : ViewInverse < string UIWidget = "None"; >; 5 | 6 | }; 7 | 8 | // --------------------------------------- Per Object ----------------------------------------- 9 | cbuffer UpdatePerObject : register(b1) 10 | { 11 | float4x4 world : World < string UIWidget = "None"; >; 12 | 13 | float4x4 worldIT : WorldInverseTranspose < string UIWidget = "None"; >; 14 | 15 | float4x4 wvp : WorldViewProjection < string UIWidget = "None"; >; 16 | 17 | }; 18 | 19 | // ---------------------------------------- Textures ----------------------------------------- 20 | TextureCube reflectionTex 21 | < 22 | string ResourceName = ""; 23 | string UIName = "reflection Texeture"; 24 | string ResourceType = "Cube"; 25 | string UIWidget = "FilePicker"; 26 | >; 27 | 28 | SamplerState MMMLWWWSampler 29 | { 30 | Filter = MIN_MAG_MIP_LINEAR; 31 | AddressU = WRAP; 32 | AddressV = WRAP; 33 | AddressW = WRAP; 34 | }; 35 | 36 | 37 | // -------------------------------------- APP and DATA -------------------------------------- 38 | struct APPDATA 39 | { 40 | float3 Position : POSITION; 41 | float3 Normal : NORMAL; 42 | }; 43 | 44 | struct SHADERDATA 45 | { 46 | float3 eyeVector : TEXCOORD0; 47 | float3 normal : NORMAL; 48 | float4 position : SV_Position; 49 | }; 50 | 51 | // -------------------------------------- ShaderVertex -------------------------------------- 52 | SHADERDATA ShaderVertex(APPDATA IN) 53 | { 54 | SHADERDATA OUT; 55 | 56 | float3 CameraPosition = viewI[3].xyz; 57 | float3 worldPosition = mul(IN.Position, world); 58 | OUT.eyeVector = CameraPosition - worldPosition; 59 | OUT.normal = mul(IN.Normal, worldIT); 60 | OUT.position = mul(float4(IN.Position, 1), wvp); 61 | 62 | return OUT; 63 | } 64 | 65 | // -------------------------------------- ShaderPixel -------------------------------------- 66 | struct PIXELDATA 67 | { 68 | float4 Color : SV_Target; 69 | }; 70 | 71 | PIXELDATA ShaderPixel(SHADERDATA IN) 72 | { 73 | PIXELDATA OUT; 74 | 75 | float3 reflectVector = reflect(IN.eyeVector, IN.normal); 76 | OUT.Color = reflectionTex.Sample(MMMLWWWSampler, reflectVector); 77 | 78 | return OUT; 79 | } 80 | 81 | // -------------------------------------- technique sample --------------------------------------- 82 | technique11 sample 83 | { 84 | pass P0 85 | < 86 | string drawContext = "colorPass"; 87 | > 88 | { 89 | SetVertexShader(CompileShader(vs_5_0, ShaderVertex())); 90 | SetPixelShader(CompileShader(ps_5_0, ShaderPixel())); 91 | SetHullShader(NULL); 92 | SetDomainShader(NULL); 93 | SetGeometryShader(NULL); 94 | } 95 | 96 | } 97 | 98 | -------------------------------------------------------------------------------- /plugins/clothDemo.py: -------------------------------------------------------------------------------- 1 | import math 2 | from maya import cmds 3 | 4 | 5 | def clothDemo(): 6 | clothNode = cmds.createNode('ClothNode') 7 | sphere, polySphere = cmds.polySphere() 8 | # plane, polyPlane = cmds.polyPlane(h=20., w=20., sh=20, sw=20, ax=(1., 0., 0.)) 9 | plane, polyPlane = cmds.polyPlane(h=20., w=20., sh=100, sw=100, ax=(1., 0., 0.)) 10 | planeShape = cmds.listRelatives(plane, c=1, s=1)[0] 11 | 12 | cmds.setAttr("{}.tx".format(sphere), 4) 13 | cmds.setAttr("{}.radius".format(polySphere), 5.5) 14 | # cmds.setAttr("{}.pinnedIdX".format(clothNode), 420) 15 | # cmds.setAttr("{}.pinnedIdY".format(clothNode), 440) 16 | # cmds.setAttr("{}.particleCountX".format(clothNode), 21) 17 | # cmds.setAttr("{}.particleCountY".format(clothNode), 21) 18 | 19 | cmds.setAttr("{}.pinnedIdX".format(clothNode), 10100) 20 | cmds.setAttr("{}.pinnedIdY".format(clothNode), 10200) 21 | cmds.setAttr("{}.particleCountX".format(clothNode), 101) 22 | cmds.setAttr("{}.particleCountY".format(clothNode), 101) 23 | 24 | cmds.setAttr("{}.visibility".format(plane), 0) 25 | 26 | multNode = cmds.createNode('multiplyDivide') 27 | cmds.setAttr("{}.operation".format(multNode), 2) 28 | plusNode = cmds.createNode('plusMinusAverage') 29 | cmds.setAttr("{}.operation".format(plusNode), 2) 30 | cmds.setAttr("{}.operation".format(plusNode), 2) 31 | cmds.connectAttr('{}.particleCountX'.format(clothNode), '{}.input2D[0].input2Dy'.format(plusNode), f=1) 32 | cmds.connectAttr('{}.particleCountY'.format(clothNode), '{}.input2D[0].input2Dx'.format(plusNode), f=1) 33 | cmds.setAttr("{}.input2D[1].input2Dx".format(plusNode), 1) 34 | cmds.setAttr("{}.input2D[1].input2Dy".format(plusNode), 1) 35 | cmds.connectAttr('{}.width'.format(polyPlane), '{}.input1X'.format(multNode), f=1) 36 | cmds.connectAttr('{}.height'.format(polyPlane), '{}.input1Y'.format(multNode), f=1) 37 | cmds.connectAttr('{}.translate'.format(sphere), '{}.spherePosition'.format(clothNode), f=1) 38 | cmds.connectAttr('{}.radius'.format(polySphere), '{}.sphereRadius'.format(clothNode), f=1) 39 | cmds.connectAttr('{}.output2Dx'.format(plusNode), '{}.input2X'.format(multNode), f=1) 40 | cmds.connectAttr('{}.output2Dy'.format(plusNode), '{}.input2Y'.format(multNode), f=1) 41 | cmds.connectAttr('{}.outputX'.format(multNode), '{}.restDistH'.format(clothNode), f=1) 42 | cmds.connectAttr('{}.outputY'.format(multNode), '{}.restDistV'.format(clothNode), f=1) 43 | 44 | restDistH = cmds.getAttr('{}.restDistH'.format(clothNode)) 45 | restDistV = cmds.getAttr('{}.restDistV'.format(clothNode)) 46 | restDistD = math.sqrt(restDistH * restDistH + restDistV + restDistV) 47 | cmds.setAttr('{}.restDistD'.format(clothNode), restDistD) 48 | 49 | clothMesh = cmds.createNode('mesh') 50 | cmds.connectAttr('{}.outMesh'.format(clothNode), '{}.inMesh'.format(clothMesh)) 51 | 52 | # cmds.connectAttr('{}.worldMesh[0]'.format(polyPlane), '{}.inMesh'.format(clothNode), f=1) 53 | cmds.connectAttr('{}.outMesh'.format(planeShape), '{}.inMesh'.format(clothNode), f=1) 54 | 55 | 56 | clothDemo() 57 | -------------------------------------------------------------------------------- /shaders/frontBackFaceColor.fx: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2014 Mack Stone 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | 25 | 26 | float4x4 world : World < string UIWidget = "None"; >; 27 | float4x4 wvp : WorldViewProjection < string UIWidget = "None"; >; 28 | float4x4 worldInverseTranspose : WorldInverseTranspose < string UIWidget = "None"; >; 29 | 30 | // parameters section 31 | float3 frontColor : Diffuse 32 | < 33 | string UIName = "Front Color"; 34 | > = {1.0f, 0.0f, 0.0f}; 35 | 36 | float3 backColor : Diffuse 37 | < 38 | string UIName = "Back Color"; 39 | > = {0.f, 0.f, 1.f}; 40 | 41 | 42 | 43 | 44 | //------------------------------------ 45 | // Structs 46 | //------------------------------------ 47 | // input from application 48 | struct APPDATA 49 | { 50 | float4 position : POSITION; 51 | }; 52 | 53 | // output to pixel shader 54 | struct SHADERDATA 55 | { 56 | float4 position : SV_Position; 57 | }; 58 | 59 | 60 | //------------------------------------ 61 | // vertex shader 62 | //------------------------------------ 63 | SHADERDATA vShader(APPDATA IN) 64 | { 65 | SHADERDATA OUT; 66 | OUT.position = mul(IN.position, wvp); 67 | return OUT; 68 | } 69 | 70 | 71 | //------------------------------------ 72 | // pixel shader 73 | //------------------------------------ 74 | float4 pShader(SHADERDATA IN, bool frontFace : SV_IsFrontFace) : COLOR 75 | { 76 | float4 outColor; 77 | 78 | if (frontFace) 79 | outColor.rgb = frontColor; 80 | else 81 | outColor.rgb = backColor; 82 | 83 | outColor.a = 1.0; 84 | 85 | return outColor; 86 | } 87 | 88 | technique11 Simple 89 | { 90 | pass one 91 | < 92 | string drawContext = "colorPass"; 93 | > 94 | { 95 | SetVertexShader(CompileShader(vs_5_0, vShader())); 96 | SetHullShader(NULL); 97 | SetDomainShader(NULL); 98 | SetGeometryShader(NULL); 99 | SetPixelShader(CompileShader(ps_5_0, pShader())); 100 | } 101 | } -------------------------------------------------------------------------------- /shaders/lambert.ogsfx: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2015 Mack Stone 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | 25 | uniform mat4 wvp : WorldViewProjection < string UIWidget="None"; >; 26 | uniform mat4 wit : WorldInverseTranspose < string UIWidget="None"; >; 27 | 28 | // parameters section 29 | uniform vec3 diffuse_color : Diffuse 30 | < 31 | string UIName = "Diffuse"; 32 | > = {1.0, 1.0, 1.0}; 33 | 34 | uniform vec3 ambient_color : Diffuse 35 | < 36 | string UIName = "Ambient"; 37 | > = {0.1, 0.1, 0.1}; 38 | 39 | // // light direction 40 | uniform vec3 Light0Dir : DIRECTION 41 | < 42 | string UIName = "Light 0 Direction"; 43 | string Space = "World"; 44 | string Object = "Light 0"; 45 | > = {0.0, -1.0, 0.0}; 46 | 47 | 48 | //------------------------------------ 49 | // Attributes 50 | //------------------------------------ 51 | // input from application 52 | attribute appIn 53 | { 54 | vec3 inPosition : POSITION; 55 | vec3 inNormal : NORMAL; 56 | } 57 | 58 | // ouput from vertex shader 59 | // input to pixel shader 60 | attribute vsOut 61 | { 62 | vec3 worldNormal : NORMAL; 63 | } 64 | 65 | // output to pixel shader 66 | attribute pixelOut 67 | { 68 | vec4 outColor : COLOR0; 69 | } 70 | 71 | 72 | //------------------------------------ 73 | // vertex shader 74 | //------------------------------------ 75 | GLSLShader VS 76 | { 77 | void main() 78 | { 79 | worldNormal = mat3(wit) * inNormal; 80 | gl_Position = wvp * vec4(inPosition, 1.0); 81 | } 82 | } 83 | 84 | 85 | //------------------------------------ 86 | // pixel shader 87 | //------------------------------------ 88 | GLSLShader FS 89 | { 90 | void main() 91 | { 92 | vec3 wNormal = normalize(worldNormal); 93 | vec3 lightDir = normalize(-Light0Dir); 94 | 95 | float lambert = clamp(dot(lightDir, wNormal), 0.0, 1.0); 96 | 97 | vec3 color = diffuse_color * (ambient_color + lambert); 98 | outColor = vec4(color, 1.0); 99 | // outColor = vec4(1.0, 0.0, 0.0, 1.0); 100 | } 101 | } 102 | 103 | technique Simple 104 | { 105 | pass p0 106 | { 107 | VertexShader (in appIn, out vsOut) = VS; 108 | PixelShader (in vsOut, out pixelOut) = FS; 109 | } 110 | } -------------------------------------------------------------------------------- /shaders/lambert.fx: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2014 Mack Stone 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | 25 | 26 | float4x4 world : World < string UIWidget = "None"; >; 27 | float4x4 wvp : WorldViewProjection < string UIWidget = "None"; >; 28 | float4x4 worldInverseTranspose : WorldInverseTranspose < string UIWidget = "None"; >; 29 | 30 | // parameters section 31 | float3 diffuseColor : Diffuse 32 | < 33 | string UIName = "Diffuse Color"; 34 | > = {1.0f, 1.0f, 1.0f}; 35 | 36 | float3 ambientColor : Diffuse 37 | < 38 | string UIName = "Ambient Color"; 39 | > = {0.1f, 0.1f, 0.1f}; 40 | 41 | // light direction 42 | float3 lightDirection : Direction 43 | < 44 | string UIName = "Light Direction"; 45 | string Space = "World"; // using world space 46 | > = {0.0f, 1.0f, 0.0f}; 47 | 48 | 49 | 50 | //------------------------------------ 51 | // Structs 52 | //------------------------------------ 53 | // input from application 54 | struct APPDATA 55 | { 56 | float4 position : POSITION; 57 | float3 normal : NORMAL; 58 | }; 59 | 60 | // output to pixel shader 61 | struct SHADERDATA 62 | { 63 | float4 position : SV_Position; 64 | float3 worldNormal : TEXCOORD0; 65 | }; 66 | 67 | 68 | //------------------------------------ 69 | // vertex shader 70 | //------------------------------------ 71 | SHADERDATA vShader(APPDATA IN) 72 | { 73 | SHADERDATA OUT; 74 | OUT.position = mul(IN.position, wvp); 75 | OUT.worldNormal = mul(IN.normal, worldInverseTranspose); 76 | 77 | return OUT; 78 | } 79 | 80 | 81 | //------------------------------------ 82 | // pixel shader 83 | //------------------------------------ 84 | float4 pShader(SHADERDATA IN) : COLOR 85 | { 86 | float4 outColor; 87 | 88 | float3 worldNormal = normalize(IN.worldNormal); 89 | float3 lightDir = normalize(-lightDirection); 90 | 91 | float lambert = saturate(dot(lightDir, worldNormal)); 92 | 93 | outColor.rgb = diffuseColor * (ambientColor + lambert); 94 | outColor.a = 1.0f; 95 | 96 | return outColor; 97 | } 98 | 99 | technique11 Simple 100 | { 101 | pass one 102 | { 103 | SetVertexShader(CompileShader(vs_5_0, vShader())); 104 | SetHullShader(NULL); 105 | SetDomainShader(NULL); 106 | SetGeometryShader(NULL); 107 | SetPixelShader(CompileShader(ps_5_0, pShader())); 108 | } 109 | } -------------------------------------------------------------------------------- /shaders/texture.fx: -------------------------------------------------------------------------------- 1 | // --------------------------------------- Per Object ----------------------------------------- 2 | cbuffer UpdatePerObject : register(b1) 3 | { 4 | float4x4 worldIT : WorldInverseTranspose < string UIWidget = "None"; >; 5 | 6 | float4x4 wvp : WorldViewProjection < string UIWidget = "None"; >; 7 | 8 | }; 9 | 10 | // --------------------------------------- Attributes ----------------------------------------- 11 | cbuffer UpdateAttributes : register(b2) 12 | { 13 | float3 ambientColor 14 | < 15 | string UIName = "ambientColor"; 16 | string UIWidget = "ColorPicker"; 17 | > = {0.317464,0.317464,0.317464}; 18 | 19 | float3 diffuseColor 20 | < 21 | string UIName = "diffuseColor"; 22 | string UIWidget = "ColorPicker"; 23 | > = {1.0,1.0,1.0}; 24 | 25 | }; 26 | 27 | // ----------------------------------- Lights -------------------------------------- 28 | cbuffer UpdateLights : register(b3) 29 | { 30 | float3 Light1Dir : DIRECTION 31 | < 32 | string UIName = "Light 1 Direction"; 33 | string Space = "World"; 34 | string Object = "Light 1"; 35 | > = {0.0, -1.0, 0.0}; 36 | 37 | }; 38 | 39 | // ---------------------------------------- Textures ----------------------------------------- 40 | Texture2D diffuseTexture 41 | < 42 | string ResourceName = ""; 43 | string UIName = "diffuseTexture"; 44 | string ResourceType = "2D"; 45 | string UIWidget = "FilePicker"; 46 | >; 47 | 48 | SamplerState SamplerDiffuse 49 | { 50 | Filter = MIN_MAG_MIP_LINEAR; 51 | AddressU = WRAP; 52 | AddressV = WRAP; 53 | AddressW = WRAP; 54 | }; 55 | 56 | 57 | // -------------------------------------- APP and DATA -------------------------------------- 58 | struct APPDATA 59 | { 60 | float3 Position : POSITION; 61 | float3 Normal : NORMAL; 62 | float2 map1 : TEXCOORD0; 63 | }; 64 | 65 | struct SHADERDATA 66 | { 67 | float3 worldNormal : TEXCOORD0; 68 | float2 uv : TEXCOORD1; 69 | float4 position : SV_Position; 70 | }; 71 | 72 | // -------------------------------------- ShaderVertex -------------------------------------- 73 | SHADERDATA ShaderVertex(APPDATA IN) 74 | { 75 | SHADERDATA OUT; 76 | 77 | float3 normal = mul(IN.Normal, worldIT); 78 | OUT.worldNormal = normal; 79 | OUT.uv = IN.map1; 80 | float4 position = mul(float4(IN.Position, 1), wvp); 81 | OUT.position = position; 82 | 83 | return OUT; 84 | } 85 | 86 | // -------------------------------------- ShaderPixel -------------------------------------- 87 | struct PIXELDATA 88 | { 89 | float4 Color : SV_Target; 90 | }; 91 | 92 | PIXELDATA ShaderPixel(SHADERDATA IN) 93 | { 94 | PIXELDATA OUT; 95 | 96 | float3 lightDir = normalize(-(Light1Dir)); 97 | float lambert = saturate(dot(lightDir, normalize(IN.worldNormal))); 98 | float4 diffuseMap = diffuseTexture.Sample(SamplerDiffuse, float2(IN.uv.x, 1-IN.uv.y)); 99 | float3 color = ((lambert + ambientColor.xyz) * (diffuseColor.xyz * diffuseMap.xyz)); 100 | OUT.Color = float4(color.x, color.y, color.z, 1.0); 101 | 102 | return OUT; 103 | } 104 | 105 | // -------------------------------------- technique sample --------------------------------------- 106 | technique11 sample 107 | { 108 | pass P0 109 | < 110 | string drawContext = "colorPass"; 111 | > 112 | { 113 | SetVertexShader(CompileShader(vs_5_0, ShaderVertex())); 114 | SetPixelShader(CompileShader(ps_5_0, ShaderPixel())); 115 | SetHullShader(NULL); 116 | SetDomainShader(NULL); 117 | SetGeometryShader(NULL); 118 | } 119 | 120 | } 121 | 122 | -------------------------------------------------------------------------------- /shaders/outline_geometryShader.shader: -------------------------------------------------------------------------------- 1 | Shader "Custom/outline_geometryShader" { 2 | Properties 3 | { 4 | _color ("Color", Color) = (.5, .5, .5, 1.0) 5 | } 6 | SubShader 7 | { 8 | Pass 9 | { 10 | CGPROGRAM 11 | #pragma vertex vert 12 | #pragma fragment frag 13 | #pragma geometry geom 14 | 15 | uniform float4 _color; 16 | 17 | // input from application 18 | struct APPDATA 19 | { 20 | float4 position : POSITION; 21 | }; 22 | 23 | // output to fragment shader 24 | struct SHADERDATA 25 | { 26 | float4 position : SV_POSITION; 27 | }; 28 | 29 | // vertex shader function 30 | SHADERDATA vert(APPDATA IN) 31 | { 32 | SHADERDATA OUT; 33 | OUT.position = mul(UNITY_MATRIX_MV, IN.position); 34 | return OUT; 35 | } 36 | 37 | // geometry shader 38 | [maxvertexcount(32)] 39 | void geom(triangleadj SHADERDATA IN[6], inout LineStream lineStream) 40 | { 41 | SHADERDATA OUT; 42 | 43 | float3 V0 = IN[0].position.xyz; 44 | float3 V1 = IN[1].position.xyz; 45 | float3 V2 = IN[2].position.xyz; 46 | float3 V3 = IN[3].position.xyz; 47 | float3 V4 = IN[4].position.xyz; 48 | float3 V5 = IN[5].position.xyz; 49 | 50 | float3 N042 = cross(V4 - V0, V2 - V0); 51 | float3 N021 = cross(V2 - V0, V1 - V0); 52 | float3 N243 = cross(V4 - V2, V3 - V2); 53 | float3 N405 = cross(V0 - V4, V5 - V4); 54 | 55 | // rashly assume all 4 normals are really meant to be 56 | // within 90 degrees of each other 57 | if (dot(N042, N021) < 0.) 58 | N021 = -N021; 59 | 60 | if (dot(N042, N243) < 0.) 61 | N243 = -N243; 62 | 63 | if (dot(N042, N405) < 0.) 64 | N405 = -N405; 65 | 66 | // look for a silhouette edge between triangles 042 and 021 67 | if (N042.z * N021.z < 0.) 68 | { 69 | OUT.position = mul(float4(V0, 1.0), UNITY_MATRIX_P); 70 | lineStream.Append(OUT); 71 | 72 | OUT.position = mul(float4(V2, 1.0), UNITY_MATRIX_P); 73 | lineStream.Append(OUT); 74 | 75 | lineStream.RestartStrip(); 76 | } 77 | 78 | // look for a silhouette edge between triangles 042 and 243 79 | if (N042.z * N243.z < 0.) 80 | { 81 | OUT.position = mul(float4(V2, 1.0), UNITY_MATRIX_P); 82 | lineStream.Append(OUT); 83 | 84 | OUT.position = mul(float4(V4, 1.0), UNITY_MATRIX_P); 85 | lineStream.Append(OUT); 86 | 87 | lineStream.RestartStrip(); 88 | } 89 | 90 | // look for a silhouette edge between triangles 042 and 405 91 | if (N042.z * N405.z < 0.) 92 | { 93 | OUT.position = mul(float4(V4, 1.0), UNITY_MATRIX_P); 94 | lineStream.Append(OUT); 95 | 96 | OUT.position = mul(float4(V0, 1.0), UNITY_MATRIX_P); 97 | lineStream.Append(OUT); 98 | 99 | lineStream.RestartStrip(); 100 | } 101 | } 102 | 103 | // fragment shader 104 | float4 frag(SHADERDATA IN) : COLOR 105 | { 106 | return _color; 107 | } 108 | 109 | ENDCG 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /shaders/discard.fx: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2014 Mack Stone 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | 25 | 26 | float4x4 world : World < string UIWidget = "None"; >; 27 | float4x4 wvp : WorldViewProjection < string UIWidget = "None"; >; 28 | float4x4 worldInverseTranspose : WorldInverseTranspose < string UIWidget = "None"; >; 29 | 30 | // parameters section 31 | float3 frontColor : Diffuse 32 | < 33 | string UIName = "Front Color"; 34 | > = {1.0f, 0.0f, 0.0f}; 35 | 36 | float3 backColor : Diffuse 37 | < 38 | string UIName = "Back Color"; 39 | > = {0.f, 0.f, 1.f}; 40 | 41 | float discardU 42 | < 43 | string UIWidget = "Slider"; 44 | float UIMin = 0.0; 45 | float UIMax = 1.0; 46 | float UIStep = 0.001; 47 | string UIName = "Discard U"; 48 | > = .2f; 49 | 50 | float discardV 51 | < 52 | string UIWidget = "Slider"; 53 | float UIMin = 0.0; 54 | float UIMax = 1.0; 55 | float UIStep = 0.001; 56 | string UIName = "Discard V"; 57 | > = .2f; 58 | 59 | 60 | //------------------------------------ 61 | // Structs 62 | //------------------------------------ 63 | // input from application 64 | struct APPDATA 65 | { 66 | float4 position : POSITION; 67 | float2 uv : TEXCOORD0; 68 | }; 69 | 70 | // output to pixel shader 71 | struct SHADERDATA 72 | { 73 | float4 position : SV_Position; 74 | float2 uv : TEXCOORD0; 75 | }; 76 | 77 | 78 | //------------------------------------ 79 | // vertex shader 80 | //------------------------------------ 81 | SHADERDATA vShader(APPDATA IN) 82 | { 83 | SHADERDATA OUT; 84 | OUT.uv = IN.uv; 85 | OUT.position = mul(IN.position, wvp); 86 | return OUT; 87 | } 88 | 89 | 90 | //------------------------------------ 91 | // pixel shader 92 | //------------------------------------ 93 | float4 pShader(SHADERDATA IN, bool frontFace : SV_IsFrontFace) : COLOR 94 | { 95 | float4 outColor; 96 | 97 | if (all(IN.uv < float2(discardU, discardV))) 98 | discard; 99 | else 100 | { 101 | if (frontFace) 102 | outColor.rgb = frontColor; 103 | else 104 | outColor.rgb = backColor; 105 | outColor.a = 1.0; 106 | } 107 | 108 | return outColor; 109 | } 110 | 111 | technique11 Simple 112 | { 113 | pass one 114 | < 115 | string drawContext = "colorPass"; 116 | > 117 | { 118 | SetVertexShader(CompileShader(vs_5_0, vShader())); 119 | SetHullShader(NULL); 120 | SetDomainShader(NULL); 121 | SetGeometryShader(NULL); 122 | SetPixelShader(CompileShader(ps_5_0, pShader())); 123 | } 124 | } -------------------------------------------------------------------------------- /plugins/cloth.comp: -------------------------------------------------------------------------------- 1 | // porated from https://github.com/SaschaWillems/Vulkan/tree/master/examples/computecloth 2 | 3 | #version 450 4 | 5 | struct Particle { 6 | vec4 pos; 7 | vec4 vel; 8 | float pinned; 9 | }; 10 | 11 | layout(std430, binding = 0) buffer ParticleIn { 12 | Particle particleIn[ ]; 13 | }; 14 | 15 | layout(std430, binding = 1) buffer ParticleOut { 16 | vec4 particleOut[ ]; 17 | }; 18 | 19 | // todo: use shared memory to speed up calculation 20 | 21 | layout (local_size_x = 10, local_size_y = 10) in; 22 | 23 | layout (binding = 2) uniform UBO 24 | { 25 | float deltaT; 26 | float particleMass; 27 | float springStiffness; 28 | float damping; 29 | float restDistH; 30 | float restDistV; 31 | float restDistD; 32 | float sphereRadius; 33 | vec4 spherePos; 34 | vec4 gravity; 35 | vec4 particleCount; 36 | } params; 37 | 38 | vec3 springForce(vec3 p0, vec3 p1, float restDist) 39 | { 40 | vec3 dist = p0 - p1; 41 | return normalize(dist) * params.springStiffness * (length(dist) - restDist); 42 | } 43 | 44 | void main() 45 | { 46 | uvec3 id = gl_GlobalInvocationID; 47 | ivec2 particleCount = ivec2(params.particleCount.xy); 48 | uint index = id.y * particleCount.x + id.x; 49 | if (index > particleCount.x * particleCount.y) 50 | return; 51 | 52 | // Pinned? 53 | if (particleIn[index].pinned == 1.0) { 54 | particleOut[index] = particleIn[index].pos; 55 | //particleOut[index].vel = vec4(0.0); 56 | particleIn[index].vel = vec4(0.0); 57 | return; 58 | } 59 | 60 | // Initial force from gravity 61 | vec3 force = params.gravity.xyz * params.particleMass; 62 | 63 | vec3 pos = particleIn[index].pos.xyz; 64 | vec3 vel = particleIn[index].vel.xyz; 65 | 66 | // Spring forces from neighboring particles 67 | // left 68 | if (id.x > 0) { 69 | force += springForce(particleIn[index-1].pos.xyz, pos, params.restDistH); 70 | } 71 | // right 72 | if (id.x < particleCount.x - 1) { 73 | force += springForce(particleIn[index + 1].pos.xyz, pos, params.restDistH); 74 | } 75 | // upper 76 | if (id.y < particleCount.y - 1) { 77 | force += springForce(particleIn[index + particleCount.x].pos.xyz, pos, params.restDistV); 78 | } 79 | // lower 80 | if (id.y > 0) { 81 | force += springForce(particleIn[index - particleCount.x].pos.xyz, pos, params.restDistV); 82 | } 83 | // upper-left 84 | if ((id.x > 0) && (id.y < particleCount.y - 1)) { 85 | force += springForce(particleIn[index + particleCount.x - 1].pos.xyz, pos, params.restDistD); 86 | } 87 | // lower-left 88 | if ((id.x > 0) && (id.y > 0)) { 89 | force += springForce(particleIn[index - particleCount.x - 1].pos.xyz, pos, params.restDistD); 90 | } 91 | // upper-right 92 | if ((id.x < particleCount.x - 1) && (id.y < particleCount.y - 1)) { 93 | force += springForce(particleIn[index + particleCount.x + 1].pos.xyz, pos, params.restDistD); 94 | } 95 | // lower-right 96 | if ((id.x < particleCount.x - 1) && (id.y > 0)) { 97 | force += springForce(particleIn[index - particleCount.x + 1].pos.xyz, pos, params.restDistD); 98 | } 99 | 100 | force += (-params.damping * vel); 101 | 102 | // Integrate 103 | vec3 f = force * (1.0 / params.particleMass); 104 | particleOut[index] = vec4(pos + vel * params.deltaT + 0.5 * f * params.deltaT * params.deltaT, 1.0); 105 | //particleOut[index].vel = vec4(vel + f * params.deltaT, 0.0); 106 | particleIn[index].vel = vec4(vel + f * params.deltaT, 0.0); 107 | 108 | // Sphere collision 109 | vec3 sphereDist = particleOut[index].xyz - params.spherePos.xyz; 110 | if (length(sphereDist) < params.sphereRadius + 0.01) { 111 | // If the particle is inside the sphere, push it to the outer radius 112 | particleOut[index].xyz = params.spherePos.xyz + normalize(sphereDist) * (params.sphereRadius + 0.01); 113 | // Cancel out velocity 114 | //particleOut[index].vel = vec4(0.0); 115 | particleIn[index].vel = vec4(0.0); 116 | } 117 | } -------------------------------------------------------------------------------- /shaders/fresnel.fx: -------------------------------------------------------------------------------- 1 | // ----------------------------------- Per Frame -------------------------------------- 2 | cbuffer UpdatePerFrame : register(b0) 3 | { 4 | float4x4 viewI : ViewInverse < string UIWidget = "None"; >; 5 | 6 | }; 7 | 8 | // --------------------------------------- Per Object ----------------------------------------- 9 | cbuffer UpdatePerObject : register(b1) 10 | { 11 | float4x4 worldIT : WorldInverseTranspose < string UIWidget = "None"; >; 12 | 13 | float4x4 world : World < string UIWidget = "None"; >; 14 | 15 | float4x4 wvp : WorldViewProjection < string UIWidget = "None"; >; 16 | 17 | }; 18 | 19 | // --------------------------------------- Attributes ----------------------------------------- 20 | cbuffer UpdateAttributes : register(b2) 21 | { 22 | float3 ambientColor 23 | < 24 | string UIName = "ambientColor"; 25 | string UIWidget = "ColorPicker"; 26 | > = {0.5,0.5,0.5}; 27 | 28 | float3 diffuseColor 29 | < 30 | string UIName = "diffuseColor"; 31 | string UIWidget = "ColorPicker"; 32 | > = {1.0,1.0,1.0}; 33 | 34 | float fresnelPower 35 | < 36 | float UIMin = 0.0; 37 | float UISoftMin = 0.0; 38 | float UIMax = 99.0; 39 | float UISoftMax = 99.0; 40 | float UIStep = 1.0; 41 | string UIName = "fresnelPower"; 42 | string UIWidget = "Slider"; 43 | > = 3.0; 44 | 45 | }; 46 | 47 | // ----------------------------------- Lights -------------------------------------- 48 | cbuffer UpdateLights : register(b3) 49 | { 50 | float3 Light1Dir : DIRECTION 51 | < 52 | string UIName = "Light 1 Direction"; 53 | string Space = "World"; 54 | string Object = "Light 1"; 55 | > = {0.0, -1.0, 0.0}; 56 | 57 | }; 58 | 59 | // -------------------------------------- APP and DATA -------------------------------------- 60 | struct APPDATA 61 | { 62 | float3 Position : POSITION; 63 | float3 Normal : NORMAL; 64 | }; 65 | 66 | struct SHADERDATA 67 | { 68 | float3 worldNormal : TEXCOORD0; 69 | float3 eyeVector : TEXCOORD1; 70 | float4 Position : SV_Position; 71 | }; 72 | 73 | // -------------------------------------- ShaderVertex -------------------------------------- 74 | SHADERDATA ShaderVertex(APPDATA IN) 75 | { 76 | SHADERDATA OUT; 77 | 78 | float3 worldNormal = mul(IN.Normal, worldIT); 79 | OUT.worldNormal = worldNormal; 80 | float3 CameraPosition = viewI[3].xyz; 81 | float3 worldSpacePos = mul(world, IN.Position); 82 | float3 eyeVector = (CameraPosition - worldSpacePos); 83 | OUT.eyeVector = eyeVector; 84 | float4 position = mul(float4(IN.Position, 1), wvp); 85 | OUT.Position = position; 86 | 87 | return OUT; 88 | } 89 | 90 | // -------------------------------------- ShaderPixel -------------------------------------- 91 | struct PIXELDATA 92 | { 93 | float4 Color : SV_Target; 94 | }; 95 | 96 | PIXELDATA ShaderPixel(SHADERDATA IN) 97 | { 98 | PIXELDATA OUT; 99 | 100 | float3 lightDir = normalize(-(Light1Dir)); 101 | float3 worldNormal = normalize(IN.worldNormal); 102 | float lambert = saturate(dot(lightDir, worldNormal)); 103 | float3 color = ((lambert + ambientColor.xyz) * diffuseColor.xyz); 104 | float fresne = pow((1.0 - saturate(dot(normalize(IN.eyeVector), worldNormal))), fresnelPower); 105 | float3 color46 = (color + (fresne * lambert)); 106 | float4 outColor = float4(color46.x, color46.y, color46.z, 1.0); 107 | OUT.Color = outColor; 108 | 109 | return OUT; 110 | } 111 | 112 | // -------------------------------------- technique sample --------------------------------------- 113 | technique11 sample 114 | { 115 | pass P0 116 | < 117 | string drawContext = "colorPass"; 118 | > 119 | { 120 | SetVertexShader(CompileShader(vs_5_0, ShaderVertex())); 121 | SetPixelShader(CompileShader(ps_5_0, ShaderPixel())); 122 | SetHullShader(NULL); 123 | SetDomainShader(NULL); 124 | SetGeometryShader(NULL); 125 | } 126 | 127 | } 128 | 129 | -------------------------------------------------------------------------------- /shaders/fresnel.ogsfx: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2015 Mack Stone 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | 25 | uniform mat4 wvp : WorldViewProjection < string UIWidget="None"; >; 26 | uniform mat4 wit : WorldInverseTranspose < string UIWidget="None"; >; 27 | uniform mat4 world : World < string UIWidget="None"; >; 28 | 29 | uniform mat4 viewI : ViewInverse < string UIWidget="None"; >; 30 | 31 | 32 | // parameters section 33 | uniform vec3 ambientColor : Diffuse 34 | < 35 | string UIName = "Ambient Color"; 36 | > = {0.5, 0.5, 0.5}; 37 | 38 | uniform vec3 diffuseColor : Diffuse 39 | < 40 | string UIName = "Diffuse Color"; 41 | > = {1.0, 1.0, 1.0}; 42 | 43 | uniform float fresnelPower 44 | < 45 | float UIMin = 0.0; 46 | float UIMax= 99.0; 47 | float UIStep = 1.0; 48 | string UIName = "Fresnel Power"; 49 | > = 3.0; 50 | 51 | // light direction 52 | uniform vec3 Light0Dir : DIRECTION 53 | < 54 | string UIName = "Light 0 Direction"; 55 | string Space = "World"; 56 | string Object = "Light 0"; 57 | > = {0.0, -1.0, 0.0}; 58 | 59 | 60 | //------------------------------------ 61 | // Attributes 62 | //------------------------------------ 63 | // input from application 64 | attribute appIn 65 | { 66 | vec3 inPosition : POSITION; 67 | vec3 inNormal : NORMAL; 68 | } 69 | 70 | // ouput from vertex shader 71 | // input to pixel shader 72 | attribute vsOut 73 | { 74 | vec3 worldNormal : NORMAL; 75 | vec3 eyeVector : TEXCOORD1; 76 | } 77 | 78 | // output to pixel shader 79 | attribute pixelOut 80 | { 81 | vec4 outColor : COLOR0; 82 | } 83 | 84 | //------------------------------------ 85 | // vertex shader 86 | //------------------------------------ 87 | GLSLShader VS 88 | { 89 | void main() 90 | { 91 | vec3 cameraPos = viewI[3].xyz; 92 | vec4 worldSpacePos = world * vec4(inPosition, 1.0); 93 | eyeVector = cameraPos - worldSpacePos.xyz; 94 | 95 | worldNormal = mat3(wit) * inNormal; 96 | gl_Position = wvp * vec4(inPosition, 1.0); 97 | } 98 | } 99 | 100 | 101 | //------------------------------------ 102 | // pixel shader 103 | //------------------------------------ 104 | GLSLShader FS 105 | { 106 | void main() 107 | { 108 | vec3 wNormal = normalize(worldNormal); 109 | vec3 lightDir = normalize(-Light0Dir); 110 | 111 | float lambert = clamp(dot(lightDir, wNormal), 0.0, 1.0); 112 | 113 | vec3 color = diffuseColor * (ambientColor + lambert); 114 | float fresnel = pow(1.0 - clamp(dot(normalize(eyeVector), wNormal), 0.0, 1.0), fresnelPower); 115 | vec3 finalColor = color + (fresnel * lambert); 116 | outColor = vec4(finalColor, 1.0); 117 | // outColor = vec4(1.0, 0.0, 0.0, 1.0); 118 | } 119 | } 120 | 121 | technique Simple 122 | { 123 | pass p0 124 | { 125 | VertexShader (in appIn, out vsOut) = VS; 126 | PixelShader (in vsOut, out pixelOut) = FS; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /shaders/transparent.fx: -------------------------------------------------------------------------------- 1 | // ----------------------------------- Per Frame -------------------------------------- 2 | cbuffer UpdatePerFrame : register(b0) 3 | { 4 | float4x4 viewI : ViewInverse < string UIWidget = "None"; >; 5 | 6 | }; 7 | 8 | // --------------------------------------- Per Object ----------------------------------------- 9 | cbuffer UpdatePerObject : register(b1) 10 | { 11 | float4x4 worldIT : WorldInverseTranspose < string UIWidget = "None"; >; 12 | 13 | float4x4 world : World < string UIWidget = "None"; >; 14 | 15 | float4x4 wvp : WorldViewProjection < string UIWidget = "None"; >; 16 | 17 | }; 18 | 19 | 20 | // --------------------------------------- Attributes ----------------------------------------- 21 | cbuffer UpdateAttributes : register(b2) 22 | { 23 | float3 ambientColor 24 | < 25 | string UIName = "ambientColor"; 26 | string UIWidget = "ColorPicker"; 27 | > = {0.5,0.5,0.5}; 28 | 29 | float3 diffuseColor 30 | < 31 | string UIName = "diffuseColor"; 32 | string UIWidget = "ColorPicker"; 33 | > = {1.0,1.0,1.0}; 34 | 35 | float fresnelPower 36 | < 37 | float UIMin = 0.0; 38 | float UISoftMin = 0.0; 39 | float UIMax = 99.0; 40 | float UISoftMax = 99.0; 41 | float UIStep = 1.0; 42 | string UIName = "fresnelPower"; 43 | string UIWidget = "Slider"; 44 | > = 3.0; 45 | 46 | float Opacity : OPACITY 47 | < 48 | //string UIGroup = "Opacity"; 49 | string UIWidget = "Slider"; 50 | float UIMin = 0.0; 51 | float UIMax = 1.0; 52 | float UIStep = 0.001; 53 | string UIName = "Opacity"; 54 | int UIOrder = 220; 55 | > = 1.0; 56 | }; 57 | 58 | // ----------------------------------- Lights -------------------------------------- 59 | cbuffer UpdateLights : register(b3) 60 | { 61 | float3 Light1Dir : DIRECTION 62 | < 63 | string UIName = "Light 1 Direction"; 64 | string Space = "World"; 65 | string Object = "Light 1"; 66 | > = {0.0, -1.0, 0.0}; 67 | 68 | }; 69 | 70 | // -------------------------------------- APP and DATA -------------------------------------- 71 | struct APPDATA 72 | { 73 | float3 Position : POSITION; 74 | float3 Normal : NORMAL; 75 | }; 76 | 77 | struct SHADERDATA 78 | { 79 | float3 worldNormal : TEXCOORD0; 80 | float3 eyeVector : TEXCOORD1; 81 | float4 Position : SV_Position; 82 | }; 83 | 84 | // -------------------------------------- ShaderVertex -------------------------------------- 85 | SHADERDATA ShaderVertex(APPDATA IN) 86 | { 87 | SHADERDATA OUT; 88 | 89 | float3 worldNormal = mul(IN.Normal, worldIT); 90 | OUT.worldNormal = worldNormal; 91 | float3 CameraPosition = viewI[3].xyz; 92 | float3 worldSpacePos = mul(world, IN.Position); 93 | float3 eyeVector = (CameraPosition - worldSpacePos); 94 | OUT.eyeVector = eyeVector; 95 | float4 position = mul(float4(IN.Position, 1), wvp); 96 | OUT.Position = position; 97 | 98 | return OUT; 99 | } 100 | 101 | // -------------------------------------- ShaderPixel -------------------------------------- 102 | struct PIXELDATA 103 | { 104 | float4 Color : SV_Target; 105 | }; 106 | 107 | PIXELDATA ShaderPixel(SHADERDATA IN) 108 | { 109 | PIXELDATA OUT; 110 | 111 | float3 lightDir = normalize(-(Light1Dir)); 112 | float3 worldNormal = normalize(IN.worldNormal); 113 | float lambert = saturate(dot(lightDir, worldNormal)); 114 | float3 color = ((lambert + ambientColor.xyz) * diffuseColor.xyz); 115 | float fresne = pow((1.0 - saturate(dot(normalize(IN.eyeVector), worldNormal))), fresnelPower); 116 | float3 color46 = (color + (fresne * lambert)); 117 | float4 outColor = float4(color46.x, color46.y, color46.z, fresne); 118 | OUT.Color = outColor; 119 | 120 | return OUT; 121 | } 122 | 123 | // -------------------------------------- technique sample --------------------------------------- 124 | technique11 sample 125 | < 126 | int isTransparent = 3; 127 | > 128 | { 129 | pass P0 130 | < 131 | string drawContext = "colorPass"; 132 | > 133 | { 134 | SetVertexShader(CompileShader(vs_5_0, ShaderVertex())); 135 | SetPixelShader(CompileShader(ps_5_0, ShaderPixel())); 136 | SetHullShader(NULL); 137 | SetDomainShader(NULL); 138 | SetGeometryShader(NULL); 139 | } 140 | 141 | } 142 | 143 | -------------------------------------------------------------------------------- /shaders/phong.fx: -------------------------------------------------------------------------------- 1 | // ----------------------------------- Per Frame -------------------------------------- 2 | cbuffer UpdatePerFrame : register(b0) 3 | { 4 | float4x4 viewI : ViewInverse < string UIWidget = "None"; >; 5 | 6 | }; 7 | 8 | // --------------------------------------- Per Object ----------------------------------------- 9 | cbuffer UpdatePerObject : register(b1) 10 | { 11 | float4x4 worldIT : WorldInverseTranspose < string UIWidget = "None"; >; 12 | 13 | float4x4 world : World < string UIWidget = "None"; >; 14 | 15 | float4x4 wvp : WorldViewProjection < string UIWidget = "None"; >; 16 | 17 | }; 18 | 19 | // --------------------------------------- Attributes ----------------------------------------- 20 | cbuffer UpdateAttributes : register(b2) 21 | { 22 | float3 ambientColor 23 | < 24 | string UIName = "ambientColor"; 25 | string UIWidget = "ColorPicker"; 26 | > = {0.15,0.15,0.15}; 27 | 28 | float3 diffuseColor 29 | < 30 | string UIName = "diffuseColor"; 31 | string UIWidget = "ColorPicker"; 32 | > = {0.7,0.7,0.7}; 33 | 34 | float fresnelPower 35 | < 36 | float UIMin = 0.0; 37 | float UISoftMin = 0.0; 38 | float UIMax = 99.0; 39 | float UISoftMax = 99.0; 40 | float UIStep = 1.0; 41 | string UIName = "fresnelPower"; 42 | string UIWidget = "Slider"; 43 | > = 3.0; 44 | 45 | float specularPower 46 | < 47 | float UIMin = 0.0; 48 | float UISoftMin = 0.0; 49 | float UIMax = 99.0; 50 | float UISoftMax = 99.0; 51 | float UIStep = 0.01; 52 | string UIName = "specularPower"; 53 | string UIWidget = "Slider"; 54 | > = 30.0; 55 | 56 | }; 57 | 58 | // ----------------------------------- Lights -------------------------------------- 59 | cbuffer UpdateLights : register(b3) 60 | { 61 | float3 Light1Dir : DIRECTION 62 | < 63 | string UIName = "Light 1 Direction"; 64 | string Space = "World"; 65 | string Object = "Light 1"; 66 | > = {0.0, -1.0, 0.0}; 67 | 68 | }; 69 | 70 | // -------------------------------------- APP and DATA -------------------------------------- 71 | struct APPDATA 72 | { 73 | float3 Position : POSITION; 74 | float3 Normal : NORMAL; 75 | }; 76 | 77 | struct SHADERDATA 78 | { 79 | float3 worldNormal : TEXCOORD0; 80 | float3 eyeVector : TEXCOORD1; 81 | float4 Position : SV_Position; 82 | }; 83 | 84 | // -------------------------------------- ShaderVertex -------------------------------------- 85 | SHADERDATA ShaderVertex(APPDATA IN) 86 | { 87 | SHADERDATA OUT; 88 | 89 | float3 worldNormal = mul(IN.Normal, worldIT); 90 | OUT.worldNormal = worldNormal; 91 | float3 CameraPosition = viewI[3].xyz; 92 | float3 worldSpacePos = mul(world, IN.Position); 93 | float3 eyeVector = (CameraPosition - worldSpacePos); 94 | OUT.eyeVector = eyeVector; 95 | float4 position = mul(float4(IN.Position, 1), wvp); 96 | OUT.Position = position; 97 | 98 | return OUT; 99 | } 100 | 101 | // -------------------------------------- ShaderPixel -------------------------------------- 102 | struct PIXELDATA 103 | { 104 | float4 Color : SV_Target; 105 | }; 106 | 107 | PIXELDATA ShaderPixel(SHADERDATA IN) 108 | { 109 | PIXELDATA OUT; 110 | 111 | float3 lightDir = normalize(-(Light1Dir)); 112 | float3 worldNormal = normalize(IN.worldNormal); 113 | float lambert = saturate(dot(lightDir, worldNormal)); 114 | 115 | float3 eyeVector = normalize(IN.eyeVector); 116 | float fresne = pow((1.0 - saturate(dot(eyeVector, worldNormal))), fresnelPower) * lambert; 117 | 118 | float3 reflectionVector = reflect(eyeVector, worldNormal); 119 | float specular = pow(saturate(dot(-(reflectionVector), lightDir)), specularPower); 120 | float3 color = (lambert + ambientColor.xyz) * diffuseColor.xyz + fresne + specular; 121 | float4 outColor = float4(color.x, color.y, color.z, 1.0); 122 | OUT.Color = outColor; 123 | 124 | return OUT; 125 | } 126 | 127 | // -------------------------------------- technique sample --------------------------------------- 128 | technique11 sample 129 | { 130 | pass P0 131 | < 132 | string drawContext = "colorPass"; 133 | > 134 | { 135 | SetVertexShader(CompileShader(vs_5_0, ShaderVertex())); 136 | SetPixelShader(CompileShader(ps_5_0, ShaderPixel())); 137 | SetHullShader(NULL); 138 | SetDomainShader(NULL); 139 | SetGeometryShader(NULL); 140 | } 141 | 142 | } 143 | 144 | -------------------------------------------------------------------------------- /shaders/vertexAnimation.fx: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2014 Mack Stone 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | 25 | // using http://adrianboeing.blogspot.com/2011/02/ripple-effect-in-webgl.html 26 | // to make ripple effect 27 | 28 | #define PI 3.1415926 29 | 30 | float4x4 world : World < string UIWidget = "None"; >; 31 | float4x4 wvp : WorldViewProjection < string UIWidget = "None"; >; 32 | float4x4 worldInverseTranspose : WorldInverseTranspose < string UIWidget = "None"; >; 33 | 34 | // time from maya 35 | float time : Time < string UIWidget = "None"; >; 36 | 37 | // render state 38 | RasterizerState wireframeState 39 | { 40 | CullMode = None; 41 | FillMode = WIREFRAME; 42 | }; 43 | 44 | // parameters section 45 | float3 diffuseColor : Diffuse 46 | < 47 | string UIName = "Diffuse Color"; 48 | > = {1.0f, 1.0f, 1.0f}; 49 | 50 | float3 ambientColor : Diffuse 51 | < 52 | string UIName = "Ambient Color"; 53 | > = {0.1f, 0.1f, 0.1f}; 54 | 55 | // light direction 56 | float3 lightDirection : Direction 57 | < 58 | string UIName = "Light Direction"; 59 | string Space = "World"; // using world space 60 | > = {0.0f, 1.0f, 0.0f}; 61 | 62 | // ripple control attributes 63 | float Amplitude 64 | < 65 | string UIGroup = "Ripple"; 66 | string UIName = "Amplitude"; 67 | int UIOrder = 11; 68 | float UIMin = 0.0; 69 | float UISoftMax = 1.0; 70 | float UIMax = 10.0; 71 | float UIStep = 0.1; 72 | > = 0.125f; 73 | 74 | float Frequency 75 | < 76 | string UIGroup = "Ripple"; 77 | string UIName = "Frequency"; 78 | int UIOrder = 12; 79 | float UIMin = 0.1; 80 | float UISoftMax = 1.0; 81 | float UIMax = 10.0; 82 | float UIStep = 0.1; 83 | > = .5f; 84 | 85 | 86 | 87 | //------------------------------------ 88 | // Structs 89 | //------------------------------------ 90 | // input from application 91 | struct APPDATA 92 | { 93 | float4 position : POSITION; 94 | float3 normal : NORMAL; 95 | }; 96 | 97 | // output to pixel shader 98 | struct SHADERDATA 99 | { 100 | float4 position : SV_Position; 101 | float3 worldNormal : TEXCOORD0; 102 | }; 103 | 104 | 105 | //------------------------------------ 106 | // vertex shader 107 | //------------------------------------ 108 | SHADERDATA vShader(APPDATA IN) 109 | { 110 | SHADERDATA OUT; 111 | float r = length(IN.position.xz); 112 | float y = Amplitude * sin(PI * r * Frequency * time) / r; 113 | OUT.position = mul(float4(IN.position.x, y, IN.position.z, 1.), wvp); 114 | OUT.worldNormal = mul(IN.normal, worldInverseTranspose); 115 | 116 | return OUT; 117 | } 118 | 119 | 120 | //------------------------------------ 121 | // pixel shader 122 | //------------------------------------ 123 | float4 pShader(SHADERDATA IN) : COLOR 124 | { 125 | float4 outColor; 126 | 127 | float3 worldNormal = normalize(IN.worldNormal); 128 | float3 lightDir = normalize(-lightDirection); 129 | 130 | float lambert = saturate(dot(lightDir, worldNormal)); 131 | 132 | outColor.rgb = diffuseColor * (ambientColor + lambert); 133 | outColor.a = 1.0f; 134 | 135 | return outColor; 136 | } 137 | 138 | technique11 Simple 139 | { 140 | pass one 141 | { 142 | SetVertexShader(CompileShader(vs_5_0, vShader())); 143 | SetHullShader(NULL); 144 | SetDomainShader(NULL); 145 | SetGeometryShader(NULL); 146 | SetPixelShader(CompileShader(ps_5_0, pShader())); 147 | SetRasterizerState(wireframeState); 148 | } 149 | } -------------------------------------------------------------------------------- /shaders/toon.fx: -------------------------------------------------------------------------------- 1 | // ----------------------------------- Per Frame -------------------------------------- 2 | cbuffer UpdatePerFrame : register(b0) 3 | { 4 | float4x4 viewI : ViewInverse < string UIWidget = "None"; >; 5 | 6 | }; 7 | 8 | // --------------------------------------- Per Object ----------------------------------------- 9 | cbuffer UpdatePerObject : register(b1) 10 | { 11 | float4x4 worldIT : WorldInverseTranspose < string UIWidget = "None"; >; 12 | 13 | float4x4 world : World < string UIWidget = "None"; >; 14 | 15 | float4x4 wvp : WorldViewProjection < string UIWidget = "None"; >; 16 | 17 | }; 18 | 19 | 20 | // --------------------------------------- Attributes ----------------------------------------- 21 | cbuffer UpdateAttributes : register(b2) 22 | { 23 | float3 ambientColor 24 | < 25 | string UIName = "ambientColor"; 26 | string UIWidget = "ColorPicker"; 27 | > = {0.5,0.5,0.5}; 28 | 29 | float3 diffuseColor 30 | < 31 | string UIName = "diffuseColor"; 32 | string UIWidget = "ColorPicker"; 33 | > = {.8,.8,.8}; 34 | 35 | float3 specColor 36 | < 37 | string UIName = "Specular Color"; 38 | string UIWidget = "ColorPicker"; 39 | > = {1.0,1.0,1.0}; 40 | 41 | float diffuseThreshold 42 | < 43 | string UIWidget = "Slider"; 44 | float UIMin = -1.0; 45 | float UIMax = 1.0; 46 | float UIStep = 0.001; 47 | string UIName = "Lighting Threshold"; 48 | > = .1; 49 | 50 | float diffusion 51 | < 52 | string UIWidget = "Slider"; 53 | float UIMin = -1.0; 54 | float UIMax = 1.0; 55 | float UIStep = 0.001; 56 | string UIName = "Diffusion"; 57 | > = .5; 58 | 59 | float shininess 60 | < 61 | string UIWidget = "Slider"; 62 | float UIMin = 0.0; 63 | float UIMax = 1.0; 64 | float UIStep = 0.001; 65 | string UIName = "Shininess"; 66 | > = .6; 67 | 68 | float specDiffusion 69 | < 70 | string UIWidget = "Slider"; 71 | float UIMin = 0.0; 72 | float UIMax = 1.0; 73 | float UIStep = .001; 74 | string UIName = "Specular Diffusion"; 75 | > = .0;s 76 | }; 77 | 78 | // ----------------------------------- Lights -------------------------------------- 79 | cbuffer UpdateLights : register(b3) 80 | { 81 | float3 Light1Dir : Direction 82 | < 83 | string UIName = "Light 1 Direction"; 84 | string Space = "World"; 85 | string Object = "Light 1"; 86 | > = {0.0, -1.0, 0.0}; 87 | 88 | float Light1Intensity : LightIntensity 89 | < 90 | string UIName = "Light 1 Position"; 91 | string Object = "Light 1"; 92 | > = {1.0}; 93 | }; 94 | 95 | // -------------------------------------- APP and DATA -------------------------------------- 96 | struct APPDATA 97 | { 98 | float3 Position : POSITION; 99 | float3 Normal : NORMAL; 100 | }; 101 | 102 | struct SHADERDATA 103 | { 104 | float4 Position : SV_Position; 105 | float3 worldNormal : TEXCOORD0; 106 | float3 viewDir : TEXCOORD1; 107 | }; 108 | 109 | // -------------------------------------- ShaderVertex -------------------------------------- 110 | SHADERDATA ShaderVertex(APPDATA IN) 111 | { 112 | SHADERDATA OUT; 113 | 114 | OUT.worldNormal = mul(IN.Normal, worldIT); 115 | OUT.Position = mul(float4(IN.Position, 1), wvp); 116 | OUT.viewDir = normalize(viewI[3].xyz - mul(IN.Position, world)); 117 | 118 | return OUT; 119 | } 120 | 121 | // -------------------------------------- ShaderPixel -------------------------------------- 122 | struct PIXELDATA 123 | { 124 | float4 Color : SV_Target; 125 | }; 126 | 127 | PIXELDATA ShaderPixel(SHADERDATA IN) 128 | { 129 | PIXELDATA OUT; 130 | 131 | float dotL = saturate(dot(IN.worldNormal, Light1Dir)); 132 | float diffuseCutoff = saturate((max(diffuseThreshold, dotL) - diffuseThreshold) * pow((2 - diffusion), 10)); 133 | float specularCutoff = saturate((max(shininess, dot(reflect(-Light1Dir, IN.worldNormal), IN.viewDir)) - shininess) * pow((2 - specDiffusion), 10)); 134 | 135 | float3 ambientLight = (1 - diffuseCutoff) * ambientColor; 136 | float3 diffuseReflection = (1 - specularCutoff) * diffuseColor * diffuseCutoff; 137 | float3 specularReflection = specColor * specularCutoff; 138 | 139 | OUT.Color.rgb = ambientLight + diffuseReflection + specularReflection; 140 | OUT.Color.a = 1.0; 141 | 142 | return OUT; 143 | } 144 | 145 | // -------------------------------------- technique sample --------------------------------------- 146 | technique11 sample 147 | < 148 | //int isTransparent = 3; 149 | > 150 | { 151 | pass P0 152 | < 153 | string drawContext = "colorPass"; 154 | > 155 | { 156 | SetVertexShader(CompileShader(vs_5_0, ShaderVertex())); 157 | SetPixelShader(CompileShader(ps_5_0, ShaderPixel())); 158 | SetHullShader(NULL); 159 | SetDomainShader(NULL); 160 | SetGeometryShader(NULL); 161 | } 162 | 163 | } 164 | 165 | -------------------------------------------------------------------------------- /shaders/outline_geometryShader.fx: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2014 Mack Stone 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | 25 | 26 | float4x4 world : World < string UIWidget = "None"; >; 27 | float4x4 view : View < string UIWidget = "None"; >; 28 | float4x4 proj : Projection < string UIWidget = "None"; >; 29 | 30 | // parameters section 31 | float3 outlineColor : Diffuse 32 | < 33 | string UIName = "Outline Color"; 34 | > = {.5f, .5f, .5f}; 35 | 36 | 37 | //------------------------------------ 38 | // Structs 39 | //------------------------------------ 40 | // input from application 41 | struct APPDATA 42 | { 43 | float4 position : POSITION; 44 | //float3 normal : NORMAL; 45 | }; 46 | 47 | // output to geometry and pixel shader 48 | struct GSPS_INPUT 49 | { 50 | float4 position : SV_Position; 51 | //float3 worldNormal : TEXCOORD0; 52 | }; 53 | 54 | 55 | //------------------------------------ 56 | // vertex shader 57 | //------------------------------------ 58 | GSPS_INPUT vShader(APPDATA IN) 59 | { 60 | GSPS_INPUT OUT; 61 | OUT.position = mul(IN.position, world); 62 | OUT.position = mul(OUT.position, view); 63 | 64 | return OUT; 65 | } 66 | 67 | 68 | //------------------------------------ 69 | // geometry shader 70 | //------------------------------------ 71 | [maxvertexcount(32)] 72 | void gShader(triangleadj GSPS_INPUT input[6], inout LineStream lineStream) 73 | { 74 | GSPS_INPUT OUT; 75 | 76 | float3 V0 = input[0].position.xyz; 77 | float3 V1 = input[1].position.xyz; 78 | float3 V2 = input[2].position.xyz; 79 | float3 V3 = input[3].position.xyz; 80 | float3 V4 = input[4].position.xyz; 81 | float3 V5 = input[5].position.xyz; 82 | 83 | float3 N042 = cross(V4 - V0, V2 - V0); 84 | float3 N021 = cross(V2 - V0, V1 - V0); 85 | float3 N243 = cross(V4 - V2, V3 - V2); 86 | float3 N405 = cross(V0 - V4, V5 - V4); 87 | 88 | // rashly assume all 4 normals are really meant to be 89 | // within 90 degrees of each other 90 | if (dot(N042, N021) < 0.) 91 | N021 = -N021; 92 | 93 | if (dot(N042, N243) < 0.) 94 | N243 = -N243; 95 | 96 | if (dot(N042, N405) < 0.) 97 | N405 = -N405; 98 | 99 | // look for a silhouette edge between triangles 042 and 021 100 | if (N042.z * N021.z < 0.) 101 | { 102 | OUT.position = mul(float4(V0, 1.0), proj); 103 | lineStream.Append(OUT); 104 | 105 | OUT.position = mul(float4(V2, 1.0), proj); 106 | lineStream.Append(OUT); 107 | 108 | lineStream.RestartStrip(); 109 | } 110 | 111 | // look for a silhouette edge between triangles 042 and 243 112 | if (N042.z * N243.z < 0.) 113 | { 114 | OUT.position = mul(float4(V2, 1.0), proj); 115 | lineStream.Append(OUT); 116 | 117 | OUT.position = mul(float4(V4, 1.0), proj); 118 | lineStream.Append(OUT); 119 | 120 | lineStream.RestartStrip(); 121 | } 122 | 123 | // look for a silhouette edge between triangles 042 and 405 124 | if (N042.z * N405.z < 0.) 125 | { 126 | OUT.position = mul(float4(V4, 1.0), proj); 127 | lineStream.Append(OUT); 128 | 129 | OUT.position = mul(float4(V0, 1.0), proj); 130 | lineStream.Append(OUT); 131 | 132 | lineStream.RestartStrip(); 133 | } 134 | } 135 | 136 | 137 | //------------------------------------ 138 | // pixel shader 139 | //------------------------------------ 140 | float4 pShader(GSPS_INPUT IN) : COLOR 141 | { 142 | float4 outColor = float4(outlineColor, 1.0); 143 | return outColor; 144 | } 145 | 146 | technique11 Simple 147 | { 148 | pass one 149 | { 150 | SetVertexShader(CompileShader(vs_5_0, vShader())); 151 | SetHullShader(NULL); 152 | SetDomainShader(NULL); 153 | SetGeometryShader(CompileShader(gs_5_0, gShader())); 154 | SetPixelShader(CompileShader(ps_5_0, pShader())); 155 | } 156 | } -------------------------------------------------------------------------------- /shaders/normalMap.fx: -------------------------------------------------------------------------------- 1 | // ----------------------------------- Per Frame -------------------------------------- 2 | cbuffer UpdatePerFrame : register(b0) 3 | { 4 | float4x4 viewI : ViewInverse < string UIWidget = "None"; >; 5 | 6 | }; 7 | 8 | // --------------------------------------- Per Object ----------------------------------------- 9 | cbuffer UpdatePerObject : register(b1) 10 | { 11 | float4x4 world : World < string UIWidget = "None"; >; 12 | float4x4 worldIT : WorldInverseTranspose < string UIWidget = "None"; >; 13 | 14 | float4x4 wvp : WorldViewProjection < string UIWidget = "None"; >; 15 | 16 | }; 17 | 18 | // --------------------------------------- Attributes ----------------------------------------- 19 | cbuffer UpdateAttributes : register(b2) 20 | { 21 | float3 ambientColor 22 | < 23 | string UIName = "ambientColor"; 24 | string UIWidget = "ColorPicker"; 25 | > = {0.317464,0.317464,0.317464}; 26 | 27 | float3 diffuseColor 28 | < 29 | string UIName = "diffuseColor"; 30 | string UIWidget = "ColorPicker"; 31 | > = {1.0,1.0,1.0}; 32 | 33 | float3 specularColor 34 | < 35 | string UIName = "specularColor"; 36 | string UIWidget = "ColorPicker"; 37 | > = {1.0,1.0,1.0}; 38 | 39 | float specularPower 40 | < 41 | float UIMin = 0.0; 42 | float UISoftMin = 0.0; 43 | float UIMax = 99.0; 44 | float UISoftMax = 99.0; 45 | float UIStep = 0.01; 46 | string UIName = "specularPower"; 47 | string UIWidget = "Slider"; 48 | > = 30.0; 49 | 50 | }; 51 | 52 | // ----------------------------------- Lights -------------------------------------- 53 | cbuffer UpdateLights : register(b3) 54 | { 55 | float3 Light1Dir : DIRECTION 56 | < 57 | string UIName = "Light 1 Direction"; 58 | string Space = "World"; 59 | string Object = "Light 1"; 60 | > = {0.0, -1.0, 0.0}; 61 | 62 | }; 63 | 64 | // ---------------------------------------- Textures ----------------------------------------- 65 | Texture2D diffuseTexture 66 | < 67 | string ResourceName = ""; 68 | string UIName = "diffuseTexture"; 69 | string ResourceType = "2D"; 70 | string UIWidget = "FilePicker"; 71 | >; 72 | 73 | Texture2D normalTexture 74 | < 75 | string ResourceName = ""; 76 | string UIName = "normalTexture"; 77 | string ResourceType = "2D"; 78 | string UIWidget = "FilePicker"; 79 | >; 80 | 81 | SamplerState textureSampler 82 | { 83 | Filter = MIN_MAG_MIP_LINEAR; 84 | AddressU = WRAP; 85 | AddressV = WRAP; 86 | AddressW = WRAP; 87 | }; 88 | 89 | 90 | // -------------------------------------- APP and DATA -------------------------------------- 91 | struct APPDATA 92 | { 93 | float3 Position : POSITION; 94 | float3 Normal : NORMAL; 95 | float3 Tangent : TANGENT; 96 | float3 BiNormal : BINORMAL; 97 | float2 map1 : TEXCOORD0; 98 | }; 99 | 100 | struct SHADERDATA 101 | { 102 | float2 uv : TEXCOORD0; 103 | float3 worldNormal : TEXCOORD1; 104 | float3 tangent : TEXCOORD2; 105 | float3 binormal : TEXCOORD3; 106 | float3 eyeVector : TEXCOORD4; 107 | float4 position : SV_Position; 108 | }; 109 | 110 | // -------------------------------------- ShaderVertex -------------------------------------- 111 | SHADERDATA ShaderVertex(APPDATA IN) 112 | { 113 | SHADERDATA OUT; 114 | 115 | OUT.worldNormal = mul(IN.Normal, worldIT); 116 | OUT.uv = IN.map1; 117 | OUT.tangent = IN.Tangent; 118 | OUT.binormal = IN.BiNormal; 119 | 120 | float3 CameraPosition = viewI[3].xyz; 121 | float3 worldSpacePos = mul(world, IN.Position); 122 | OUT.eyeVector = CameraPosition - worldSpacePos; 123 | 124 | float4 position = mul(float4(IN.Position, 1), wvp); 125 | OUT.position = position; 126 | 127 | return OUT; 128 | } 129 | 130 | // -------------------------------------- ShaderPixel -------------------------------------- 131 | struct PIXELDATA 132 | { 133 | float4 Color : SV_Target; 134 | }; 135 | 136 | PIXELDATA ShaderPixel(SHADERDATA IN) 137 | { 138 | PIXELDATA OUT; 139 | 140 | float3 lightDir = normalize(-Light1Dir); 141 | float3 eyeVector = normalize(IN.eyeVector); 142 | float3 worldNormal = normalTexture.Sample(textureSampler, float2(IN.uv.x, 1-IN.uv.y)).rgb * 2.0 - 1.0; 143 | worldNormal = ((worldNormal.x * IN.tangent) + (worldNormal.y * IN.binormal) + (worldNormal.z * IN.worldNormal)); 144 | 145 | float3 reflectionVec = -reflect(eyeVector, worldNormal); 146 | float3 specular = pow(saturate(dot(reflectionVec, lightDir)), specularPower) * specularColor; 147 | 148 | float lambert = saturate(dot(lightDir, normalize(IN.worldNormal))); 149 | float4 diffuseMap = diffuseTexture.Sample(textureSampler, float2(IN.uv.x, 1-IN.uv.y)); 150 | float3 color = ((lambert + ambientColor.xyz) * (diffuseColor.xyz * diffuseMap.xyz)) + specular; 151 | OUT.Color = float4(color.x, color.y, color.z, 1.0); 152 | //OUT.Color = float4(worldNormal, 1.0); 153 | 154 | return OUT; 155 | } 156 | 157 | // -------------------------------------- technique sample --------------------------------------- 158 | technique11 sample 159 | { 160 | pass P0 161 | < 162 | string drawContext = "colorPass"; 163 | > 164 | { 165 | SetVertexShader(CompileShader(vs_5_0, ShaderVertex())); 166 | SetPixelShader(CompileShader(ps_5_0, ShaderPixel())); 167 | SetHullShader(NULL); 168 | SetDomainShader(NULL); 169 | SetGeometryShader(NULL); 170 | } 171 | 172 | } 173 | 174 | -------------------------------------------------------------------------------- /shaders/normalMap.ogsfx: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2015 Mack Stone 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /* 25 | A normal map shader from 26 | http://learnopengl.com/#!Advanced-Lighting/Normal-Mapping 27 | */ 28 | 29 | 30 | // uniform mat4 wvp : WorldViewProjection < string UIWidget="None"; >; 31 | uniform mat4 world : World < string UIWidget="None"; >; 32 | uniform mat4 view : View < string UIWidget="None"; >; 33 | uniform mat4 projection : Projection < string UIWidget="None"; >; 34 | 35 | uniform mat4 wit : WorldInverseTranspose < string UIWidget="None"; >; 36 | uniform mat4 viewI : ViewInverse < string UIWidget="None"; >; 37 | 38 | 39 | // light 40 | uniform vec3 Light0Pos : POSITION 41 | < 42 | string UIName = "Light 0 Position"; 43 | string Space = "World"; 44 | string Object = "Light 0"; 45 | > = {1.0, 1.0, 1.0}; 46 | 47 | uniform vec3 Light0Dir : DIRECTION 48 | < 49 | string UIName = "Light 0 Direction"; 50 | string Space = "World"; 51 | string Object = "Light 0"; 52 | > = {0.0, -1.0, 0.0}; 53 | 54 | 55 | // textures 56 | uniform texture2D diffuseMap 57 | < 58 | //Specify the texture file to be loaded by default 59 | string ResourceName = "brickwall.jpg"; 60 | 61 | //Specify the type of texture 62 | string ResourceType = "2D"; 63 | 64 | string UIName = "Diffuse Map"; 65 | >; 66 | 67 | uniform texture2D normalMap 68 | < 69 | //Specify the texture file to be loaded by default 70 | string ResourceName = "brickwall_normal.jpg"; 71 | 72 | //Specify the type of texture 73 | string ResourceType = "2D"; 74 | 75 | string UIName = "Normal Map"; 76 | >; 77 | 78 | uniform sampler2D diffuseMapSampler = sampler_state 79 | { 80 | Texture = ; 81 | TEXTURE_MIN_FILTER = LINEAR; 82 | TEXTURE_MAG_FILTER = LINEAR; 83 | TEXTURE_WRAP_S = REPEAT; 84 | TEXTURE_WRAP_T = REPEAT; 85 | TEXTURE_WRAP_R = REPEAT; 86 | }; 87 | 88 | uniform sampler2D normalMapSampler = sampler_state 89 | { 90 | Texture = ; 91 | TEXTURE_MIN_FILTER = LINEAR; 92 | TEXTURE_MAG_FILTER = LINEAR; 93 | TEXTURE_WRAP_S = REPEAT; 94 | TEXTURE_WRAP_T = REPEAT; 95 | TEXTURE_WRAP_R = REPEAT; 96 | }; 97 | 98 | 99 | //------------------------------------ 100 | // Attributes 101 | //------------------------------------ 102 | // input from application 103 | attribute appIn 104 | { 105 | vec3 inPosition : POSITION; 106 | vec2 inUV : TEXCOORD0; 107 | vec3 inNormal : NORMAL; 108 | vec3 inTangent : TANGENT; 109 | vec3 inBiTangent : BITANGENT; 110 | } 111 | 112 | // ouput from vertex shader 113 | // input to pixel shader 114 | attribute vsOut 115 | { 116 | // vec3 worldNormal : NORMAL; 117 | vec2 outUV : TEXCOORD0; 118 | // vec3 fragPos : TEXCOORD1; 119 | // vec3 tangentLightPos : TEXCOORD2; 120 | // vec3 tangentViewPos : TEXCOORD3; 121 | // vec3 tangentFragPos : TEXCOORD4; 122 | } 123 | 124 | // output to pixel shader 125 | attribute pixelOut 126 | { 127 | vec4 outColor : COLOR0; 128 | } 129 | 130 | //------------------------------------ 131 | // vertex shader 132 | //------------------------------------ 133 | GLSLShader VS 134 | { 135 | void main() 136 | { 137 | vec3 cameraPos = viewI[3].xyz; // view pos 138 | // fragPos = vec3(world * vec4(inPosition, 1.0)); 139 | outUV = inUV; 140 | 141 | mat3 normalMatrix = mat3(wit); 142 | vec3 T = normalize(normalMatrix * inTangent); 143 | vec3 B = normalize(normalMatrix * inBiTangent); 144 | vec3 N = normalize(normalMatrix * inNormal); 145 | 146 | // mat3 TBN = transpose(mat3(T, B, N)); 147 | // tangentLightPos = TBN * Light0Pos; 148 | // tangentViewPos = TBN * cameraPos; 149 | // tangentFragPos = TBN * fragPos; 150 | 151 | // worldNormal = mat3(wit) * inNormal; 152 | gl_Position = projection * view * world * vec4(inPosition, 1.0); 153 | } 154 | } 155 | 156 | 157 | //------------------------------------ 158 | // pixel shader 159 | //------------------------------------ 160 | GLSLShader FS 161 | { 162 | void main() 163 | { 164 | // Obtain normal from normal map in range [0,1] 165 | vec3 normal = texture(normalMapSampler, vec2(outUV.x, 1 - outUV.y)).rgb; 166 | // Transform normal vector to range [-1, 1] 167 | normal = normalize(normal * 2.0 - 1.0); // this normal is in tangent space 168 | 169 | // Get diffuse color 170 | vec3 color = texture(diffuseMapSampler, vec2(outUV.x, 1 - outUV.y)).rgb; 171 | // Ambient 172 | vec3 ambient = 0.1 * color; 173 | // Diffuse 174 | float diff = max(dot(Light0Dir, normal), 0.0); 175 | vec3 diffuse = diff * color; 176 | // Specular 177 | vec3 reflectDir = reflect(-Light0Dir, normal); 178 | vec3 halfwayDir = normalize(Light0Dir + viewI[3].xyz); 179 | float spec = pow(max(dot(normal, halfwayDir), 0.0), 32.0); 180 | vec3 specular = vec3(0.2) * spec; 181 | 182 | outColor = vec4(ambient + diffuse + specular, 1.0); 183 | // outColor = vec4(1.0, 0.0, 0.0, 1.0); 184 | } 185 | } 186 | 187 | technique Simple 188 | { 189 | pass p0 190 | { 191 | VertexShader (in appIn, out vsOut) = VS; 192 | PixelShader (in vsOut, out pixelOut) = FS; 193 | } 194 | } 195 | -------------------------------------------------------------------------------- /plugins/yTwistNode_ocl.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------------- 2 | # Copyright (c) 2013 Mack Stone. All rights reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | # THE SOFTWARE. 21 | # -------------------------------------------------------------------------------- 22 | 23 | """ 24 | Simple deform node use pyopencl in Maya. 25 | 26 | @author: Mack Stone 27 | """ 28 | 29 | import sys 30 | import logging 31 | 32 | import maya.OpenMaya as om 33 | import maya.OpenMayaMPx as ompx 34 | from maya import utils 35 | 36 | import numpy 37 | import pyopencl as cl 38 | 39 | 40 | # opencl code, run on GPU 41 | kernelCode = """ 42 | __kernel void ytwist(__global const float4 *pos, 43 | __global float4 *newPos, 44 | float angle, 45 | float envelope) 46 | { 47 | int gid = get_global_id(0); 48 | 49 | newPos[gid].xyzw = pos[gid].xyzw; 50 | 51 | float ff = angle * pos[gid].y * envelope; 52 | if(ff != 0.0f) 53 | { 54 | float cct = cos(ff); 55 | float cst = sin(ff); 56 | newPos[gid].x = pos[gid].x * cct - pos[gid].z * cst; 57 | newPos[gid].z = pos[gid].x * cst + pos[gid].z * cct; 58 | } 59 | } 60 | """ 61 | 62 | class YTwistNode(ompx.MPxDeformerNode): 63 | 64 | NAME = "yTwistNode" 65 | ID = om.MTypeId(0x8702) 66 | 67 | angle = om.MObject() 68 | 69 | def __init__(self): 70 | ompx.MPxDeformerNode.__init__(self) 71 | 72 | # create context 73 | self._ctx = cl.create_some_context() 74 | # command queue 75 | self._queue = cl.CommandQueue(self._ctx) 76 | # create and build GPU program 77 | self._program = cl.Program(self._ctx, kernelCode).build() 78 | 79 | # setup logger 80 | formatter = logging.Formatter("%(asctime)s - %(message)s") 81 | utils._guiLogHandler.setFormatter(formatter) 82 | 83 | def deform(self, dataBlock, geomIter, matrix, multiIndex): 84 | logging.info("start deforming") 85 | 86 | # get the angle from the datablock 87 | angleHandle = dataBlock.inputValue( self.angle ) 88 | angleValue = angleHandle.asDouble() 89 | 90 | # get the envelope 91 | envelope = OpenMayaMPx.cvar.MPxDeformerNode_envelope 92 | envelopeHandle = dataBlock.inputValue( envelope ) 93 | envelopeValue = envelopeHandle.asFloat() 94 | 95 | # get all position data 96 | logging.info("get all position data") 97 | pos = numpy.zeros((geomIter.count(), 4), dtype=numpy.float32) 98 | while not geomIter.isDone(): 99 | point = geomIter.position() 100 | index = geomIter.index() 101 | 102 | pos[index, 0] = point.x 103 | pos[index, 1] = point.y 104 | pos[index, 2] = point.z 105 | pos[index, 3] = point.w 106 | geomIter.next() 107 | 108 | logging.info("start copy data to GPU") 109 | memf = cl.mem_flags 110 | # create buffer from pos 111 | posBuf = cl.Buffer(self._ctx, memf.READ_ONLY | memf.COPY_HOST_PTR, hostbuf=pos) 112 | # create write buffer 113 | outBuf = cl.Buffer(self._ctx, memf.WRITE_ONLY, pos.nbytes) 114 | 115 | # run GPU Program 116 | logging.info("run GPU Program") 117 | self._program.ytwist(self._queue, pos.shape, None, posBuf, outBuf, 118 | numpy.float32(angleValue), numpy.float32(envelopeValue)) 119 | logging.info("end GPU Program") 120 | 121 | # copy data back to memory 122 | newPos = numpy.zeros_like(pos) 123 | cl.enqueue_copy(self._queue, newPos, outBuf).wait() 124 | 125 | # set positions 126 | logging.info("set all position") 127 | geomIter.reset() 128 | while not geomIter.isDone(): 129 | point = geomIter.position() 130 | index = geomIter.index() 131 | 132 | point.x = float(newPos[index, 0]) 133 | point.y = float(newPos[index, 1]) 134 | point.z = float(newPos[index, 2]) 135 | geomIter.next() 136 | 137 | logging.info("end deform") 138 | 139 | @staticmethod 140 | def creator(): 141 | return ompx.asMPxPtr(YTwistNode()) 142 | 143 | @staticmethod 144 | def initialize(): 145 | # angle 146 | nAttr = om.MFnNumericAttribute() 147 | YTwistNode.angle = nAttr.create("angle", "fa", om.MFnNumericData.kDouble, 0.0) 148 | nAttr.setKeyable(1) 149 | 150 | # add attribute 151 | YTwistNode.addAttribute(YTwistNode.angle) 152 | outputGeom = ompx.cvar.MPxDeformerNode_outputGeom 153 | YTwistNode.attributeAffects(YTwistNode.angle, outputGeom) 154 | 155 | # initialize the script plug-in 156 | def initializePlugin(mobject): 157 | mplugin = ompx.MFnPlugin(mobject) 158 | try: 159 | mplugin.registerNode(YTwistNode.NAME, YTwistNode.ID, YTwistNode.creator, 160 | YTwistNode.initialize, ompx.MPxNode.kDeformerNode ) 161 | except: 162 | sys.stderr.write("Failed to register node: %s\n" % YTwistNode.NAME) 163 | 164 | # uninitialize the script plug-in 165 | def uninitializePlugin(mobject): 166 | mplugin = ompx.MFnPlugin(mobject) 167 | try: 168 | mplugin.deregisterNode(YTwistNode.ID) 169 | except: 170 | sys.stderr.write("Failed to unregister node: %s\n" % YTwistNode.NAME ) 171 | -------------------------------------------------------------------------------- /shaders/reflectionMap.sfx: -------------------------------------------------------------------------------- 1 | SFX_WIN 2 | Version=26 3 | GroupVersion=-1.0 4 | Advanced=0 5 | HelpID=0 6 | NumberOfNodes=25 7 | #NT=20008 0 8 | PC=2 9 | posx=1 v=2003 -344.157 10 | posy=1 v=2003 105.677 11 | group=-1 12 | ISC=2 13 | SVT=5001 3003 1 0 0 14 | SVT=5001 2003 3 0 0 15 | OSC=1 16 | SVT=5001 5009 2 17 | CC=1 18 | C=0 0 2 2 4 5 0 19 | CPC=0 20 | #NT=20002 0 21 | PC=3 22 | posx=1 v=2003 66.6801 23 | posy=1 v=2003 12.5409 24 | techniquename=1 v=5000 sample 25 | group=-1 26 | ISC=1 27 | SVT=5001 5004 1 0 0 28 | OSC=1 29 | SVT=5001 5003 2 30 | CC=1 31 | C=1 0 2 3 2 2 0 32 | CPC=0 33 | #NT=20003 0 34 | PC=2 35 | posx=1 v=2003 -136.578 36 | posy=1 v=2003 -53.9801 37 | group=-1 38 | ISC=7 39 | SVT=5001 5014 1 0 0 40 | SVT=5001 5005 2 0 0 41 | SVT=5001 5007 3 0 0 42 | SVT=5001 5008 4 0 0 43 | SVT=5001 5009 5 0 0 44 | SVT=5001 5011 7 0 0 45 | SVT=5001 5011 8 0 0 46 | OSC=1 47 | SVT=5001 5004 6 48 | CC=1 49 | C=2 0 6 1 0 1 0 50 | CPC=0 51 | #NT=20001 0 52 | PC=4 53 | posx=1 v=2003 280.38 54 | posy=1 v=2003 -3.74363 55 | config=2 e=0 v=5012 1 56 | saveshadertodisk=2 e=0 v=5015 57 | group=-1 58 | ISC=3 59 | SVT=2002 2002 3 0 0 60 | SVT=5001 5016 1 0 0 61 | SVT=5001 5003 2 0 0 62 | OSC=0 63 | #NT=20004 0 64 | PC=2 65 | posx=1 v=2003 -437.518 66 | posy=1 v=2003 -131.667 67 | group=-1 68 | ISC=3 69 | SVT=5001 3003 1 0 0 70 | SVT=5001 1002 4 0 0 71 | SVT=5001 3003 2 0 0 72 | OSC=1 73 | SVT=5001 5005 3 74 | CC=1 75 | C=4 0 3 2 1 2 0 76 | CPC=0 77 | #NT=20012 0 78 | PC=2 79 | posx=1 v=2003 -1035.82 80 | posy=1 v=2003 -249.786 81 | group=-1 82 | ISC=0 83 | OSC=2 84 | SVT=5001 3003 1 85 | CC=1 86 | C=5 0 1 4 0 1 0 87 | CPC=0 88 | SVT=5001 3002 2 89 | CC=0 90 | #NT=20012 0 91 | PC=2 92 | posx=1 v=2003 -1055.0 93 | posy=1 v=2003 -122.675 94 | group=-1 95 | ISC=0 96 | OSC=2 97 | SVT=5001 3003 1 98 | CC=1 99 | C=6 0 1 8 0 1 0 100 | CPC=0 101 | SVT=5001 3002 2 102 | CC=1 103 | C=6 1 2 13 0 1 0 104 | CPC=0 105 | #NT=20081 0 106 | PC=2 107 | posx=1 v=2003 -1044.27 108 | posy=1 v=2003 4.55731 109 | group=-1 110 | ISC=0 111 | OSC=1 112 | SVT=5001 4900 1 113 | CC=1 114 | C=7 0 1 8 1 2 0 115 | CPC=0 116 | #NT=20016 0 117 | PC=3 118 | name=1 v=5000 position 119 | posx=1 v=2003 -872.328 120 | posy=1 v=2003 -77.459 121 | group=-1 122 | ISC=2 123 | SVT=5001 3003 1 0 0 124 | SVT=5001 4900 2 0 0 125 | OSC=1 126 | SVT=5001 3003 3 127 | CC=1 128 | C=8 0 3 9 1 2 0 129 | CPC=0 130 | #NT=20015 0 131 | PC=7 132 | name=1 v=5000 position 133 | posx=1 v=2003 -686.015 134 | posy=1 v=2003 -55.352 135 | texcoordname=1 v=5000 position 136 | semantic=1 v=5000 SV_Position 137 | semantictype=1 v=5012 2 138 | tweaktexcoord=1 v=2001 1 139 | group=-1 140 | ISC=2 141 | SVT=5001 5000 1 0 0 142 | SVT=5001 3003 2 0 0 143 | OSC=1 144 | SVT=5001 3003 3 145 | CC=1 146 | C=9 0 3 4 2 2 0 147 | CPC=0 148 | #NT=20067 0 149 | PC=2 150 | posx=1 v=2003 -1502.45 151 | posy=1 v=2003 247.359 152 | group=-1 153 | ISC=0 154 | OSC=1 155 | SVT=5001 4900 1 156 | CC=1 157 | C=10 0 1 11 0 1 0 158 | CPC=0 159 | #NT=20110 0 160 | PC=2 161 | posx=1 v=2003 -1296.04 162 | posy=1 v=2003 265.239 163 | group=-1 164 | ISC=1 165 | SVT=5001 4900 1 0 0 166 | OSC=1 167 | SVT=5001 3002 2 168 | CC=1 169 | C=11 0 2 14 0 1 0 170 | CPC=0 171 | #NT=20061 0 172 | PC=2 173 | posx=1 v=2003 -1453.72 174 | posy=1 v=2003 114.371 175 | group=-1 176 | ISC=0 177 | OSC=2 178 | SVT=5001 4900 1 179 | CC=1 180 | C=12 0 1 13 1 2 0 181 | CPC=0 182 | SVT=5001 4600 2 183 | CC=0 184 | #NT=20016 0 185 | PC=3 186 | name=1 v=5000 worldPosition 187 | posx=1 v=2003 -1161.93 188 | posy=1 v=2003 124.05 189 | group=-1 190 | ISC=2 191 | SVT=5001 3002 1 0 0 192 | SVT=5001 4900 2 0 0 193 | OSC=1 194 | SVT=5001 3002 3 195 | CC=1 196 | C=13 0 3 14 1 2 0 197 | CPC=0 198 | #NT=20022 0 199 | PC=3 200 | name=1 v=5000 eyeVector 201 | posx=1 v=2003 -961.224 202 | posy=1 v=2003 159.262 203 | group=-1 204 | ISC=2 205 | SVT=5001 3002 1 0 0 206 | SVT=5001 3002 2 0 0 207 | OSC=1 208 | SVT=5001 3002 3 209 | CC=1 210 | C=14 0 3 15 1 2 0 211 | CPC=0 212 | #NT=20015 0 213 | PC=4 214 | posx=1 v=2003 -776.323 215 | posy=1 v=2003 179.146 216 | texcoordname=1 v=5000 eyeVector 217 | tweaktexcoord=1 v=2001 1 218 | group=-1 219 | ISC=2 220 | SVT=5001 5000 1 0 0 221 | SVT=5001 3002 2 0 0 222 | OSC=1 223 | SVT=5001 3002 3 224 | CC=1 225 | C=15 0 3 16 0 1 0 226 | CPC=0 227 | #NT=20057 0 228 | PC=3 229 | name=1 v=5000 reflectVector 230 | posx=1 v=2003 -599.578 231 | posy=1 v=2003 233.979 232 | group=-1 233 | ISC=2 234 | SVT=5001 3002 1 0 0 235 | SVT=5001 3002 2 0 0 236 | OSC=1 237 | SVT=5001 3002 3 238 | CC=1 239 | C=16 0 3 24 1 2 0 240 | CPC=0 241 | #NT=20014 0 242 | PC=2 243 | posx=1 v=2003 -1569.11 244 | posy=1 v=2003 357.724 245 | group=-1 246 | ISC=0 247 | OSC=2 248 | SVT=5001 3003 1 249 | CC=0 250 | SVT=5001 3002 2 251 | CC=1 252 | C=17 1 2 20 0 1 0 253 | CPC=0 254 | #NT=20015 0 255 | PC=5 256 | posx=1 v=2003 -1178.86 257 | posy=1 v=2003 379.404 258 | texcoordname=1 v=5000 normal 259 | semantic=1 v=5000 NORMAL 260 | semantictype=1 v=5012 3 261 | group=-1 262 | ISC=2 263 | SVT=5001 5000 1 0 0 264 | SVT=5001 3002 2 0 0 265 | OSC=1 266 | SVT=5001 3002 3 267 | CC=1 268 | C=18 0 3 16 1 2 0 269 | CPC=0 270 | #NT=20064 0 271 | PC=2 272 | posx=1 v=2003 -1574.53 273 | posy=1 v=2003 475.61 274 | group=-1 275 | ISC=0 276 | OSC=1 277 | SVT=5001 4900 1 278 | CC=1 279 | C=19 0 1 20 1 2 0 280 | CPC=0 281 | #NT=20016 0 282 | PC=2 283 | posx=1 v=2003 -1379.4 284 | posy=1 v=2003 395.664 285 | group=-1 286 | ISC=2 287 | SVT=5001 3002 1 0 0 288 | SVT=5001 4900 2 0 0 289 | OSC=1 290 | SVT=5001 3002 3 291 | CC=1 292 | C=20 0 3 18 1 2 0 293 | CPC=0 294 | #NT=20159 0 295 | PC=3 296 | posx=1 v=2003 -1108.5 297 | posy=1 v=2003 568.575 298 | type=1 v=5012 3 299 | group=-1 300 | ISC=0 301 | OSC=1 302 | SVT=2002 2002 1 303 | CC=2 304 | C=21 0 1 22 2 4 0 305 | CPC=0 306 | C=21 0 1 23 1 2 0 307 | CPC=0 308 | #NT=20028 0 309 | PC=5 310 | name=1 v=5000 reflectionTexture 311 | posx=1 v=2003 -896.514 312 | posy=1 v=2003 526.796 313 | defineinheader=2 e=0 v=2001 1 314 | texturenodename=2 e=1 v=5000 reflectionTex 315 | group=-1 316 | ISC=3 317 | SVT=2002 2002 1 0 0 318 | SVT=2002 2002 3 0 0 319 | SVT=2002 2002 4 0 0 320 | OSC=1 321 | SVT=5001 5011 2 322 | CC=2 323 | C=22 0 2 23 0 3 0 324 | CPC=0 325 | C=22 0 2 24 0 1 0 326 | CPC=0 327 | #NT=20092 0 328 | PC=2 329 | posx=1 v=2003 -695.259 330 | posy=1 v=2003 527.771 331 | group=-1 332 | ISC=2 333 | SVT=5001 5011 3 0 0 334 | SVT=2002 2002 2 0 0 335 | OSC=1 336 | SVT=5001 5013 1 337 | CC=1 338 | C=23 0 1 24 3 4 0 339 | CPC=0 340 | #NT=20029 0 341 | PC=2 342 | posx=1 v=2003 -399.787 343 | posy=1 v=2003 267.717 344 | group=-1 345 | ISC=7 346 | SVT=5001 5011 1 0 0 347 | SVT=5001 3002 2 0 0 348 | SVT=5001 2003 3 0 0 349 | SVT=5001 5013 4 0 0 350 | SVT=5001 2002 11 0 0 351 | SVT=5001 2002 12 0 0 352 | SVT=2002 2002 13 0 0 353 | OSC=6 354 | SVT=5001 3003 5 355 | CC=1 356 | C=24 0 5 0 0 1 0 357 | CPC=0 358 | SVT=5001 3002 6 359 | CC=0 360 | SVT=5001 2003 7 361 | CC=0 362 | SVT=5001 2003 8 363 | CC=0 364 | SVT=5001 2003 9 365 | CC=0 366 | SVT=5001 2003 10 367 | CC=0 368 | -------------------------------------------------------------------------------- /uvOverlap.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # The MIT License (MIT) 4 | # 5 | # Copyright (c) 2014 Mack Stone 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | # this software and associated documentation files (the "Software"), to deal in 9 | # the Software without restriction, including without limitation the rights to 10 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | # the Software, and to permit persons to whom the Software is furnished to do so, 12 | # subject to the following conditions: 13 | # 14 | # The above copyright notice and this permission notice shall be included in all 15 | # copies or substantial portions of the Software. 16 | # 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | 25 | # this script was base on MayaInstallDir/devkit/plug-ins/peltOverlapCmd/peltOverlapCmd.cpp 26 | # using python API 2.0 27 | 28 | # how to use: 29 | # 30 | # from maya import cmds 31 | # 32 | # pcube = cmds.polyCube() 33 | # cmds.polyAutoProjection() 34 | # cmds.polyEditUV('%s.map[12]' % pcube[0], u=-0.057, v=-0.109) 35 | # overlapFaces = getOverlapUVFaces(pcube[0]) 36 | # cmds.select(overlapFaces, r=1) 37 | 38 | import math 39 | import maya.api.OpenMaya as om 40 | 41 | 42 | def createBoundingCircle(meshfn): 43 | """Parameter: meshfn - MFnMesh 44 | Represent a face by a center and radius, i.e. 45 | center = [center1u, center1v, center2u, center2v, ... ] 46 | radius = [radius1, radius2, ... ] 47 | 48 | return (center, radius)""" 49 | center = [] 50 | radius = [] 51 | for i in xrange(meshfn.numPolygons): 52 | # get uvs from face 53 | uarray = [] 54 | varray = [] 55 | for j in range(len(meshfn.getPolygonVertices(i))): 56 | uv = meshfn.getPolygonUV(i, j) 57 | uarray.append(uv[0]) 58 | varray.append(uv[1]) 59 | 60 | # loop through all vertices to construct edges/rays 61 | cu = .0 62 | cv = .0 63 | for j in range(len(uarray)): 64 | cu += uarray[j] 65 | cv += varray[j] 66 | 67 | cu /= len(uarray) 68 | cv /= len(varray) 69 | rsqr = .0 70 | for j in range(len(varray)): 71 | du = uarray[j] - cu 72 | dv = varray[j] - cv 73 | dsqr = du * du + dv * dv 74 | rsqr = dsqr if dsqr > rsqr else rsqr 75 | 76 | center.append(cu) 77 | center.append(cv) 78 | radius.append(math.sqrt(rsqr)) 79 | 80 | return center, radius 81 | 82 | def createRayGivenFace(meshfn, faceId): 83 | """Represent a face by a series of edges(rays), i.e. 84 | orig = [orig1u, orig1v, orig2u, orig2v, ... ] 85 | vec = [vec1u, vec1v, vec2u, vec2v, ... ] 86 | 87 | return false if no valid uv's. 88 | return (true, orig, vec) or (false, None, None)""" 89 | orig = [] 90 | vec = [] 91 | # get uvs 92 | uarray = [] 93 | varray = [] 94 | for i in range(len(meshfn.getPolygonVertices(faceId))): 95 | uv = meshfn.getPolygonUV(faceId, i) 96 | uarray.append(uv[0]) 97 | varray.append(uv[1]) 98 | 99 | if len(uarray) == 0 or len(varray) == 0: 100 | return (False, None, None) 101 | 102 | # loop throught all vertices to construct edges/rays 103 | u = uarray[-1] 104 | v = varray[-1] 105 | for i in xrange(len(uarray)): 106 | orig.append(uarray[i]) 107 | orig.append(varray[i]) 108 | vec.append(u - uarray[i]) 109 | vec.append(v - varray[i]) 110 | u = uarray[i] 111 | v = varray[i] 112 | 113 | return (True, orig, vec) 114 | 115 | def area(orig): 116 | sum = .0 117 | num = len(orig)/2 118 | for i in xrange(num): 119 | idx = 2 * i 120 | idy = (i + 1) % num 121 | idy = 2 * idy + 1 122 | idy2 = (i + num - 1) % num 123 | idy2 = 2 * idy2 + 1 124 | sum += orig[idx] * (orig[idy] - orig[idy2]) 125 | 126 | return math.fabs(sum) * .5 127 | 128 | def checkCrossingEdges(face1Orig, face1Vec, face2Orig, face2Vec): 129 | """Check if there are crossing edges between two faces. Return true 130 | if there are crossing edges and false otherwise. A face is represented 131 | by a series of edges(rays), i.e. 132 | faceOrig[] = [orig1u, orig1v, orig2u, orig2v, ... ] 133 | faceVec[] = [vec1u, vec1v, vec2u, vec2v, ... ]""" 134 | face1Size = len(face1Orig) 135 | face2Size = len(face2Orig) 136 | for i in xrange(0, face1Size, 2): 137 | o1x = face1Orig[i] 138 | o1y = face1Orig[i+1] 139 | v1x = face1Vec[i] 140 | v1y = face1Vec[i+1] 141 | n1x = v1y 142 | n1y = -v1x 143 | for j in xrange(0, face2Size, 2): 144 | # Given ray1(O1, V1) and ray2(O2, V2) 145 | # Normal of ray1 is (V1.y, V1.x) 146 | o2x = face2Orig[j] 147 | o2y = face2Orig[j+1] 148 | v2x = face2Vec[j] 149 | v2y = face2Vec[j+1] 150 | n2x = v2y 151 | n2y = -v2x 152 | 153 | # Find t for ray2 154 | # t = [(o1x-o2x)n1x + (o1y-o2y)n1y] / (v2x * n1x + v2y * n1y) 155 | denum = v2x * n1x + v2y * n1y 156 | # Edges are parallel if denum is close to 0. 157 | if math.fabs(denum) < 0.000001: continue 158 | t2 = ((o1x-o2x)* n1x + (o1y-o2y) * n1y) / denum 159 | if (t2 < 0.00001 or t2 > 0.99999): continue 160 | 161 | # Find t for ray1 162 | # t = [(o2x-o1x)n2x + (o2y-o1y)n2y] / (v1x * n2x + v1y * n2y) 163 | denum = v1x * n2x + v1y * n2y 164 | # Edges are parallel if denum is close to 0. 165 | if math.fabs(denum) < 0.000001: continue 166 | t1 = ((o2x-o1x)* n2x + (o2y-o1y) * n2y) / denum 167 | 168 | # Edges intersect 169 | if (t1 > 0.00001 and t1 < 0.99999): return 1 170 | 171 | return 0 172 | 173 | def getOverlapUVFaces(meshName): 174 | """Return overlapping faces""" 175 | faces = [] 176 | # find polygon mesh node 177 | selList = om.MSelectionList() 178 | selList.add(meshName) 179 | mesh = selList.getDependNode(0) 180 | if mesh.apiType() == om.MFn.kTransform: 181 | dagPath = selList.getDagPath(0) 182 | dagFn = om.MFnDagNode(dagPath) 183 | child = dagFn.child(0) 184 | if child.apiType() != om.MFn.kMesh: 185 | raise Exception("Can't find polygon mesh") 186 | mesh = child 187 | meshfn = om.MFnMesh(mesh) 188 | 189 | center, radius = createBoundingCircle(meshfn) 190 | for i in xrange(meshfn.numPolygons): 191 | rayb1, face1Orig, face1Vec = createRayGivenFace(meshfn, i) 192 | if not rayb1: continue 193 | cui = center[2*i] 194 | cvi = center[2*i+1] 195 | ri = radius[i] 196 | # Exclude the degenerate face 197 | # if(area(face1Orig) < 0.000001) continue; 198 | # Loop through face j where j != i 199 | for j in range(i+1, meshfn.numPolygons): 200 | cuj = center[2*j] 201 | cvj = center[2*j+1] 202 | rj = radius[j] 203 | du = cuj - cui 204 | dv = cvj - cvi 205 | dsqr = du * du + dv * dv 206 | # Quick rejection if bounding circles don't overlap 207 | if (dsqr >= (ri + rj) * (ri + rj)): continue 208 | 209 | rayb2, face2Orig, face2Vec = createRayGivenFace(meshfn, j) 210 | if not rayb2: continue 211 | # Exclude the degenerate face 212 | # if(area(face2Orig) < 0.000001): continue; 213 | if checkCrossingEdges(face1Orig, face1Vec, face2Orig, face2Vec): 214 | face1 = '%s.f[%d]' % (meshfn.name(), i) 215 | face2 = '%s.f[%d]' % (meshfn.name(), j) 216 | if face1 not in faces: 217 | faces.append(face1) 218 | if face2 not in faces: 219 | faces.append(face2) 220 | return faces 221 | -------------------------------------------------------------------------------- /shaders/lambert.sfx: -------------------------------------------------------------------------------- 1 | SFX_WIN 2 | Version=26 3 | GroupVersion=-1.0 4 | Advanced=0 5 | HelpID=0 6 | NumberOfNodes=29 7 | #NT=20011 0 8 | PC=5 9 | name=1 v=5000 ambientColor 10 | posx=1 v=2003 9.19464 11 | posy=1 v=2003 310.451 12 | color=2 e=0 v=3003 0.317464,0.317464,0.317464,1.0 13 | defineinheader=2 e=0 v=2001 1 14 | group=-1 15 | ISC=0 16 | OSC=6 17 | SVT=5001 3003 1 18 | CC=0 19 | SVT=5001 3002 2 20 | CC=1 21 | C=0 1 2 10 1 2 0 22 | CPC=0 23 | SVT=5001 2003 3 24 | CC=0 25 | SVT=5001 2003 4 26 | CC=0 27 | SVT=5001 2003 5 28 | CC=0 29 | SVT=5001 2003 6 30 | CC=0 31 | #NT=20011 0 32 | PC=5 33 | name=1 v=5000 diffuseColor 34 | posx=1 v=2003 236.341 35 | posy=1 v=2003 437.745 36 | color=2 e=0 v=3003 1.0,1.0,1.0,1.0 37 | defineinheader=2 e=0 v=2001 1 38 | group=-1 39 | ISC=0 40 | OSC=6 41 | SVT=5001 3003 1 42 | CC=0 43 | SVT=5001 3002 2 44 | CC=1 45 | C=1 1 2 11 1 2 0 46 | CPC=0 47 | SVT=5001 2003 3 48 | CC=0 49 | SVT=5001 2003 4 50 | CC=0 51 | SVT=5001 2003 5 52 | CC=0 53 | SVT=5001 2003 6 54 | CC=0 55 | #NT=20152 0 56 | PC=3 57 | posx=1 v=2003 -1120.1 58 | posy=1 v=2003 39.9262 59 | exposesetting=1 v=2001 1 60 | group=-1 61 | ISC=0 62 | OSC=1 63 | SVT=5001 5017 1 64 | CC=1 65 | C=2 0 1 3 0 1 0 66 | CPC=0 67 | #NT=20153 0 68 | PC=2 69 | posx=1 v=2003 -940.04 70 | posy=1 v=2003 31.7645 71 | group=-1 72 | ISC=1 73 | SVT=5001 5017 1 0 0 74 | OSC=1 75 | SVT=2002 2002 2 76 | CC=1 77 | C=3 0 2 21 0 1 0 78 | CPC=0 79 | #NT=20008 0 80 | PC=2 81 | posx=1 v=2003 797.873 82 | posy=1 v=2003 144.947 83 | group=-1 84 | ISC=2 85 | SVT=5001 3003 1 0 0 86 | SVT=5001 2003 3 0 0 87 | OSC=1 88 | SVT=5001 5009 2 89 | CC=1 90 | C=4 0 2 6 4 5 0 91 | CPC=0 92 | #NT=20002 0 93 | PC=3 94 | posx=1 v=2003 1164.43 95 | posy=1 v=2003 16.5409 96 | techniquename=1 v=5000 sample 97 | group=-1 98 | ISC=1 99 | SVT=5001 5004 1 0 0 100 | OSC=1 101 | SVT=5001 5003 2 102 | CC=1 103 | C=5 0 2 15 2 2 0 104 | CPC=0 105 | #NT=20003 0 106 | PC=2 107 | posx=1 v=2003 961.172 108 | posy=1 v=2003 -49.9801 109 | group=-1 110 | ISC=7 111 | SVT=5001 5014 1 0 0 112 | SVT=5001 5005 2 0 0 113 | SVT=5001 5007 3 0 0 114 | SVT=5001 5008 4 0 0 115 | SVT=5001 5009 5 0 0 116 | SVT=5001 5011 7 0 0 117 | SVT=5001 5011 8 0 0 118 | OSC=1 119 | SVT=5001 5004 6 120 | CC=1 121 | C=6 0 6 5 0 1 0 122 | CPC=0 123 | #NT=20021 0 124 | PC=3 125 | name=1 v=5000 worldNormal 126 | posx=1 v=2003 -560.262 127 | posy=1 v=2003 291.808 128 | group=-1 129 | ISC=1 130 | SVT=5001 3002 1 0 0 131 | OSC=1 132 | SVT=5001 3002 2 133 | CC=1 134 | C=7 0 2 8 1 2 0 135 | CPC=0 136 | #NT=20018 0 137 | PC=2 138 | posx=1 v=2003 -149.099 139 | posy=1 v=2003 152.985 140 | group=-1 141 | ISC=2 142 | SVT=5001 3002 1 0 0 143 | SVT=5001 3002 2 0 0 144 | OSC=1 145 | SVT=5001 2003 3 146 | CC=1 147 | C=8 0 3 9 0 1 0 148 | CPC=0 149 | #NT=20023 0 150 | PC=3 151 | name=1 v=5000 lambert 152 | posx=1 v=2003 63.5021 153 | posy=1 v=2003 171.577 154 | group=-1 155 | ISC=1 156 | SVT=5001 2003 1 0 0 157 | OSC=1 158 | SVT=5001 2003 2 159 | CC=1 160 | C=9 0 2 10 0 1 0 161 | CPC=0 162 | #NT=20026 0 163 | PC=2 164 | posx=1 v=2003 247.093 165 | posy=1 v=2003 252.166 166 | group=-1 167 | ISC=2 168 | SVT=5001 2003 1 0 0 169 | SVT=5001 3002 2 0 0 170 | OSC=1 171 | SVT=5001 3002 3 172 | CC=1 173 | C=10 0 3 11 0 1 0 174 | CPC=0 175 | #NT=20016 0 176 | PC=3 177 | name=1 v=5000 color 178 | posx=1 v=2003 423.288 179 | posy=1 v=2003 339.726 180 | group=-1 181 | ISC=2 182 | SVT=5001 3002 1 0 0 183 | SVT=5001 3002 2 0 0 184 | OSC=1 185 | SVT=5001 3002 3 186 | CC=1 187 | C=11 0 3 12 4 5 0 188 | CPC=0 189 | #NT=20020 0 190 | PC=3 191 | name=1 v=5000 outColor 192 | posx=1 v=2003 598.63 193 | posy=1 v=2003 284.931 194 | group=-1 195 | ISC=6 196 | SVT=5001 2003 1 0 0 197 | SVT=5001 2003 2 0 0 198 | SVT=5001 3001 3 0 0 199 | SVT=5001 2003 4 0 0 200 | SVT=5001 3002 5 0 0 201 | SVT=5001 2003 6 0 0 202 | OSC=3 203 | SVT=5001 3001 7 204 | CC=0 205 | SVT=5001 3002 8 206 | CC=0 207 | SVT=5001 3003 9 208 | CC=1 209 | C=12 2 9 4 0 1 0 210 | CPC=0 211 | #NT=20017 0 212 | PC=2 213 | posx=1 v=2003 408.219 214 | posy=1 v=2003 524.657 215 | group=-1 216 | ISC=0 217 | OSC=1 218 | SVT=5001 2003 1 219 | CC=1 220 | C=13 0 1 12 5 6 0 221 | CPC=0 222 | #NT=20112 0 223 | PC=2 224 | posx=1 v=2003 -556.482 225 | posy=1 v=2003 99.5242 226 | group=-1 227 | ISC=1 228 | SVT=5001 3002 1 0 0 229 | OSC=1 230 | SVT=5001 3002 2 231 | CC=1 232 | C=14 0 2 16 0 1 0 233 | CPC=0 234 | #NT=20001 0 235 | PC=4 236 | posx=1 v=2003 1376.31 237 | posy=1 v=2003 1.79483 238 | config=2 e=0 v=5012 1 239 | saveshadertodisk=2 e=0 v=5015 240 | group=-1 241 | ISC=3 242 | SVT=2002 2002 3 0 0 243 | SVT=5001 5016 1 0 0 244 | SVT=5001 5003 2 0 0 245 | OSC=0 246 | #NT=20021 0 247 | PC=3 248 | name=1 v=5000 lightDir 249 | posx=1 v=2003 -345.777 250 | posy=1 v=2003 120.241 251 | group=-1 252 | ISC=1 253 | SVT=5001 3002 1 0 0 254 | OSC=1 255 | SVT=5001 3002 2 256 | CC=1 257 | C=16 0 2 8 0 1 0 258 | CPC=0 259 | #NT=20014 0 260 | PC=2 261 | posx=1 v=2003 -1147.54 262 | posy=1 v=2003 274.591 263 | group=-1 264 | ISC=0 265 | OSC=2 266 | SVT=5001 3003 1 267 | CC=1 268 | C=17 0 1 28 1 2 0 269 | CPC=0 270 | SVT=5001 3002 2 271 | CC=1 272 | C=17 1 2 19 0 1 0 273 | CPC=0 274 | #NT=20064 0 275 | PC=2 276 | posx=1 v=2003 -1139.35 277 | posy=1 v=2003 430.329 278 | group=-1 279 | ISC=0 280 | OSC=1 281 | SVT=5001 4900 1 282 | CC=1 283 | C=18 0 1 19 1 2 0 284 | CPC=0 285 | #NT=20016 0 286 | PC=2 287 | posx=1 v=2003 -945.039 288 | posy=1 v=2003 326.066 289 | group=-1 290 | ISC=2 291 | SVT=5001 3002 1 0 0 292 | SVT=5001 4900 2 0 0 293 | OSC=1 294 | SVT=5001 3002 3 295 | CC=1 296 | C=19 0 3 20 1 2 0 297 | CPC=0 298 | #NT=20015 0 299 | PC=6 300 | name=1 v=5000 worldNormal 301 | posx=1 v=2003 -758.49 302 | posy=1 v=2003 343.766 303 | texcoordname=1 v=5000 worldNormal 304 | tweaktexcoord=1 v=2001 1 305 | stage=1 v=5012 3 306 | group=-1 307 | ISC=2 308 | SVT=5001 5000 1 0 0 309 | SVT=5001 3002 2 0 0 310 | OSC=1 311 | SVT=5001 3002 3 312 | CC=1 313 | C=20 0 3 7 0 1 0 314 | CPC=0 315 | #NT=20130 0 316 | PC=3 317 | posx=1 v=2003 -758.038 318 | posy=1 v=2003 54.338 319 | lightindex=2 e=0 v=2002 1 320 | group=-1 321 | ISC=1 322 | SVT=2002 2002 1 0 0 323 | OSC=1 324 | SVT=5001 3002 2 325 | CC=1 326 | C=21 0 2 14 0 1 0 327 | CPC=0 328 | #NT=20004 0 329 | PC=2 330 | posx=1 v=2003 28.5651 331 | posy=1 v=2003 -184.334 332 | group=-1 333 | ISC=3 334 | SVT=5001 3003 1 0 0 335 | SVT=5001 1002 4 0 0 336 | SVT=5001 3003 2 0 0 337 | OSC=1 338 | SVT=5001 5005 3 339 | CC=1 340 | C=22 0 3 6 1 2 0 341 | CPC=0 342 | #NT=20012 0 343 | PC=2 344 | posx=1 v=2003 -520.135 345 | posy=1 v=2003 -307.629 346 | group=-1 347 | ISC=0 348 | OSC=2 349 | SVT=5001 3003 1 350 | CC=1 351 | C=23 0 1 22 0 1 0 352 | CPC=0 353 | SVT=5001 3002 2 354 | CC=0 355 | #NT=20012 0 356 | PC=2 357 | posx=1 v=2003 -567.878 358 | posy=1 v=2003 -161.534 359 | group=-1 360 | ISC=0 361 | OSC=2 362 | SVT=5001 3003 1 363 | CC=1 364 | C=24 0 1 26 0 1 0 365 | CPC=0 366 | SVT=5001 3002 2 367 | CC=0 368 | #NT=20081 0 369 | PC=2 370 | posx=1 v=2003 -568.182 371 | posy=1 v=2003 -46.4427 372 | group=-1 373 | ISC=0 374 | OSC=1 375 | SVT=5001 4900 1 376 | CC=1 377 | C=25 0 1 26 1 2 0 378 | CPC=0 379 | #NT=20016 0 380 | PC=3 381 | name=1 v=5000 position 382 | posx=1 v=2003 -396.245 383 | posy=1 v=2003 -128.459 384 | group=-1 385 | ISC=2 386 | SVT=5001 3003 1 0 0 387 | SVT=5001 4900 2 0 0 388 | OSC=1 389 | SVT=5001 3003 3 390 | CC=1 391 | C=26 0 3 27 1 2 0 392 | CPC=0 393 | #NT=20015 0 394 | PC=6 395 | name=1 v=5000 position_abc 396 | posx=1 v=2003 -209.931 397 | posy=1 v=2003 -106.352 398 | semantic=1 v=5000 SV_Position 399 | semantictype=1 v=5012 2 400 | tweaktexcoord=1 v=2001 1 401 | group=-1 402 | ISC=2 403 | SVT=5001 5000 1 0 0 404 | SVT=5001 3003 2 0 0 405 | OSC=1 406 | SVT=5001 3003 3 407 | CC=1 408 | C=27 0 3 22 2 2 0 409 | CPC=0 410 | #NT=20015 0 411 | PC=5 412 | name=1 v=5000 normal 413 | posx=1 v=2003 -948.617 414 | posy=1 v=2003 173.913 415 | semantic=1 v=5000 NORMAL 416 | semantictype=1 v=5012 3 417 | group=-1 418 | ISC=2 419 | SVT=5001 5000 1 0 0 420 | SVT=5001 3003 2 0 0 421 | OSC=1 422 | SVT=5001 3003 3 423 | CC=0 424 | -------------------------------------------------------------------------------- /intersectCmd.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | import maya.api.OpenMaya as om 4 | import maya.OpenMaya as oom 5 | 6 | from maya import cmds 7 | 8 | class RayArrow(object): 9 | 10 | def __init__(self): 11 | self.botHandle = None 12 | self.topHandle = None 13 | self.__arrowMesh = None 14 | 15 | self.create() 16 | self.moveToGroup() 17 | 18 | def create(self): 19 | handle = cmds.polyCylinder(sc=0, r=0.05, sa=5) 20 | arrowCone = cmds.polyCone(r=.25, h=.5, sa=5) 21 | cmds.move(0, 1.2, 0) 22 | 23 | arrow = cmds.polyUnite(handle[0], arrowCone[0]) 24 | arrow = cmds.rename(arrow[0], 'arrowMesh#') 25 | self.__arrowMesh = arrow 26 | 27 | cmds.DeleteHistory() 28 | 29 | topVertices = [] 30 | botVertices = [] 31 | selList = om.MSelectionList() 32 | selList.add(arrow) 33 | 34 | # meshFn = om.MFnMesh(selList.getDagPath(0)) 35 | # for i in range(meshFn.numVertices): 36 | # point = meshFn.getPoint(i, om.MSpace.kWorld) 37 | 38 | vertIt = om.MItMeshVertex(selList.getDagPath(0)) 39 | while not vertIt.isDone(): 40 | pos = vertIt.position(om.MSpace.kWorld) 41 | if pos.y > 0: 42 | topVertices.append(vertIt.index()) 43 | else: 44 | botVertices.append(vertIt.index()) 45 | vertIt.next() 46 | 47 | topVert = ['{}.vtx[{}]'.format(arrow, id) for id in topVertices] 48 | botVert = ['{}.vtx[{}]'.format(arrow, id) for id in botVertices] 49 | self.topHandle = cmds.cluster(topVert)[1] 50 | self.botHandle = cmds.cluster(botVert)[1] 51 | 52 | self.topHandle = cmds.rename(self.topHandle, 'arrowTopHandle#') 53 | self.botHandle = cmds.rename(self.botHandle, 'arrowbotHandle#') 54 | 55 | 56 | def orient(self): 57 | constraint = cmds.aimConstraint(self.botHandle, self.topHandle, 58 | aimVector=[0, -1, 0], 59 | upVector=[1, 0, 0]) 60 | cmds.delete(constraint) 61 | constraint = cmds.aimConstraint(self.topHandle, self.botHandle, 62 | aimVector=[0, 1, 0], 63 | upVector=[1, 0, 0]) 64 | cmds.delete(constraint) 65 | 66 | def moveToGroup(self): 67 | grpName = 'arrows' 68 | if not cmds.objExists(grpName): 69 | grp = cmds.group(em=1, n=grpName) 70 | else: 71 | grp = grpName 72 | 73 | cmds.parent(self.topHandle, grp) 74 | cmds.parent(self.botHandle, grp) 75 | cmds.parent(self.__arrowMesh, grp) 76 | 77 | 78 | def getLightDirection(name): 79 | selList = oom.MSelectionList() 80 | selList.add(name) 81 | 82 | lightDagPath = oom.MDagPath() 83 | selList.getDagPath(0, lightDagPath) 84 | 85 | lightFn = oom.MFnSpotLight(lightDagPath) 86 | 87 | rayDir = lightFn.lightDirection(0, oom.MSpace.kWorld) 88 | 89 | return om.MFloatVector(rayDir) 90 | 91 | def intersect(): 92 | activeSelList = om.MGlobal.getActiveSelectionList() 93 | selListIt = om.MItSelectionList(activeSelList) 94 | 95 | sportLightTransformNode = None 96 | # spotLightDP = None 97 | # meshTransformNode = None 98 | meshDP = None 99 | 100 | while not selListIt.isDone(): 101 | nodeDP = selListIt.getDagPath() 102 | if nodeDP.apiType() == om.MFn.kTransform: 103 | dagNodeFn = om.MFnDagNode(nodeDP) 104 | nodeDP = dagNodeFn.child(0) 105 | 106 | if nodeDP.apiType() == om.MFn.kSpotLight: 107 | # spotLightDP = nodeDP 108 | sportLightTransformNode = dagNodeFn 109 | elif nodeDP.apiType() == om.MFn.kMesh: 110 | meshDP = nodeDP 111 | # meshTransformNode = dagNodeFn 112 | selListIt.next() 113 | 114 | tx = sportLightTransformNode.findPlug('tx', False).asFloat() 115 | ty = sportLightTransformNode.findPlug('ty', False).asFloat() 116 | tz = sportLightTransformNode.findPlug('tz', False).asFloat() 117 | 118 | fpSource = om.MFloatPoint(tx, ty, tz) 119 | fvRayDir = getLightDirection(sportLightTransformNode.name()) 120 | 121 | meshFn = om.MFnMesh(om.MDagPath.getAPathTo(meshDP)) 122 | mmAccelParams = meshFn.autoUniformGridParams() 123 | hitPoint, hitRayParam, hitFace, hitTriangle, hitBary1, hitBary2 = meshFn.anyIntersection( 124 | fpSource, fvRayDir, om.MSpace.kWorld, 9999., False, 125 | accelParams=mmAccelParams, tolerance=float(1e-6)) 126 | 127 | if hitRayParam == 0.0: 128 | print('There were no intersection points detected') 129 | return 130 | 131 | hitPoints, hitRayParams, hitFaces, hitTriangles, hitBary1s, hitBary2s = meshFn.allIntersections( 132 | fpSource, fvRayDir, om.MSpace.kWorld, 9999., False, tolerance=0.000001 133 | ) 134 | 135 | normals = meshFn.getNormals(om.MSpace.kWorld) 136 | i = 0 137 | for hp in hitPoints: 138 | arrow = RayArrow() 139 | constraint = cmds.pointConstraint(sportLightTransformNode.name(), arrow.botHandle) 140 | cmds.delete(constraint) 141 | cube = cmds.polyCube() 142 | cmds.move(hp.x, hp.y, hp.z, ws=1) 143 | constraint = cmds.pointConstraint(cube[0], arrow.topHandle) 144 | cmds.delete(cube+constraint) 145 | arrow.orient() 146 | 147 | # reflection 148 | # R = 2(N dot L)N - L 149 | # L: fvRayDir 150 | faceId = hitFaces[i] 151 | 152 | # N 153 | faceNormal = normals[meshFn.getFaceNormalIds(faceId)[0]] 154 | 155 | # R 156 | refl = 2 * (faceNormal * fvRayDir) * faceNormal - fvRayDir 157 | 158 | # reflection arrow 159 | arrowRefl = RayArrow() 160 | constraint = cmds.pointConstraint(arrow.topHandle, arrowRefl.botHandle) 161 | cmds.delete(constraint) 162 | 163 | selListIt = om.MSelectionList() 164 | selListIt.add(arrowRefl.botHandle) 165 | selListIt.add(arrowRefl.topHandle) 166 | 167 | # move and rotate botHandle 168 | reflBotTran = om.MFnTransform(selListIt.getDagPath(0)) 169 | reflBotTran.setRotation(om.MEulerRotation(refl), om.MSpace.kTransform) 170 | 171 | # move and rotate topHandle 172 | constraint = cmds.parentConstraint(arrowRefl.botHandle, arrowRefl.topHandle, mo=0) 173 | cmds.delete(constraint) 174 | # reflTopTran = om.MFnTransform(selListIt.getDagPath(1)) 175 | # #reflTopTran.setRotation(om.MEulerRotation(refl), om.MSpace.kTransform) 176 | # # topMove = om.MVector(refl) 177 | # #topMove = om.MVector(refl + om.MFloatVector(0, 6, 0)) * reflTopTran.transformationMatrix() 178 | # topMove = om.MVector(refl * om.MFloatVector(1, 6, 1)) * reflBotTran.transformationMatrix() 179 | # # topMove.y += 6 180 | # reflTopTran.setTranslation(topMove, om.MSpace.kTransform) 181 | 182 | cmds.move(0, 6, 0, arrowRefl.topHandle, r=1, os=1, wd=1) 183 | 184 | arrowRefl.orient() 185 | 186 | # refraction arrow 187 | # T = ((1/fl*N) dot L) - sqrt(1 - 1/(fl*fl)*(1 - (N dot L)*(N dot L))) * N - 1/fl * L 188 | fl = .750 189 | fl2 = 0.5627813555039173 190 | 191 | a = (fl * faceNormal) * fvRayDir 192 | b = math.sqrt(1 - fl2 * abs(1 - math.pow(faceNormal * fvRayDir, 2))) 193 | c = a - b 194 | refr = c * faceNormal - fl * fvRayDir 195 | 196 | refrArrow = RayArrow() 197 | constraint = cmds.pointConstraint(arrow.topHandle, refrArrow.botHandle) 198 | cmds.delete(constraint) 199 | 200 | selListIt = om.MSelectionList() 201 | selListIt.add(refrArrow.botHandle) 202 | selListIt.add(refrArrow.topHandle) 203 | 204 | # move and rotate botHandle 205 | reflBotTran = om.MFnTransform(selListIt.getDagPath(0)) 206 | reflBotTran.setRotation(om.MEulerRotation(refr), om.MSpace.kTransform) 207 | 208 | # move and rotate topHandle 209 | constraint = cmds.parentConstraint(refrArrow.botHandle, refrArrow.topHandle, mo=0) 210 | cmds.delete(constraint) 211 | 212 | cmds.move(0, -6, 0, refrArrow.topHandle, r=1, os=1, wd=1) 213 | 214 | refrArrow.orient() 215 | 216 | i += 1 217 | 218 | def demo(): 219 | cmds.file(f=1, new=1) 220 | cmds.polyPlane(w=50, h=50) 221 | cmds.rotate(1.555, -6.203, 6.393, r=1, os=1, fo=1) 222 | cmds.spotLight() 223 | cmds.move(14.142, 26.414, 18.0) 224 | cmds.rotate(-54, 36.4, 0, r=1, os=1, fo=1) 225 | if cmds.objExists('arrows'): 226 | cmds.delete('arrows') 227 | cmds.select(['pPlane1', 'spotLight1']) 228 | intersect() 229 | 230 | demo() -------------------------------------------------------------------------------- /plugins/yTwistNode_ogl.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------------- 2 | # Copyright (c) 2014 Mack Stone. All rights reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | # THE SOFTWARE. 21 | # -------------------------------------------------------------------------------- 22 | 23 | """ 24 | Simple deform node use pyopengl and compute shader in Maya. 25 | 26 | @author: Mack Stone 27 | """ 28 | 29 | import sys 30 | import ctypes 31 | from array import array 32 | import logging 33 | 34 | import maya.OpenMaya as om 35 | import maya.OpenMayaMPx as ompx 36 | from maya import utils 37 | 38 | import numpy as np 39 | from OpenGL.GL import * 40 | from OpenGL.GL import shaders 41 | from PySide.QtOpenGL import * 42 | 43 | 44 | # shaders 45 | 46 | computeShaderSrc = """#version 430 47 | layout(local_size_x = 256) in; 48 | 49 | layout(std430, binding = 0) buffer InputBuffer{ vec4 inPos[]; }; 50 | layout(std430, binding = 1) buffer OutputBuffer{ vec4 outPos[]; }; 51 | 52 | uniform int numVert; 53 | uniform float angle; 54 | uniform float envelope; 55 | 56 | void main() 57 | { 58 | uint index = gl_GlobalInvocationID.x; 59 | if (index >= numVert) 60 | return; 61 | 62 | vec4 pos = inPos[index]; 63 | vec4 oPos = pos; 64 | float ff = angle * pos.y * envelope; 65 | if (ff != 0.0f) 66 | { 67 | float cct = cos(ff); 68 | float cst = sin(ff); 69 | oPos.x = pos.x * cct - pos.z * cst; 70 | oPos.z = pos.x * cst + pos.z * cct; 71 | } 72 | outPos[index] = oPos; 73 | } 74 | """ 75 | 76 | class MyGLWidget(QGLWidget): 77 | 78 | def __init__(self, gformat, parent=None): 79 | super(MyGLWidget, self).__init__(gformat, parent) 80 | 81 | self.angle = 0.0 82 | self.envelope = 0.0 83 | self.vertexPos = None 84 | 85 | self.__program = None 86 | self.__fbo = None 87 | 88 | self.__data = None 89 | 90 | def paintGL(self): 91 | glClearColor(0, 0, 0, 0) 92 | 93 | # create shaders 94 | compShader = shaders.compileShader(computeShaderSrc, GL_COMPUTE_SHADER) 95 | # create shader program 96 | self.__program = shaders.compileProgram(compShader) 97 | 98 | # get attribute and set uniform for shaders 99 | glUseProgram(self.__program) 100 | self.numVertUL = glGetUniformLocation(self.__program, 'numVert') 101 | glUniform1i(self.numVertUL, len(self.vertexPos)) 102 | self.angleUL = glGetUniformLocation(self.__program, 'angle') 103 | glUniform1f(self.angleUL, self.angle) 104 | self.envelopeUL = glGetUniformLocation(self.__program, 'envelope') 105 | glUniform1f(self.envelopeUL, self.envelope) 106 | #glUseProgram(0) 107 | 108 | # create buffers 109 | inPos, outPos = glGenBuffers(2) 110 | glBindBuffer(GL_SHADER_STORAGE_BUFFER, inPos) 111 | glBufferData(GL_SHADER_STORAGE_BUFFER, self.vertexPos.nbytes, self.vertexPos, GL_STATIC_DRAW) 112 | glBindBuffer(GL_SHADER_STORAGE_BUFFER, outPos) 113 | glBufferData(GL_SHADER_STORAGE_BUFFER, self.vertexPos.nbytes, np.zeros_like(self.vertexPos), GL_STATIC_DRAW) 114 | 115 | # bind buffers to fixed binding points 116 | glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, inPos) 117 | glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, outPos) 118 | 119 | # run compute shader 120 | glDispatchCompute(len(self.vertexPos), 1, 1) 121 | glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT | GL_SHADER_STORAGE_BARRIER_BIT 122 | | GL_BUFFER_UPDATE_BARRIER_BIT) 123 | 124 | glBindBuffer(GL_SHADER_STORAGE_BUFFER, outPos) 125 | dataBuffer = glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_READ_ONLY) 126 | data = ctypes.cast(dataBuffer, ctypes.POINTER(ctypes.c_float)) 127 | self.__data = np.ctypeslib.as_array(data, (len(self.vertexPos), 4)) 128 | glUnmapBuffer(GL_SHADER_STORAGE_BUFFER) 129 | 130 | def getData(self): 131 | return self.__data 132 | 133 | 134 | class YTwistNode(ompx.MPxDeformerNode): 135 | 136 | NAME = "yTwistNode" 137 | ID = om.MTypeId(0x8702) 138 | 139 | angle = om.MObject() 140 | 141 | def __init__(self): 142 | ompx.MPxDeformerNode.__init__(self) 143 | 144 | # setup logger 145 | formatter = logging.Formatter("%(asctime)s - %(message)s") 146 | utils._guiLogHandler.setFormatter(formatter) 147 | 148 | gformat = QGLFormat() 149 | gformat.setVersion(4, 3) 150 | gformat.setProfile(QGLFormat.CoreProfile) 151 | self._widget = MyGLWidget(gformat) 152 | 153 | def deform(self, dataBlock, geomIter, matrix, multiIndex): 154 | logging.info("start deforming") 155 | 156 | # get the angle from the datablock 157 | angleHandle = dataBlock.inputValue(self.angle) 158 | angleValue = angleHandle.asDouble() 159 | 160 | # get the envelope 161 | envelope = ompx.cvar.MPxDeformerNode_envelope 162 | envelopeHandle = dataBlock.inputValue(envelope) 163 | envelopeValue = envelopeHandle.asFloat() 164 | 165 | # get all position data 166 | logging.info("get all position data") 167 | pos = np.zeros((geomIter.count(), 4), dtype=np.float32) 168 | while not geomIter.isDone(): 169 | point = geomIter.position() 170 | index = geomIter.index() 171 | 172 | pos[index, 0] = point.x 173 | pos[index, 1] = point.y 174 | pos[index, 2] = point.z 175 | pos[index, 3] = point.w 176 | geomIter.next() 177 | 178 | # 179 | self._widget.angle = angleValue 180 | self._widget.envelope = envelopeValue 181 | self._widget.vertexPos = pos 182 | self._widget.updateGL() 183 | newPos = self._widget.getData() 184 | #print newPos 185 | #for i in newPos: print i 186 | 187 | # set positions 188 | logging.info("set all position") 189 | geomIter.reset() 190 | while not geomIter.isDone(): 191 | point = geomIter.position() 192 | index = geomIter.index() 193 | 194 | point.x = float(newPos[index, 0]) 195 | point.y = float(newPos[index, 1]) 196 | point.z = float(newPos[index, 2]) 197 | geomIter.setPosition(point) 198 | geomIter.next() 199 | 200 | logging.info("end deform") 201 | 202 | @staticmethod 203 | def creator(): 204 | return ompx.asMPxPtr(YTwistNode()) 205 | 206 | @staticmethod 207 | def initialize(): 208 | # angle 209 | nAttr = om.MFnNumericAttribute() 210 | YTwistNode.angle = nAttr.create("angle", "fa", om.MFnNumericData.kDouble, 0.0) 211 | nAttr.setKeyable(1) 212 | 213 | # add attribute 214 | YTwistNode.addAttribute(YTwistNode.angle) 215 | outputGeom = ompx.cvar.MPxDeformerNode_outputGeom 216 | YTwistNode.attributeAffects(YTwistNode.angle, outputGeom) 217 | 218 | # initialize the script plug-in 219 | def initializePlugin(mobject): 220 | mplugin = ompx.MFnPlugin(mobject) 221 | try: 222 | mplugin.registerNode(YTwistNode.NAME, YTwistNode.ID, YTwistNode.creator, 223 | YTwistNode.initialize, ompx.MPxNode.kDeformerNode ) 224 | except: 225 | sys.stderr.write("Failed to register node: %s\n" % YTwistNode.NAME) 226 | 227 | # uninitialize the script plug-in 228 | def uninitializePlugin(mobject): 229 | mplugin = ompx.MFnPlugin(mobject) 230 | try: 231 | mplugin.deregisterNode(YTwistNode.ID) 232 | except: 233 | sys.stderr.write("Failed to unregister node: %s\n" % YTwistNode.NAME ) 234 | -------------------------------------------------------------------------------- /shaders/parallaxMapping_01.ogsfx: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2016 Mack Stone 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /* 25 | A parallax map shader from 26 | https://github.com/SaschaWillems/Vulkan/tree/master/data/shaders/parallax 27 | */ 28 | 29 | 30 | // uniform mat4 wvp : WorldViewProjection < string UIWidget="None"; >; 31 | uniform mat4 world : World < string UIWidget="None"; >; 32 | uniform mat4 view : View < string UIWidget="None"; >; 33 | uniform mat4 projection : Projection < string UIWidget="None"; >; 34 | 35 | uniform mat4 wit : WorldInverseTranspose < string UIWidget="None"; >; 36 | uniform mat4 viewI : ViewInverse < string UIWidget="None"; >; 37 | 38 | 39 | // parameters section 40 | uniform bool Parallax = true; 41 | 42 | uniform float scale 43 | < 44 | float UIMin = 0.0; 45 | float UIMax= 0.1; 46 | float UIStep = 0.01; 47 | string UIName = "Scale"; 48 | > = 0.06; 49 | 50 | uniform float bias 51 | < 52 | float UIMin = -10.0; 53 | float UIMax= 10.0; 54 | float UIStep = 0.01; 55 | string UIName = "Bias"; 56 | > = -0.04; 57 | 58 | uniform float lightRadius 59 | < 60 | float UIMin = 0.0; 61 | float UIMax= 99.0; 62 | float UIStep = 1.0; 63 | string UIName = "Light Radius"; 64 | > = 20.0; 65 | 66 | uniform int usePom 67 | < 68 | int UIMin = 0; 69 | int UIMax= 1; 70 | int UIStep = 1; 71 | string UIName = "Disable/Enable Parallax"; 72 | > = 1; 73 | 74 | // light 75 | uniform vec3 Light0Pos : POSITION 76 | < 77 | string UIName = "Light 0 Position"; 78 | string Space = "World"; 79 | string Object = "Light 0"; 80 | > = {1.0, 1.0, 1.0}; 81 | 82 | uniform vec3 Light0Dir : DIRECTION 83 | < 84 | string UIName = "Light 0 Direction"; 85 | string Space = "World"; 86 | string Object = "Light 0"; 87 | > = {0.0, -1.0, 0.0}; 88 | 89 | 90 | // textures 91 | uniform texture2D diffuseMap 92 | < 93 | //Specify the texture file to be loaded by default 94 | string ResourceName = ""; 95 | 96 | //Specify the type of texture 97 | string ResourceType = "2D"; 98 | 99 | string UIName = "Diffuse Map"; 100 | >; 101 | 102 | uniform texture2D normalHeightMap 103 | < 104 | //Specify the texture file to be loaded by default 105 | string ResourceName = ""; 106 | 107 | //Specify the type of texture 108 | string ResourceType = "2D"; 109 | 110 | string UIName = "Normal Height Map"; 111 | >; 112 | 113 | uniform sampler2D diffuseMapSampler = sampler_state 114 | { 115 | Texture = ; 116 | TEXTURE_MIN_FILTER = LINEAR; 117 | TEXTURE_MAG_FILTER = LINEAR; 118 | TEXTURE_WRAP_S = REPEAT; 119 | TEXTURE_WRAP_T = REPEAT; 120 | TEXTURE_WRAP_R = REPEAT; 121 | }; 122 | 123 | uniform sampler2D normalHeightMapSampler = sampler_state 124 | { 125 | Texture = ; 126 | TEXTURE_MIN_FILTER = LINEAR; 127 | TEXTURE_MAG_FILTER = LINEAR; 128 | TEXTURE_WRAP_S = REPEAT; 129 | TEXTURE_WRAP_T = REPEAT; 130 | TEXTURE_WRAP_R = REPEAT; 131 | }; 132 | 133 | 134 | //------------------------------------ 135 | // Attributes 136 | //------------------------------------ 137 | // input from application 138 | attribute appIn 139 | { 140 | vec3 inPosition : POSITION; 141 | vec2 inUV : TEXCOORD0; 142 | vec3 inNormal : NORMAL; 143 | vec3 inTangent : TANGENT; 144 | vec3 inBiTangent : BITANGENT; 145 | } 146 | 147 | // ouput from vertex shader 148 | // input to pixel shader 149 | attribute vsOut 150 | { 151 | vec2 outUV : TEXCOORD0; 152 | vec3 outLightVec : TEXCOORD1; 153 | vec3 outLightVecB : TEXCOORD2; 154 | vec3 outSpecular : TEXCOORD3; 155 | vec3 outEyeVec : TEXCOORD4; 156 | vec3 outLightDir : TEXCOORD5; 157 | vec3 outViewVec : TEXCOORD6; 158 | } 159 | 160 | // output to pixel shader 161 | attribute pixelOut 162 | { 163 | vec4 outColor : COLOR0; 164 | } 165 | 166 | //------------------------------------ 167 | // vertex shader 168 | //------------------------------------ 169 | GLSLShader VS 170 | { 171 | void main() 172 | { 173 | vec3 vertexPosition = vec3(view * world * vec4(inPosition, 1.0)); 174 | outLightDir = normalize(Light0Pos - vertexPosition); 175 | 176 | // Setup (t)angent-(b)inormal-(n)ormal matrix for converting 177 | // object coordinates into tangent space 178 | mat3 normalMatrix = mat3(wit); 179 | mat3 tbnMatrix; 180 | tbnMatrix[0] = normalMatrix * inTangent; 181 | tbnMatrix[1] = normalMatrix * inBiTangent; 182 | tbnMatrix[2] = normalMatrix * inNormal; 183 | 184 | outEyeVec = vec3(-vertexPosition) * tbnMatrix; 185 | 186 | outLightVec.xyz = vec3(Light0Pos - vertexPosition) * tbnMatrix; 187 | 188 | vec3 lightDist = Light0Pos - inPosition; 189 | outLightVecB.x = dot(inTangent, lightDist); 190 | outLightVecB.y = dot(inBiTangent, lightDist); 191 | outLightVecB.z = dot(inNormal, lightDist); 192 | 193 | vec3 cameraPos = viewI[3].xyz; 194 | //vec3 camPos = vec3(normalMatrix * cameraPos); 195 | vec3 camPos = normalMatrix * cameraPos.xyz; 196 | 197 | vec3 camVec = camPos - inPosition; 198 | outViewVec.x = dot(inTangent, camVec); 199 | outViewVec.y = dot(inBiTangent, camVec); 200 | outViewVec.z = dot(inNormal, camVec); 201 | 202 | vec3 reflectVec = reflect(-camVec, inNormal); 203 | vec3 outViewVec = outLightDir; 204 | float specIntensity = pow(max(dot(reflectVec, outViewVec), 0.0), 8.0); 205 | outSpecular = vec3(specIntensity * 3.0); 206 | 207 | 208 | outUV = inUV; 209 | 210 | gl_Position = projection * view * world * vec4(inPosition, 1.0); 211 | } 212 | } 213 | 214 | 215 | //------------------------------------ 216 | // pixel shader 217 | //------------------------------------ 218 | GLSLShader FS 219 | { 220 | void main() 221 | { 222 | 223 | vec3 specularColor = vec3(0.0, 0.0, 0.0); 224 | float invRadius = 1.0 / lightRadius; 225 | float ambient = 0.5; 226 | 227 | vec3 rgb, normal, eyeVecTs; 228 | vec2 inUV = vec2(outUV.x, 1 - outUV.y); 229 | vec2 UV = inUV; 230 | 231 | // Get new scaled and biased texture coordinates 232 | // Height info is stored in alpha channel of normal map 233 | vec2 height_bump = vec2(texture(normalHeightMapSampler, inUV).a * scale + bias, 0.0); 234 | 235 | // if parallax mapping is enabled, offset texture coordinates 236 | if (usePom == 1) 237 | { 238 | UV = inUV + (height_bump.x * normalize(outEyeVec).xy); 239 | } 240 | 241 | rgb = texture(diffuseMapSampler, UV).rgb; 242 | 243 | normal = normalize(outLightVec).xyz; 244 | 245 | eyeVecTs = normalize(outLightVec).xyz; 246 | height_bump.y = min(dot(normal, eyeVecTs), 1.0); 247 | height_bump.y = pow(height_bump.y, 8.0); 248 | 249 | float distSqr = dot(outLightVecB, outLightVecB); 250 | vec3 lVec = outLightVecB * inversesqrt(distSqr); 251 | 252 | vec3 nvViewVec = normalize(outViewVec); 253 | float specular = pow(clamp(dot(reflect(-nvViewVec, normal), lVec), 0.0, 1.0), 4.0); 254 | 255 | float atten = clamp(1.0 - invRadius * sqrt(distSqr), 0.0, 1.0); 256 | float diffuse = clamp(dot(lVec, normal), 0.0, 1.0); 257 | 258 | outColor = vec4((rgb * ambient + (diffuse * rgb + 0.5 * specular * specularColor)) * atten, 1.0); 259 | 260 | //outColor = vec4(1.0, 0.0, 0.0, 1.0); 261 | } 262 | } 263 | 264 | technique Simple 265 | { 266 | pass p0 267 | { 268 | VertexShader (in appIn, out vsOut) = VS; 269 | PixelShader (in vsOut, out pixelOut) = FS; 270 | } 271 | } 272 | -------------------------------------------------------------------------------- /plugins/yTwistNode_ocl/yTwistNode.cpp: -------------------------------------------------------------------------------- 1 | //- 2 | // ========================================================================== 3 | // Copyright 1995,2006,2008 Autodesk, Inc. All rights reserved. 4 | // 5 | // Use of this software is subject to the terms of the Autodesk 6 | // license agreement provided at the time of installation or download, 7 | // or which otherwise accompanies this software in either electronic 8 | // or hard copy form. 9 | // ========================================================================== 10 | //+ 11 | // 12 | // File: yTwist.cpp 13 | // 14 | // Description: 15 | // Example implementation of a deformer. This node 16 | // twists the deformed vertices around the y-axis. 17 | // 18 | #define __CL_ENABLE_EXCEPTIONS 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | // opencl include 42 | #include 43 | #include 44 | #include 45 | #include 46 | 47 | 48 | #define McheckErr(stat,msg) \ 49 | if ( MS::kSuccess != stat ) { \ 50 | cerr << msg; \ 51 | return MS::kFailure; \ 52 | } 53 | 54 | // kerne code 55 | const char kerneSrc[] = "#pragma OPENCL EXTENSION cl_khr_fp64: enable\n" 56 | "__kernel void ytwist(__global const double4 *pos,\n" 57 | "__global double4 *newPos,\n" 58 | "double magnitude,\n" 59 | "float envelope)\n" 60 | "{\n" 61 | " int gid = get_global_id(0);\n" 62 | " newPos[gid] = pos[gid];\n" 63 | " float ff = magnitude * pos[gid].y * envelope;\n" 64 | " if (ff != 0.f)\n" 65 | " {\n" 66 | " float cct = cos(ff);\n" 67 | " float cst = sin(ff);\n" 68 | " newPos[gid].x = pos[gid].x * cct - pos[gid].z * cst;\n" 69 | " newPos[gid].z = pos[gid].x * cst + pos[gid].z * cct;\n" 70 | " }\n" 71 | "}"; 72 | 73 | 74 | class yTwist : public MPxDeformerNode 75 | { 76 | public: 77 | yTwist(); 78 | virtual ~yTwist(); 79 | 80 | static void* creator(); 81 | static MStatus initialize(); 82 | 83 | // deformation function 84 | // 85 | virtual MStatus deform(MDataBlock& block, 86 | MItGeometry& iter, 87 | const MMatrix& mat, 88 | unsigned int multiIndex); 89 | 90 | public: 91 | // yTwist attributes 92 | // 93 | static MObject angle; // angle to twist 94 | 95 | static MTypeId id; 96 | 97 | private: 98 | 99 | }; 100 | 101 | MTypeId yTwist::id(0x8000e); 102 | 103 | //////////////////////// 104 | // yTwist attributes // 105 | //////////////////////// 106 | 107 | MObject yTwist::angle; 108 | 109 | 110 | yTwist::yTwist() 111 | // 112 | // Description: 113 | // constructor 114 | // 115 | { 116 | 117 | } 118 | 119 | yTwist::~yTwist() 120 | // 121 | // Description: 122 | // destructor 123 | // 124 | {} 125 | 126 | void* yTwist::creator() 127 | // 128 | // Description: 129 | // create the yTwist 130 | // 131 | { 132 | return new yTwist(); 133 | } 134 | 135 | MStatus yTwist::initialize() 136 | // 137 | // Description: 138 | // initialize the attributes 139 | // 140 | { 141 | // local attribute initialization 142 | // 143 | MFnNumericAttribute nAttr; 144 | angle = nAttr.create("angle", "fa", MFnNumericData::kDouble); 145 | nAttr.setDefault(0.0); 146 | nAttr.setKeyable(true); 147 | addAttribute(angle); 148 | 149 | // affects 150 | // 151 | attributeAffects(yTwist::angle, yTwist::outputGeom); 152 | 153 | return MS::kSuccess; 154 | } 155 | 156 | MStatus 157 | yTwist::deform(MDataBlock& block, 158 | MItGeometry& iter, 159 | const MMatrix& /*m*/, 160 | unsigned int /*multiIndex*/) 161 | // 162 | // Method: deform 163 | // 164 | // Description: Deform the point with a yTwist algorithm 165 | // 166 | // Arguments: 167 | // block : the datablock of the node 168 | // iter : an iterator for the geometry to be deformed 169 | // m : matrix to transform the point into world space 170 | // multiIndex : the index of the geometry that we are deforming 171 | // 172 | // 173 | { 174 | cl_int err = CL_SUCCESS; 175 | MStatus status = MS::kSuccess; 176 | 177 | // determine the angle of the yTwist 178 | // 179 | MDataHandle angleData = block.inputValue(angle, &status); 180 | McheckErr(status, "Error getting angle data handle\n"); 181 | double magnitude = angleData.asDouble(); 182 | 183 | // determine the envelope (this is a global scale factor) 184 | // 185 | MDataHandle envData = block.inputValue(envelope, &status); 186 | McheckErr(status, "Error getting envelope data handle\n"); 187 | float env = envData.asFloat(); 188 | 189 | try 190 | { 191 | // find a opencl platform 192 | std::vector platforms; 193 | cl::Platform::get(&platforms); 194 | if (platforms.size() == 0) 195 | { 196 | MGlobal::displayError("Platform size 0"); 197 | return MS::kFailure; 198 | } 199 | 200 | // create a context 201 | cl_context_properties properties[] = { CL_CONTEXT_PLATFORM, 202 | (cl_context_properties)(platforms[0])(), 0 }; 203 | cl::Context context(CL_DEVICE_TYPE_GPU, properties); 204 | // get devices 205 | std::vector devices = context.getInfo(); 206 | // create a program 207 | cl::Program::Sources source(1, std::make_pair(kerneSrc, strlen(kerneSrc))); 208 | cl::Program program(context, source); 209 | program.build(devices); 210 | 211 | // position data 212 | int numPoints = iter.count(); 213 | cl_double4 *allPos = new cl_double4[numPoints]; 214 | cl_double4 *outPos = new cl_double4[numPoints]; 215 | 216 | // iterate through each point in the geometry 217 | // get all position data 218 | int i = 0; 219 | for (; !iter.isDone(); iter.next()) { 220 | MPoint pt = iter.position(); 221 | #if defined(__GNUC__) 222 | allPos[i].x = pt.x; 223 | allPos[i].y = pt.y; 224 | allPos[i].z = pt.z; 225 | allPos[i].w = pt.w; 226 | #else 227 | // for MSVC 228 | allPos[i].s[0] = pt.x; 229 | allPos[i].s[1] = pt.y; 230 | allPos[i].s[2] = pt.z; 231 | allPos[i].s[3] = pt.w; 232 | #endif 233 | 234 | i++; 235 | } 236 | 237 | // create buffers 238 | cl::Buffer posBuffer = cl::Buffer(context, 239 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, 240 | numPoints * sizeof(cl_double4), allPos); 241 | cl::Buffer nposBuffer = cl::Buffer(context, 242 | CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR, 243 | numPoints * sizeof(cl_double4), outPos); 244 | 245 | // create a kernel 246 | cl::Kernel kernel(program, "ytwist", &err); 247 | // set kernel argmuments 248 | kernel.setArg(0, posBuffer); 249 | kernel.setArg(1, nposBuffer); 250 | kernel.setArg(2, magnitude); 251 | kernel.setArg(3, env); 252 | 253 | // create a command queue 254 | cl::Event event; 255 | cl::CommandQueue queue(context, devices[0], 0, &err); 256 | // execut the kernel 257 | queue.enqueueNDRangeKernel(kernel, 258 | cl::NullRange, 259 | cl::NDRange(numPoints), 260 | cl::NullRange, 261 | NULL, 262 | &event); 263 | event.wait(); 264 | 265 | // read the data back 266 | queue.enqueueReadBuffer(nposBuffer, CL_TRUE, 0, numPoints * sizeof(cl_double4), outPos); 267 | 268 | // set the new positions 269 | i = 0; 270 | iter.reset(); 271 | for (; !iter.isDone(); iter.next()) { 272 | MPoint pt = iter.position(); 273 | #if defined(__GNUC__) 274 | pt.x = outPos[i].x; 275 | pt.z = outPos[i].z; 276 | #else 277 | pt.x = outPos[i].s[0]; 278 | pt.z = outPos[i].s[2]; 279 | #endif 280 | iter.setPosition(pt); 281 | i++; 282 | } 283 | 284 | // clean up 285 | delete[] allPos; 286 | delete[] outPos; 287 | } 288 | catch (cl::Error err){ 289 | MString errStr; 290 | errStr += "ERROR: "; 291 | errStr += err.what(); 292 | errStr += "("; 293 | errStr += err.err(); 294 | errStr += ")"; 295 | MGlobal::displayError(errStr); 296 | /*std::cerr << "ERROR: " 297 | << err.what() 298 | << "(" 299 | << err.err() 300 | << ")" 301 | << std::endl;*/ 302 | } 303 | 304 | return status; 305 | } 306 | 307 | // standard initialization procedures 308 | // 309 | 310 | MStatus initializePlugin(MObject obj) 311 | { 312 | MStatus result; 313 | MFnPlugin plugin(obj, PLUGIN_COMPANY, "3.0", "Any"); 314 | result = plugin.registerNode("yTwist", yTwist::id, yTwist::creator, 315 | yTwist::initialize, MPxNode::kDeformerNode); 316 | return result; 317 | } 318 | 319 | MStatus uninitializePlugin(MObject obj) 320 | { 321 | MStatus result; 322 | MFnPlugin plugin(obj); 323 | result = plugin.deregisterNode(yTwist::id); 324 | return result; 325 | } 326 | -------------------------------------------------------------------------------- /shaders/parallaxMapping.ogsfx: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2015 Mack Stone 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /* 25 | A normal map shader from 26 | http://learnopengl.com/#!Advanced-Lighting/Normal-Mapping 27 | */ 28 | 29 | 30 | // uniform mat4 wvp : WorldViewProjection < string UIWidget="None"; >; 31 | uniform mat4 world : World < string UIWidget="None"; >; 32 | uniform mat4 view : View < string UIWidget="None"; >; 33 | uniform mat4 projection : Projection < string UIWidget="None"; >; 34 | 35 | uniform mat4 wit : WorldInverseTranspose < string UIWidget="None"; >; 36 | uniform mat4 viewI : ViewInverse < string UIWidget="None"; >; 37 | 38 | 39 | // parameters section 40 | uniform bool Parallax = true; 41 | 42 | uniform float height_scale 43 | < 44 | float UIMin = 0.0; 45 | float UIMax = 0.5; 46 | float UIStep = 0.01; 47 | string UIName = "Height Scale"; 48 | > = 0.08; 49 | 50 | // light 51 | uniform vec3 Light0Pos : POSITION 52 | < 53 | string UIName = "Light 0 Position"; 54 | string Space = "World"; 55 | string Object = "Light 0"; 56 | > = {1.0, 1.0, 1.0}; 57 | 58 | uniform vec3 Light0Dir : DIRECTION 59 | < 60 | string UIName = "Light 0 Direction"; 61 | string Space = "World"; 62 | string Object = "Light 0"; 63 | > = {0.0, -1.0, 0.0}; 64 | 65 | 66 | // textures 67 | uniform texture2D diffuseMap 68 | < 69 | //Specify the texture file to be loaded by default 70 | string ResourceName = "bricks2.jpg"; 71 | 72 | //Specify the type of texture 73 | string ResourceType = "2D"; 74 | 75 | string UIName = "Diffuse Map"; 76 | >; 77 | 78 | uniform texture2D normalMap 79 | < 80 | //Specify the texture file to be loaded by default 81 | string ResourceName = "bricks2_normal.jpg"; 82 | 83 | //Specify the type of texture 84 | string ResourceType = "2D"; 85 | 86 | string UIName = "Normal Map"; 87 | >; 88 | 89 | uniform texture2D depthMap 90 | < 91 | //Specify the texture file to be loaded by default 92 | string ResourceName = "bricks2_disp.jpg"; 93 | 94 | //Specify the type of texture 95 | string ResourceType = "2D"; 96 | 97 | string UIName = "Depth Map"; 98 | >; 99 | 100 | uniform sampler2D diffuseMapSampler = sampler_state 101 | { 102 | Texture = ; 103 | TEXTURE_MIN_FILTER = LINEAR; 104 | TEXTURE_MAG_FILTER = LINEAR; 105 | TEXTURE_WRAP_S = REPEAT; 106 | TEXTURE_WRAP_T = REPEAT; 107 | TEXTURE_WRAP_R = REPEAT; 108 | }; 109 | 110 | uniform sampler2D normalMapSampler = sampler_state 111 | { 112 | Texture = ; 113 | TEXTURE_MIN_FILTER = LINEAR; 114 | TEXTURE_MAG_FILTER = LINEAR; 115 | TEXTURE_WRAP_S = REPEAT; 116 | TEXTURE_WRAP_T = REPEAT; 117 | TEXTURE_WRAP_R = REPEAT; 118 | }; 119 | 120 | uniform sampler2D depthMapSampler = sampler_state 121 | { 122 | Texture = ; 123 | TEXTURE_MIN_FILTER = LINEAR; 124 | TEXTURE_MAG_FILTER = LINEAR; 125 | TEXTURE_WRAP_S = REPEAT; 126 | TEXTURE_WRAP_T = REPEAT; 127 | TEXTURE_WRAP_R = REPEAT; 128 | }; 129 | 130 | 131 | //------------------------------------ 132 | // Attributes 133 | //------------------------------------ 134 | // input from application 135 | attribute appIn 136 | { 137 | vec3 inPosition : POSITION; 138 | vec2 inUV : TEXCOORD0; 139 | vec3 inNormal : NORMAL; 140 | vec3 inTangent : TANGENT; 141 | vec3 inBiTangent : BITANGENT; 142 | } 143 | 144 | // ouput from vertex shader 145 | // input to pixel shader 146 | attribute vsOut 147 | { 148 | vec2 outUV : TEXCOORD0; 149 | vec3 fragPos : TEXCOORD1; 150 | vec3 tangentLightPos : TEXCOORD2; 151 | vec3 tangentViewPos : TEXCOORD3; 152 | vec3 tangentFragPos : TEXCOORD4; 153 | } 154 | 155 | // output to pixel shader 156 | attribute pixelOut 157 | { 158 | vec4 outColor : COLOR0; 159 | } 160 | 161 | //------------------------------------ 162 | // vertex shader 163 | //------------------------------------ 164 | GLSLShader VS 165 | { 166 | void main() 167 | { 168 | vec3 cameraPos = viewI[3].xyz; // view pos 169 | fragPos = vec3(world * vec4(inPosition, 1.0)); 170 | outUV = inUV; 171 | 172 | mat3 normalMatrix = mat3(wit); 173 | vec3 T = normalize(normalMatrix * inTangent); 174 | vec3 B = normalize(normalMatrix * inBiTangent); 175 | vec3 N = normalize(normalMatrix * inNormal); 176 | 177 | mat3 TBN = transpose(mat3(T, B, N)); 178 | tangentLightPos = TBN * Light0Pos; 179 | tangentViewPos = TBN * cameraPos; 180 | tangentFragPos = TBN * fragPos; 181 | 182 | gl_Position = projection * view * world * vec4(inPosition, 1.0); 183 | } 184 | } 185 | 186 | // pixel shader functions 187 | GLSLShader PixelShader_funcs 188 | { 189 | vec2 ParallaxMapping(vec2 texCoords, vec3 viewDir) 190 | { 191 | //vec3 viewDir = viewI[3].xyz; 192 | 193 | // number of depth layers 194 | const float minLayers = 8; 195 | const float maxLayers = 32; 196 | float numLayers = mix(maxLayers, minLayers, abs(dot(vec3(0.0, 0.0, 1.0), viewDir))); 197 | // calculate the size of each layer 198 | float layerDepth = 1.0 / numLayers; 199 | // depth of current layer 200 | float currentLayerDepth = 0.0; 201 | // the amount to shift the texture coordinates per layer (from vector P) 202 | vec2 P = viewDir.xy / viewDir.z * height_scale; 203 | vec2 deltaTexCoords = P / numLayers; 204 | 205 | // get initial values 206 | vec2 currentTexCoords = texCoords; 207 | float currentDepthMapValue = texture(depthMapSampler, currentTexCoords).r; 208 | 209 | while(currentLayerDepth < currentDepthMapValue) 210 | { 211 | // shift texture coordinates along direction of P 212 | currentTexCoords -= deltaTexCoords; 213 | // get depthmap value at current texture coordinates 214 | currentDepthMapValue = texture(depthMapSampler, currentTexCoords).r; 215 | // get depth of next layer 216 | currentLayerDepth += layerDepth; 217 | } 218 | 219 | // -- parallax occlusion mapping interpolation from here on 220 | // get texture coordinates before collision (reverse operations) 221 | vec2 prevTexCoords = currentTexCoords + deltaTexCoords; 222 | 223 | // get depth after and before collision for linear interpolation 224 | float afterDepth = currentDepthMapValue - currentLayerDepth; 225 | float beforeDepth = texture(depthMapSampler, prevTexCoords).r - currentLayerDepth + layerDepth; 226 | 227 | // interpolation of texture coordinates 228 | float weight = afterDepth / (afterDepth - beforeDepth); 229 | vec2 finalTexCoords = prevTexCoords * weight + currentTexCoords * (1.0 - weight); 230 | return finalTexCoords; 231 | } 232 | } 233 | 234 | //------------------------------------ 235 | // pixel shader 236 | //------------------------------------ 237 | GLSLShader FS 238 | { 239 | void main() 240 | { 241 | // Offset texture coordinates with Parallax Mapping 242 | vec3 viewDir = normalize(tangentViewPos - tangentFragPos); 243 | vec2 texCoords = vec2(outUV.x, 1 - outUV.y); 244 | if(Parallax) 245 | // texCoords = ParallaxMapping(vec2(outUV.x, 1 - outUV.y), viewI[3].xyz); 246 | texCoords = ParallaxMapping(outUV, viewDir); 247 | 248 | if(texCoords.x > 1.0 || texCoords.y > 1.0 || texCoords.x < 0.0 || texCoords.y < 0.0) 249 | discard; 250 | 251 | // Obtain normal from normal map in range [0,1] 252 | vec3 normal = texture(normalMapSampler, texCoords).rgb; 253 | // Transform normal vector to range [-1, 1] 254 | normal = normalize(normal * 2.0 - 1.0); // this normal is in tangent space 255 | 256 | // Get diffuse color 257 | vec3 color = texture(diffuseMapSampler, texCoords).rgb; 258 | // Ambient 259 | vec3 ambient = 0.1 * color; 260 | // Diffuse 261 | vec3 lightDir = normalize(tangentLightPos - tangentFragPos); 262 | float diff = max(dot(lightDir, normal), 0.0); 263 | vec3 diffuse = diff * color; 264 | // Specular 265 | vec3 reflectDir = reflect(-lightDir, normal); 266 | vec3 halfwayDir = normalize(lightDir + viewDir); 267 | float spec = pow(max(dot(normal, halfwayDir), 0.0), 32.0); 268 | vec3 specular = vec3(0.2) * spec; 269 | 270 | outColor = vec4(ambient + diffuse + specular, 1.0); 271 | 272 | // outColor = vec4(1.0, 0.0, 0.0, 1.0); 273 | } 274 | } 275 | 276 | technique Simple 277 | { 278 | pass p0 279 | { 280 | VertexShader (in appIn, out vsOut) = VS; 281 | PixelShader (in vsOut, out pixelOut) = {PixelShader_funcs, FS}; 282 | } 283 | } 284 | -------------------------------------------------------------------------------- /plugins/yTwistNode_ocl/yTwistNode.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | x64 7 | 8 | 9 | ReleaseDebug 10 | x64 11 | 12 | 13 | Release 14 | x64 15 | 16 | 17 | 18 | Win32Proj 19 | 20 | 21 | 22 | DynamicLibrary 23 | true 24 | 25 | 26 | DynamicLibrary 27 | false 28 | 29 | 30 | DynamicLibrary 31 | false 32 | Windows7.1SDK 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | true 52 | $(Platform)\$(Configuration)\ 53 | .mll 54 | AllRules.ruleset 55 | 56 | 57 | 58 | _DEBUG;WIN32;_WINDOWS;_USRDLL;NT_PLUGIN;_HAS_ITERATOR_DEBUGGING=0;_SECURE_SCL=0;_SECURE_SCL_THROWS=0;_SECURE_SCL_DEPRECATE=0;_CRT_SECURE_NO_DEPRECATE;TBB_USE_DEBUG=0;__TBB_LIB_NAME=tbb.lib;REQUIRE_IOSTREAM;AW_NEW_IOSTREAMS;Bits64_;%(PreprocessorDefinitions) 59 | .;..\..\..\include;..\..\..\..\include;%(AdditionalIncludeDirectories) 60 | MultiThreadedDebugDLL 61 | Level3 62 | ProgramDatabase 63 | true 64 | $(IntDir)$(ProjectName).pdb 65 | Disabled 66 | 67 | 68 | true 69 | Windows 70 | ..\..\..\lib;..\..\..\..\lib;%(AdditionalLibraryDirectories) 71 | OpenMaya.lib;OpenMayaAnim.lib;Foundation.lib;%(AdditionalDependencies) 72 | /export:initializePlugin /export:uninitializePlugin %(AdditionalOptions) 73 | false 74 | $(OutDir)$(TargetName).lib 75 | 76 | 77 | 78 | false 79 | $(Platform)\$(Configuration)\ 80 | .mll 81 | AllRules.ruleset 82 | 83 | 84 | 85 | NDEBUG;WIN32;_WINDOWS;_USRDLL;NT_PLUGIN;_HAS_ITERATOR_DEBUGGING=0;_SECURE_SCL=0;_SECURE_SCL_THROWS=0;_SECURE_SCL_DEPRECATE=0;_CRT_SECURE_NO_DEPRECATE;TBB_USE_DEBUG=0;__TBB_LIB_NAME=tbb.lib;REQUIRE_IOSTREAM;AW_NEW_IOSTREAMS;Bits64_;%(PreprocessorDefinitions) 86 | .;..\..\..\include;..\..\..\..\include;%(AdditionalIncludeDirectories) 87 | MultiThreadedDLL 88 | Level3 89 | ProgramDatabase 90 | true 91 | $(IntDir)$(ProjectName).pdb 92 | OnlyExplicitInline 93 | true 94 | true 95 | 96 | 97 | true 98 | Windows 99 | ..\..\..\lib;..\..\..\..\lib;%(AdditionalLibraryDirectories) 100 | OpenMaya.lib;OpenMayaAnim.lib;Foundation.lib;%(AdditionalDependencies) 101 | /export:initializePlugin /export:uninitializePlugin %(AdditionalOptions) 102 | false 103 | $(OutDir)$(TargetName).lib 104 | true 105 | true 106 | 107 | 108 | 109 | false 110 | $(Platform)\$(Configuration)\ 111 | .mll 112 | AllRules.ruleset 113 | C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\include;C:\Program Files\Autodesk\Maya2014\include;C:\Program Files %28x86%29\Microsoft SDKs\Windows\v7.1A\Include;$(IncludePath) 114 | C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\lib\x64;C:\Program Files\Autodesk\Maya2014\lib;C:\Program Files %28x86%29\Microsoft SDKs\Windows\v7.1A\Lib\x64;$(LibraryPath) 115 | 116 | 117 | 118 | NDEBUG;WIN32;_WINDOWS;_USRDLL;NT_PLUGIN;_HAS_ITERATOR_DEBUGGING=0;_SECURE_SCL=0;_SECURE_SCL_THROWS=0;_SECURE_SCL_DEPRECATE=0;_CRT_SECURE_NO_DEPRECATE;TBB_USE_DEBUG=0;__TBB_LIB_NAME=tbb.lib;REQUIRE_IOSTREAM;AW_NEW_IOSTREAMS;Bits64_;%(PreprocessorDefinitions) 119 | .;..\..\..\include;..\..\..\..\include;%(AdditionalIncludeDirectories) 120 | MultiThreadedDLL 121 | Level3 122 | ProgramDatabase 123 | true 124 | $(IntDir)$(ProjectName).pdb 125 | OnlyExplicitInline 126 | true 127 | true 128 | 129 | 130 | false 131 | Windows 132 | ..\..\..\lib;..\..\..\..\lib;%(AdditionalLibraryDirectories) 133 | OpenMaya.lib;OpenMayaAnim.lib;Foundation.lib;OpenCL.lib;%(AdditionalDependencies) 134 | /export:initializePlugin /export:uninitializePlugin %(AdditionalOptions) 135 | false 136 | $(OutDir)$(TargetName).lib 137 | true 138 | true 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /shaders/texture.sfx: -------------------------------------------------------------------------------- 1 | SFX_WIN 2 | Version=26 3 | GroupVersion=-1.0 4 | Advanced=0 5 | HelpID=0 6 | NumberOfNodes=35 7 | #NT=20011 0 8 | PC=5 9 | name=1 v=5000 ambientColor 10 | posx=1 v=2003 9.19464 11 | posy=1 v=2003 310.451 12 | color=2 e=0 v=3003 0.317464,0.317464,0.317464,1.0 13 | defineinheader=2 e=0 v=2001 1 14 | group=-1 15 | ISC=0 16 | OSC=6 17 | SVT=5001 3003 1 18 | CC=0 19 | SVT=5001 3002 2 20 | CC=1 21 | C=0 1 2 10 1 2 0 22 | CPC=0 23 | SVT=5001 2003 3 24 | CC=0 25 | SVT=5001 2003 4 26 | CC=0 27 | SVT=5001 2003 5 28 | CC=0 29 | SVT=5001 2003 6 30 | CC=0 31 | #NT=20011 0 32 | PC=5 33 | name=1 v=5000 diffuseColor 34 | posx=1 v=2003 -65.3373 35 | posy=1 v=2003 475.367 36 | color=2 e=0 v=3003 1.0,1.0,1.0,1.0 37 | defineinheader=2 e=0 v=2001 1 38 | group=-1 39 | ISC=0 40 | OSC=6 41 | SVT=5001 3003 1 42 | CC=0 43 | SVT=5001 3002 2 44 | CC=1 45 | C=1 1 2 34 0 1 0 46 | CPC=0 47 | SVT=5001 2003 3 48 | CC=0 49 | SVT=5001 2003 4 50 | CC=0 51 | SVT=5001 2003 5 52 | CC=0 53 | SVT=5001 2003 6 54 | CC=0 55 | #NT=20152 0 56 | PC=3 57 | posx=1 v=2003 -1120.1 58 | posy=1 v=2003 39.9262 59 | exposesetting=1 v=2001 1 60 | group=-1 61 | ISC=0 62 | OSC=1 63 | SVT=5001 5017 1 64 | CC=1 65 | C=2 0 1 3 0 1 0 66 | CPC=0 67 | #NT=20153 0 68 | PC=2 69 | posx=1 v=2003 -940.04 70 | posy=1 v=2003 31.7645 71 | group=-1 72 | ISC=1 73 | SVT=5001 5017 1 0 0 74 | OSC=1 75 | SVT=2002 2002 2 76 | CC=1 77 | C=3 0 2 21 0 1 0 78 | CPC=0 79 | #NT=20008 0 80 | PC=2 81 | posx=1 v=2003 797.873 82 | posy=1 v=2003 144.947 83 | group=-1 84 | ISC=2 85 | SVT=5001 3003 1 0 0 86 | SVT=5001 2003 3 0 0 87 | OSC=1 88 | SVT=5001 5009 2 89 | CC=1 90 | C=4 0 2 6 4 5 0 91 | CPC=0 92 | #NT=20002 0 93 | PC=3 94 | posx=1 v=2003 1164.43 95 | posy=1 v=2003 16.5409 96 | techniquename=1 v=5000 sample 97 | group=-1 98 | ISC=1 99 | SVT=5001 5004 1 0 0 100 | OSC=1 101 | SVT=5001 5003 2 102 | CC=1 103 | C=5 0 2 15 2 2 0 104 | CPC=0 105 | #NT=20003 0 106 | PC=2 107 | posx=1 v=2003 961.172 108 | posy=1 v=2003 -49.9801 109 | group=-1 110 | ISC=7 111 | SVT=5001 5014 1 0 0 112 | SVT=5001 5005 2 0 0 113 | SVT=5001 5007 3 0 0 114 | SVT=5001 5008 4 0 0 115 | SVT=5001 5009 5 0 0 116 | SVT=5001 5011 7 0 0 117 | SVT=5001 5011 8 0 0 118 | OSC=1 119 | SVT=5001 5004 6 120 | CC=1 121 | C=6 0 6 5 0 1 0 122 | CPC=0 123 | #NT=20021 0 124 | PC=3 125 | name=1 v=5000 worldNormal 126 | posx=1 v=2003 -409.101 127 | posy=1 v=2003 309.9 128 | group=-1 129 | ISC=1 130 | SVT=5001 3002 1 0 0 131 | OSC=1 132 | SVT=5001 3002 2 133 | CC=1 134 | C=7 0 2 8 1 2 0 135 | CPC=0 136 | #NT=20018 0 137 | PC=4 138 | name=1 v=5000 lambert 139 | posx=1 v=2003 -149.099 140 | posy=1 v=2003 152.985 141 | compoundassignment=1 v=2001 1 142 | group=-1 143 | ISC=2 144 | SVT=5001 3002 1 0 0 145 | SVT=5001 3002 2 0 0 146 | OSC=1 147 | SVT=5001 2003 3 148 | CC=1 149 | C=8 0 3 9 0 1 0 150 | CPC=0 151 | #NT=20023 0 152 | PC=4 153 | name=1 v=5000 lambert 154 | posx=1 v=2003 63.5021 155 | posy=1 v=2003 171.577 156 | compoundassignment=1 v=2001 1 157 | group=-1 158 | ISC=1 159 | SVT=5001 2003 1 0 0 160 | OSC=1 161 | SVT=5001 2003 2 162 | CC=1 163 | C=9 0 2 10 0 1 0 164 | CPC=0 165 | #NT=20026 0 166 | PC=2 167 | posx=1 v=2003 247.093 168 | posy=1 v=2003 252.166 169 | group=-1 170 | ISC=2 171 | SVT=5001 2003 1 0 0 172 | SVT=5001 3002 2 0 0 173 | OSC=1 174 | SVT=5001 3002 3 175 | CC=1 176 | C=10 0 3 11 0 1 0 177 | CPC=0 178 | #NT=20016 0 179 | PC=3 180 | name=1 v=5000 color 181 | posx=1 v=2003 423.288 182 | posy=1 v=2003 339.726 183 | group=-1 184 | ISC=2 185 | SVT=5001 3002 1 0 0 186 | SVT=5001 3002 2 0 0 187 | OSC=1 188 | SVT=5001 3002 3 189 | CC=1 190 | C=11 0 3 12 4 5 0 191 | CPC=0 192 | #NT=20020 0 193 | PC=3 194 | name=1 v=5000 outColor 195 | posx=1 v=2003 598.63 196 | posy=1 v=2003 284.931 197 | group=-1 198 | ISC=6 199 | SVT=5001 2003 1 0 0 200 | SVT=5001 2003 2 0 0 201 | SVT=5001 3001 3 0 0 202 | SVT=5001 2003 4 0 0 203 | SVT=5001 3002 5 0 0 204 | SVT=5001 2003 6 0 0 205 | OSC=3 206 | SVT=5001 3001 7 207 | CC=0 208 | SVT=5001 3002 8 209 | CC=0 210 | SVT=5001 3003 9 211 | CC=1 212 | C=12 2 9 4 0 1 0 213 | CPC=0 214 | #NT=20017 0 215 | PC=2 216 | posx=1 v=2003 408.219 217 | posy=1 v=2003 524.657 218 | group=-1 219 | ISC=0 220 | OSC=1 221 | SVT=5001 2003 1 222 | CC=1 223 | C=13 0 1 12 5 6 0 224 | CPC=0 225 | #NT=20112 0 226 | PC=2 227 | posx=1 v=2003 -556.482 228 | posy=1 v=2003 99.5242 229 | group=-1 230 | ISC=1 231 | SVT=5001 3002 1 0 0 232 | OSC=1 233 | SVT=5001 3002 2 234 | CC=1 235 | C=14 0 2 16 0 1 0 236 | CPC=0 237 | #NT=20001 0 238 | PC=4 239 | posx=1 v=2003 1378.13 240 | posy=1 v=2003 0.256368 241 | config=2 e=0 v=5012 1 242 | saveshadertodisk=2 e=0 v=5015 243 | group=-1 244 | ISC=3 245 | SVT=2002 2002 3 0 0 246 | SVT=5001 5016 1 0 0 247 | SVT=5001 5003 2 0 0 248 | OSC=0 249 | #NT=20021 0 250 | PC=3 251 | name=1 v=5000 lightDir 252 | posx=1 v=2003 -345.777 253 | posy=1 v=2003 120.241 254 | group=-1 255 | ISC=1 256 | SVT=5001 3002 1 0 0 257 | OSC=1 258 | SVT=5001 3002 2 259 | CC=1 260 | C=16 0 2 8 0 1 0 261 | CPC=0 262 | #NT=20014 0 263 | PC=3 264 | name=1 v=5000 normal 265 | posx=1 v=2003 -1147.54 266 | posy=1 v=2003 274.591 267 | group=-1 268 | ISC=0 269 | OSC=2 270 | SVT=5001 3003 1 271 | CC=0 272 | SVT=5001 3002 2 273 | CC=1 274 | C=17 1 2 19 0 1 0 275 | CPC=0 276 | #NT=20064 0 277 | PC=2 278 | posx=1 v=2003 -1139.35 279 | posy=1 v=2003 430.329 280 | group=-1 281 | ISC=0 282 | OSC=1 283 | SVT=5001 4900 1 284 | CC=1 285 | C=18 0 1 19 1 2 0 286 | CPC=0 287 | #NT=20016 0 288 | PC=3 289 | name=1 v=5000 normal 290 | posx=1 v=2003 -940.985 291 | posy=1 v=2003 327.417 292 | group=-1 293 | ISC=2 294 | SVT=5001 3002 1 0 0 295 | SVT=5001 4900 2 0 0 296 | OSC=1 297 | SVT=5001 3002 3 298 | CC=1 299 | C=19 0 3 20 1 2 0 300 | CPC=0 301 | #NT=20015 0 302 | PC=5 303 | name=1 v=5000 worldNormal 304 | posx=1 v=2003 -692.148 305 | posy=1 v=2003 328.304 306 | texcoordname=1 v=5000 worldNormal 307 | tweaktexcoord=1 v=2001 1 308 | group=-1 309 | ISC=2 310 | SVT=5001 5000 1 0 0 311 | SVT=5001 3002 2 0 0 312 | OSC=1 313 | SVT=5001 3002 3 314 | CC=1 315 | C=20 0 3 7 0 1 0 316 | CPC=0 317 | #NT=20130 0 318 | PC=3 319 | posx=1 v=2003 -758.038 320 | posy=1 v=2003 54.338 321 | lightindex=2 e=0 v=2002 1 322 | group=-1 323 | ISC=1 324 | SVT=2002 2002 1 0 0 325 | OSC=1 326 | SVT=5001 3002 2 327 | CC=1 328 | C=21 0 2 14 0 1 0 329 | CPC=0 330 | #NT=20004 0 331 | PC=2 332 | posx=1 v=2003 28.5651 333 | posy=1 v=2003 -184.334 334 | group=-1 335 | ISC=3 336 | SVT=5001 3003 1 0 0 337 | SVT=5001 1002 4 0 0 338 | SVT=5001 3003 2 0 0 339 | OSC=1 340 | SVT=5001 5005 3 341 | CC=1 342 | C=22 0 3 6 1 2 0 343 | CPC=0 344 | #NT=20012 0 345 | PC=2 346 | posx=1 v=2003 -579.738 347 | posy=1 v=2003 -334.119 348 | group=-1 349 | ISC=0 350 | OSC=2 351 | SVT=5001 3003 1 352 | CC=1 353 | C=23 0 1 22 0 1 0 354 | CPC=0 355 | SVT=5001 3002 2 356 | CC=0 357 | #NT=20012 0 358 | PC=2 359 | posx=1 v=2003 -578.916 360 | posy=1 v=2003 -173.675 361 | group=-1 362 | ISC=0 363 | OSC=2 364 | SVT=5001 3003 1 365 | CC=1 366 | C=24 0 1 26 0 1 0 367 | CPC=0 368 | SVT=5001 3002 2 369 | CC=0 370 | #NT=20081 0 371 | PC=2 372 | posx=1 v=2003 -568.182 373 | posy=1 v=2003 -46.4427 374 | group=-1 375 | ISC=0 376 | OSC=1 377 | SVT=5001 4900 1 378 | CC=1 379 | C=25 0 1 26 1 2 0 380 | CPC=0 381 | #NT=20016 0 382 | PC=3 383 | name=1 v=5000 position 384 | posx=1 v=2003 -396.245 385 | posy=1 v=2003 -128.459 386 | group=-1 387 | ISC=2 388 | SVT=5001 3003 1 0 0 389 | SVT=5001 4900 2 0 0 390 | OSC=1 391 | SVT=5001 3003 3 392 | CC=1 393 | C=26 0 3 27 1 2 0 394 | CPC=0 395 | #NT=20015 0 396 | PC=7 397 | name=1 v=5000 position 398 | posx=1 v=2003 -209.931 399 | posy=1 v=2003 -106.352 400 | texcoordname=1 v=5000 position 401 | semantic=1 v=5000 SV_Position 402 | semantictype=1 v=5012 2 403 | tweaktexcoord=1 v=2001 1 404 | group=-1 405 | ISC=2 406 | SVT=5001 5000 1 0 0 407 | SVT=5001 3003 2 0 0 408 | OSC=1 409 | SVT=5001 3003 3 410 | CC=1 411 | C=27 0 3 22 2 2 0 412 | CPC=0 413 | #NT=20106 0 414 | PC=3 415 | name=1 v=5000 uv 416 | posx=1 v=2003 -625.976 417 | posy=1 v=2003 482.909 418 | group=-1 419 | ISC=3 420 | SVT=2002 2002 5 0 0 421 | SVT=5000 5000 6 0 0 422 | SVT=2001 2001 7 0 0 423 | OSC=4 424 | SVT=5001 5000 1 425 | CC=0 426 | SVT=5001 3003 2 427 | CC=0 428 | SVT=5001 3002 3 429 | CC=0 430 | SVT=5001 3001 4 431 | CC=1 432 | C=28 3 4 29 1 2 0 433 | CPC=0 434 | #NT=20015 0 435 | PC=4 436 | posx=1 v=2003 -423.552 437 | posy=1 v=2003 550.06 438 | texcoordname=1 v=5000 uv 439 | tweaktexcoord=1 v=2001 1 440 | group=-1 441 | ISC=2 442 | SVT=5001 5000 1 0 0 443 | SVT=5001 3001 2 0 0 444 | OSC=1 445 | SVT=5001 3001 3 446 | CC=1 447 | C=29 0 3 33 1 2 0 448 | CPC=0 449 | #NT=20159 0 450 | PC=2 451 | posx=1 v=2003 -639.553 452 | posy=1 v=2003 788.727 453 | group=-1 454 | ISC=0 455 | OSC=1 456 | SVT=2002 2002 1 457 | CC=2 458 | C=30 0 1 31 2 4 0 459 | CPC=0 460 | C=30 0 1 32 1 2 0 461 | CPC=0 462 | #NT=20028 0 463 | PC=6 464 | name=1 v=5000 diffuseTexture 465 | posx=1 v=2003 -459.552 466 | posy=1 v=2003 706.061 467 | defineinheader=2 e=0 v=2001 1 468 | texturenodename=2 e=1 v=5000 diffuseTexture 469 | primvariableName=2 e=0 v=5000 diffuseTex 470 | group=-1 471 | ISC=3 472 | SVT=2002 2002 1 0 0 473 | SVT=2002 2002 3 0 0 474 | SVT=2002 2002 4 0 0 475 | OSC=1 476 | SVT=5001 5011 2 477 | CC=2 478 | C=31 0 2 32 0 3 0 479 | CPC=0 480 | C=31 0 2 33 0 1 0 481 | CPC=0 482 | #NT=20092 0 483 | PC=3 484 | name=1 v=5000 diffuseSamplerState 485 | posx=1 v=2003 -282.219 486 | posy=1 v=2003 780.727 487 | group=-1 488 | ISC=2 489 | SVT=5001 5011 3 0 0 490 | SVT=2002 2002 2 0 0 491 | OSC=1 492 | SVT=5001 5013 1 493 | CC=1 494 | C=32 0 1 33 3 4 0 495 | CPC=0 496 | #NT=20029 0 497 | PC=3 498 | name=1 v=5000 diffuseMap 499 | posx=1 v=2003 -70.2185 500 | posy=1 v=2003 668.727 501 | group=-1 502 | ISC=7 503 | SVT=5001 5011 1 0 0 504 | SVT=5001 3001 2 0 0 505 | SVT=5001 2003 3 0 0 506 | SVT=5001 5013 4 0 0 507 | SVT=5001 2002 11 0 0 508 | SVT=5001 2002 12 0 0 509 | SVT=2002 2002 13 0 0 510 | OSC=6 511 | SVT=5001 3003 5 512 | CC=0 513 | SVT=5001 3002 6 514 | CC=1 515 | C=33 1 6 34 1 2 0 516 | CPC=0 517 | SVT=5001 2003 7 518 | CC=0 519 | SVT=5001 2003 8 520 | CC=0 521 | SVT=5001 2003 9 522 | CC=0 523 | SVT=5001 2003 10 524 | CC=0 525 | #NT=20016 0 526 | PC=3 527 | name=1 v=5000 diffColor 528 | posx=1 v=2003 142.575 529 | posy=1 v=2003 619.071 530 | group=-1 531 | ISC=2 532 | SVT=5001 3002 1 0 0 533 | SVT=5001 3002 2 0 0 534 | OSC=1 535 | SVT=5001 3002 3 536 | CC=1 537 | C=34 0 3 11 1 2 0 538 | CPC=0 539 | -------------------------------------------------------------------------------- /shaders/fresnel.sfx: -------------------------------------------------------------------------------- 1 | SFX_WIN 2 | Version=26 3 | GroupVersion=-1.0 4 | Advanced=0 5 | HelpID=0 6 | NumberOfNodes=43 7 | #NT=20011 0 8 | PC=4 9 | name=1 v=5000 ambientColor 10 | posx=1 v=2003 -8.22696 11 | posy=1 v=2003 456.792 12 | defineinheader=2 e=0 v=2001 1 13 | group=-1 14 | ISC=0 15 | OSC=6 16 | SVT=5001 3003 1 17 | CC=0 18 | SVT=5001 3002 2 19 | CC=1 20 | C=0 1 2 10 1 2 0 21 | CPC=0 22 | SVT=5001 2003 3 23 | CC=0 24 | SVT=5001 2003 4 25 | CC=0 26 | SVT=5001 2003 5 27 | CC=0 28 | SVT=5001 2003 6 29 | CC=0 30 | #NT=20011 0 31 | PC=5 32 | name=1 v=5000 diffuseColor 33 | posx=1 v=2003 218.919 34 | posy=1 v=2003 584.086 35 | color=2 e=0 v=3003 1.0,1.0,1.0,1.0 36 | defineinheader=2 e=0 v=2001 1 37 | group=-1 38 | ISC=0 39 | OSC=6 40 | SVT=5001 3003 1 41 | CC=0 42 | SVT=5001 3002 2 43 | CC=1 44 | C=1 1 2 11 1 2 0 45 | CPC=0 46 | SVT=5001 2003 3 47 | CC=0 48 | SVT=5001 2003 4 49 | CC=0 50 | SVT=5001 2003 5 51 | CC=0 52 | SVT=5001 2003 6 53 | CC=0 54 | #NT=20152 0 55 | PC=3 56 | posx=1 v=2003 -1137.52 57 | posy=1 v=2003 186.268 58 | exposesetting=1 v=2001 1 59 | group=-1 60 | ISC=0 61 | OSC=1 62 | SVT=5001 5017 1 63 | CC=1 64 | C=2 0 1 3 0 1 0 65 | CPC=0 66 | #NT=20153 0 67 | PC=2 68 | posx=1 v=2003 -957.462 69 | posy=1 v=2003 178.106 70 | group=-1 71 | ISC=1 72 | SVT=5001 5017 1 0 0 73 | OSC=1 74 | SVT=2002 2002 2 75 | CC=1 76 | C=3 0 2 21 0 1 0 77 | CPC=0 78 | #NT=20008 0 79 | PC=2 80 | posx=1 v=2003 836.165 81 | posy=1 v=2003 98.9912 82 | group=-1 83 | ISC=2 84 | SVT=5001 3003 1 0 0 85 | SVT=5001 2003 3 0 0 86 | OSC=1 87 | SVT=5001 5009 2 88 | CC=1 89 | C=4 0 2 6 4 5 0 90 | CPC=0 91 | #NT=20002 0 92 | PC=3 93 | posx=1 v=2003 1212.79 94 | posy=1 v=2003 18.824 95 | techniquename=1 v=5000 sample 96 | group=-1 97 | ISC=1 98 | SVT=5001 5004 1 0 0 99 | OSC=1 100 | SVT=5001 5003 2 101 | CC=1 102 | C=5 0 2 15 2 2 0 103 | CPC=0 104 | #NT=20003 0 105 | PC=2 106 | posx=1 v=2003 1018.25 107 | posy=1 v=2003 -49.9801 108 | group=-1 109 | ISC=7 110 | SVT=5001 5014 1 0 0 111 | SVT=5001 5005 2 0 0 112 | SVT=5001 5007 3 0 0 113 | SVT=5001 5008 4 0 0 114 | SVT=5001 5009 5 0 0 115 | SVT=5001 5011 7 0 0 116 | SVT=5001 5011 8 0 0 117 | OSC=1 118 | SVT=5001 5004 6 119 | CC=1 120 | C=6 0 6 5 0 1 0 121 | CPC=0 122 | #NT=20021 0 123 | PC=3 124 | name=1 v=5000 worldNormal 125 | posx=1 v=2003 -577.684 126 | posy=1 v=2003 438.149 127 | group=-1 128 | ISC=1 129 | SVT=5001 3002 1 0 0 130 | OSC=1 131 | SVT=5001 3002 2 132 | CC=2 133 | C=7 0 2 8 1 2 0 134 | CPC=0 135 | C=7 0 2 35 1 2 0 136 | CPC=0 137 | #NT=20018 0 138 | PC=2 139 | posx=1 v=2003 -166.521 140 | posy=1 v=2003 299.326 141 | group=-1 142 | ISC=2 143 | SVT=5001 3002 1 0 0 144 | SVT=5001 3002 2 0 0 145 | OSC=1 146 | SVT=5001 2003 3 147 | CC=1 148 | C=8 0 3 9 0 1 0 149 | CPC=0 150 | #NT=20023 0 151 | PC=3 152 | name=1 v=5000 lambert 153 | posx=1 v=2003 46.0805 154 | posy=1 v=2003 317.918 155 | group=-1 156 | ISC=1 157 | SVT=5001 2003 1 0 0 158 | OSC=1 159 | SVT=5001 2003 2 160 | CC=2 161 | C=9 0 2 10 0 1 0 162 | CPC=0 163 | C=9 0 2 42 1 2 0 164 | CPC=0 165 | #NT=20026 0 166 | PC=2 167 | posx=1 v=2003 229.671 168 | posy=1 v=2003 398.507 169 | group=-1 170 | ISC=2 171 | SVT=5001 2003 1 0 0 172 | SVT=5001 3002 2 0 0 173 | OSC=1 174 | SVT=5001 3002 3 175 | CC=1 176 | C=10 0 3 11 0 1 0 177 | CPC=0 178 | #NT=20016 0 179 | PC=3 180 | name=1 v=5000 color 181 | posx=1 v=2003 405.866 182 | posy=1 v=2003 486.067 183 | group=-1 184 | ISC=2 185 | SVT=5001 3002 1 0 0 186 | SVT=5001 3002 2 0 0 187 | OSC=1 188 | SVT=5001 3002 3 189 | CC=1 190 | C=11 0 3 41 0 1 0 191 | CPC=0 192 | #NT=20020 0 193 | PC=3 194 | name=1 v=5000 outColor 195 | posx=1 v=2003 936.469 196 | posy=1 v=2003 479.205 197 | group=-1 198 | ISC=6 199 | SVT=5001 2003 1 0 0 200 | SVT=5001 2003 2 0 0 201 | SVT=5001 3001 3 0 0 202 | SVT=5001 2003 4 0 0 203 | SVT=5001 3002 5 0 0 204 | SVT=5001 2003 6 0 0 205 | OSC=3 206 | SVT=5001 3001 7 207 | CC=0 208 | SVT=5001 3002 8 209 | CC=0 210 | SVT=5001 3003 9 211 | CC=1 212 | C=12 2 9 4 0 1 0 213 | CPC=0 214 | #NT=20017 0 215 | PC=2 216 | posx=1 v=2003 390.797 217 | posy=1 v=2003 670.999 218 | group=-1 219 | ISC=0 220 | OSC=1 221 | SVT=5001 2003 1 222 | CC=1 223 | C=13 0 1 12 5 6 0 224 | CPC=0 225 | #NT=20112 0 226 | PC=2 227 | posx=1 v=2003 -573.904 228 | posy=1 v=2003 245.866 229 | group=-1 230 | ISC=1 231 | SVT=5001 3002 1 0 0 232 | OSC=1 233 | SVT=5001 3002 2 234 | CC=1 235 | C=14 0 2 16 0 1 0 236 | CPC=0 237 | #NT=20001 0 238 | PC=5 239 | posx=1 v=2003 1400.28 240 | posy=1 v=2003 1.79483 241 | config=2 e=0 v=5012 1 242 | saveshadertodisk=2 e=0 v=5015 243 | group=-1 244 | ISC=3 245 | SVT=2002 2002 3 0 0 246 | SVT=5001 5016 1 0 0 247 | SVT=5001 5003 2 0 0 248 | OSC=0 249 | #NT=20021 0 250 | PC=3 251 | name=1 v=5000 lightDir 252 | posx=1 v=2003 -363.199 253 | posy=1 v=2003 266.582 254 | group=-1 255 | ISC=1 256 | SVT=5001 3002 1 0 0 257 | OSC=1 258 | SVT=5001 3002 2 259 | CC=1 260 | C=16 0 2 8 0 1 0 261 | CPC=0 262 | #NT=20014 0 263 | PC=2 264 | posx=1 v=2003 -1164.96 265 | posy=1 v=2003 420.932 266 | group=-1 267 | ISC=0 268 | OSC=2 269 | SVT=5001 3003 1 270 | CC=0 271 | SVT=5001 3002 2 272 | CC=1 273 | C=17 1 2 19 0 1 0 274 | CPC=0 275 | #NT=20064 0 276 | PC=2 277 | posx=1 v=2003 -1156.77 278 | posy=1 v=2003 576.671 279 | group=-1 280 | ISC=0 281 | OSC=1 282 | SVT=5001 4900 1 283 | CC=1 284 | C=18 0 1 19 1 2 0 285 | CPC=0 286 | #NT=20016 0 287 | PC=3 288 | name=1 v=5000 worldNormal 289 | posx=1 v=2003 -962.461 290 | posy=1 v=2003 472.407 291 | group=-1 292 | ISC=2 293 | SVT=5001 3002 1 0 0 294 | SVT=5001 4900 2 0 0 295 | OSC=1 296 | SVT=5001 3002 3 297 | CC=1 298 | C=19 0 3 20 1 2 0 299 | CPC=0 300 | #NT=20015 0 301 | PC=5 302 | name=1 v=5000 worldNormal 303 | posx=1 v=2003 -775.912 304 | posy=1 v=2003 490.107 305 | texcoordname=1 v=5000 worldNormal 306 | tweaktexcoord=1 v=2001 1 307 | group=-1 308 | ISC=2 309 | SVT=5001 5000 1 0 0 310 | SVT=5001 3002 2 0 0 311 | OSC=1 312 | SVT=5001 3002 3 313 | CC=1 314 | C=20 0 3 7 0 1 0 315 | CPC=0 316 | #NT=20130 0 317 | PC=3 318 | posx=1 v=2003 -775.46 319 | posy=1 v=2003 200.679 320 | lightindex=2 e=0 v=2002 1 321 | group=-1 322 | ISC=1 323 | SVT=2002 2002 1 0 0 324 | OSC=1 325 | SVT=5001 3002 2 326 | CC=1 327 | C=21 0 2 14 0 1 0 328 | CPC=0 329 | #NT=20004 0 330 | PC=2 331 | posx=1 v=2003 757.315 332 | posy=1 v=2003 -69.334 333 | group=-1 334 | ISC=3 335 | SVT=5001 3003 1 0 0 336 | SVT=5001 1002 4 0 0 337 | SVT=5001 3003 2 0 0 338 | OSC=1 339 | SVT=5001 5005 3 340 | CC=1 341 | C=22 0 3 6 1 2 0 342 | CPC=0 343 | #NT=20012 0 344 | PC=2 345 | posx=1 v=2003 522.365 346 | posy=1 v=2003 -141.379 347 | group=-1 348 | ISC=0 349 | OSC=2 350 | SVT=5001 3003 1 351 | CC=1 352 | C=23 0 1 22 0 1 0 353 | CPC=0 354 | SVT=5001 3002 2 355 | CC=0 356 | #NT=20012 0 357 | PC=2 358 | posx=1 v=2003 -481.354 359 | posy=1 v=2003 -147.738 360 | group=-1 361 | ISC=0 362 | OSC=2 363 | SVT=5001 3003 1 364 | CC=1 365 | C=24 0 1 26 0 1 0 366 | CPC=0 367 | SVT=5001 3002 2 368 | CC=1 369 | C=24 1 2 29 1 2 0 370 | CPC=0 371 | #NT=20081 0 372 | PC=2 373 | posx=1 v=2003 96.3958 374 | posy=1 v=2003 13.5708 375 | group=-1 376 | ISC=0 377 | OSC=1 378 | SVT=5001 4900 1 379 | CC=1 380 | C=25 0 1 26 1 2 0 381 | CPC=0 382 | #NT=20016 0 383 | PC=3 384 | name=1 v=5000 position 385 | posx=1 v=2003 308.173 386 | posy=1 v=2003 -84.8668 387 | group=-1 388 | ISC=2 389 | SVT=5001 3003 1 0 0 390 | SVT=5001 4900 2 0 0 391 | OSC=1 392 | SVT=5001 3003 3 393 | CC=1 394 | C=26 0 3 27 1 2 0 395 | CPC=0 396 | #NT=20015 0 397 | PC=7 398 | name=1 v=5000 Position 399 | posx=1 v=2003 509.002 400 | posy=1 v=2003 -23.7301 401 | texcoordname=1 v=5000 Position 402 | semantic=1 v=5000 SV_Position 403 | semantictype=1 v=5012 2 404 | tweaktexcoord=1 v=2001 1 405 | group=-1 406 | ISC=2 407 | SVT=5001 5000 1 0 0 408 | SVT=5001 3003 2 0 0 409 | OSC=1 410 | SVT=5001 3003 3 411 | CC=1 412 | C=27 0 3 22 2 2 0 413 | CPC=0 414 | #NT=20061 0 415 | PC=2 416 | posx=1 v=2003 -643.45 417 | posy=1 v=2003 -27.5667 418 | group=-1 419 | ISC=0 420 | OSC=2 421 | SVT=5001 4900 1 422 | CC=1 423 | C=28 0 1 29 0 1 0 424 | CPC=0 425 | SVT=5001 4600 2 426 | CC=0 427 | #NT=20016 0 428 | PC=3 429 | name=1 v=5000 worldSpacePos 430 | posx=1 v=2003 -476.215 431 | posy=1 v=2003 -12.7978 432 | group=-1 433 | ISC=2 434 | SVT=5001 4900 1 0 0 435 | SVT=5001 3002 2 0 0 436 | OSC=1 437 | SVT=5001 3002 3 438 | CC=1 439 | C=29 0 3 32 1 2 0 440 | CPC=0 441 | #NT=20110 0 442 | PC=3 443 | posx=1 v=2003 -474.102 444 | posy=1 v=2003 123.208 445 | previewswatch=1 v=2002 1 446 | group=-1 447 | ISC=1 448 | SVT=5001 4900 1 0 0 449 | OSC=1 450 | SVT=5001 3002 2 451 | CC=1 452 | C=30 0 2 32 0 1 0 453 | CPC=0 454 | #NT=20067 0 455 | PC=2 456 | posx=1 v=2003 -660.235 457 | posy=1 v=2003 89.1949 458 | group=-1 459 | ISC=0 460 | OSC=1 461 | SVT=5001 4900 1 462 | CC=1 463 | C=31 0 1 30 0 1 0 464 | CPC=0 465 | #NT=20022 0 466 | PC=3 467 | name=1 v=5000 eyeVector 468 | posx=1 v=2003 -287.614 469 | posy=1 v=2003 126.344 470 | group=-1 471 | ISC=2 472 | SVT=5001 3002 1 0 0 473 | SVT=5001 3002 2 0 0 474 | OSC=1 475 | SVT=5001 3002 3 476 | CC=1 477 | C=32 0 3 33 1 2 0 478 | CPC=0 479 | #NT=20015 0 480 | PC=5 481 | name=1 v=5000 eyeVector 482 | posx=1 v=2003 -110.462 483 | posy=1 v=2003 127.075 484 | texcoordname=1 v=5000 eyeVector 485 | tweaktexcoord=1 v=2001 1 486 | group=-1 487 | ISC=2 488 | SVT=5001 5000 1 0 0 489 | SVT=5001 3002 2 0 0 490 | OSC=1 491 | SVT=5001 3002 3 492 | CC=1 493 | C=33 0 3 34 0 1 0 494 | CPC=0 495 | #NT=20021 0 496 | PC=3 497 | name=1 v=5000 eyeVector 498 | posx=1 v=2003 68.9176 499 | posy=1 v=2003 160.644 500 | group=-1 501 | ISC=1 502 | SVT=5001 3002 1 0 0 503 | OSC=1 504 | SVT=5001 3002 2 505 | CC=1 506 | C=34 0 2 35 0 1 0 507 | CPC=0 508 | #NT=20018 0 509 | PC=3 510 | name=1 v=5000 fresnel 511 | posx=1 v=2003 236.027 512 | posy=1 v=2003 210.414 513 | group=-1 514 | ISC=2 515 | SVT=5001 3002 1 0 0 516 | SVT=5001 3002 2 0 0 517 | OSC=1 518 | SVT=5001 2003 3 519 | CC=1 520 | C=35 0 3 36 0 1 0 521 | CPC=0 522 | #NT=20023 0 523 | PC=3 524 | name=1 v=5000 fresnel 525 | posx=1 v=2003 413.639 526 | posy=1 v=2003 240.54 527 | group=-1 528 | ISC=1 529 | SVT=5001 2003 1 0 0 530 | OSC=1 531 | SVT=5001 2003 2 532 | CC=1 533 | C=36 0 2 37 1 2 0 534 | CPC=0 535 | #NT=20022 0 536 | PC=3 537 | name=1 v=5000 fresnel 538 | posx=1 v=2003 598.845 539 | posy=1 v=2003 178.092 540 | group=-1 541 | ISC=2 542 | SVT=5001 2003 1 0 0 543 | SVT=5001 2003 2 0 0 544 | OSC=1 545 | SVT=5001 2003 3 546 | CC=1 547 | C=37 0 3 39 0 1 0 548 | CPC=0 549 | #NT=20017 0 550 | PC=2 551 | posx=1 v=2003 421.263 552 | posy=1 v=2003 132.328 553 | group=-1 554 | ISC=0 555 | OSC=1 556 | SVT=5001 2003 1 557 | CC=1 558 | C=38 0 1 37 0 1 0 559 | CPC=0 560 | #NT=20055 0 561 | PC=3 562 | name=1 v=5000 fresnel 563 | posx=1 v=2003 771.617 564 | posy=1 v=2003 242.481 565 | group=-1 566 | ISC=2 567 | SVT=5001 2003 1 0 0 568 | SVT=5001 2003 2 0 0 569 | OSC=1 570 | SVT=5001 2003 3 571 | CC=1 572 | C=39 0 3 42 0 1 0 573 | CPC=0 574 | #NT=20017 0 575 | PC=6 576 | name=1 v=5000 fresnelPower 577 | posx=1 v=2003 585.526 578 | posy=1 v=2003 308.271 579 | value=2 e=0 v=2003 3.0 580 | defineinheader=2 e=0 v=2001 1 581 | uistep=2 e=0 v=2003 1.0 582 | group=-1 583 | ISC=0 584 | OSC=1 585 | SVT=5001 2003 1 586 | CC=1 587 | C=40 0 1 39 1 2 0 588 | CPC=0 589 | #NT=20026 0 590 | PC=3 591 | name=1 v=5000 color 592 | posx=1 v=2003 734.369 593 | posy=1 v=2003 441.637 594 | group=-1 595 | ISC=2 596 | SVT=5001 3002 1 0 0 597 | SVT=5001 2003 2 0 0 598 | OSC=1 599 | SVT=5001 3002 3 600 | CC=1 601 | C=41 0 3 12 4 5 0 602 | CPC=0 603 | #NT=20016 0 604 | PC=3 605 | name=1 v=5000 fresnel 606 | posx=1 v=2003 939.834 607 | posy=1 v=2003 284.232 608 | group=-1 609 | ISC=2 610 | SVT=5001 2003 1 0 0 611 | SVT=5001 2003 2 0 0 612 | OSC=1 613 | SVT=5001 2003 3 614 | CC=1 615 | C=42 0 3 41 1 2 0 616 | CPC=0 617 | -------------------------------------------------------------------------------- /shaders/vertexAnimation.sfx: -------------------------------------------------------------------------------- 1 | SFX_WIN 2 | Version=26 3 | GroupVersion=-1.0 4 | Advanced=0 5 | HelpID=0 6 | NumberOfNodes=41 7 | #NT=20011 0 8 | PC=5 9 | name=1 v=5000 ambientColor 10 | posx=1 v=2003 9.19464 11 | posy=1 v=2003 310.451 12 | color=2 e=0 v=3003 0.317464,0.317464,0.317464,1.0 13 | defineinheader=2 e=0 v=2001 1 14 | group=-1 15 | ISC=0 16 | OSC=6 17 | SVT=5001 3003 1 18 | CC=0 19 | SVT=5001 3002 2 20 | CC=1 21 | C=0 1 2 10 1 2 0 22 | CPC=0 23 | SVT=5001 2003 3 24 | CC=0 25 | SVT=5001 2003 4 26 | CC=0 27 | SVT=5001 2003 5 28 | CC=0 29 | SVT=5001 2003 6 30 | CC=0 31 | #NT=20011 0 32 | PC=5 33 | name=1 v=5000 diffuseColor 34 | posx=1 v=2003 182.031 35 | posy=1 v=2003 480.63 36 | color=2 e=0 v=3003 1.0,1.0,1.0,1.0 37 | defineinheader=2 e=0 v=2001 1 38 | group=-1 39 | ISC=0 40 | OSC=6 41 | SVT=5001 3003 1 42 | CC=0 43 | SVT=5001 3002 2 44 | CC=1 45 | C=1 1 2 11 1 2 0 46 | CPC=0 47 | SVT=5001 2003 3 48 | CC=0 49 | SVT=5001 2003 4 50 | CC=0 51 | SVT=5001 2003 5 52 | CC=0 53 | SVT=5001 2003 6 54 | CC=0 55 | #NT=20152 0 56 | PC=3 57 | posx=1 v=2003 -1120.1 58 | posy=1 v=2003 39.9262 59 | exposesetting=1 v=2001 1 60 | group=-1 61 | ISC=0 62 | OSC=1 63 | SVT=5001 5017 1 64 | CC=1 65 | C=2 0 1 3 0 1 0 66 | CPC=0 67 | #NT=20153 0 68 | PC=2 69 | posx=1 v=2003 -940.04 70 | posy=1 v=2003 31.7645 71 | group=-1 72 | ISC=1 73 | SVT=5001 5017 1 0 0 74 | OSC=1 75 | SVT=2002 2002 2 76 | CC=1 77 | C=3 0 2 21 0 1 0 78 | CPC=0 79 | #NT=20008 0 80 | PC=2 81 | posx=1 v=2003 797.873 82 | posy=1 v=2003 144.947 83 | group=-1 84 | ISC=2 85 | SVT=5001 3003 1 0 0 86 | SVT=5001 2003 3 0 0 87 | OSC=1 88 | SVT=5001 5009 2 89 | CC=1 90 | C=4 0 2 6 4 5 0 91 | CPC=0 92 | #NT=20002 0 93 | PC=3 94 | posx=1 v=2003 1164.43 95 | posy=1 v=2003 16.5409 96 | techniquename=1 v=5000 sample 97 | group=-1 98 | ISC=1 99 | SVT=5001 5004 1 0 0 100 | OSC=1 101 | SVT=5001 5003 2 102 | CC=1 103 | C=5 0 2 15 2 2 0 104 | CPC=0 105 | #NT=20003 0 106 | PC=2 107 | posx=1 v=2003 961.172 108 | posy=1 v=2003 -49.9801 109 | group=-1 110 | ISC=7 111 | SVT=5001 5014 1 0 0 112 | SVT=5001 5005 2 0 0 113 | SVT=5001 5007 3 0 0 114 | SVT=5001 5008 4 0 0 115 | SVT=5001 5009 5 0 0 116 | SVT=5001 5011 7 0 0 117 | SVT=5001 5011 8 0 0 118 | OSC=1 119 | SVT=5001 5004 6 120 | CC=1 121 | C=6 0 6 5 0 1 0 122 | CPC=0 123 | #NT=20021 0 124 | PC=3 125 | name=1 v=5000 worldNormal 126 | posx=1 v=2003 -409.101 127 | posy=1 v=2003 309.9 128 | group=-1 129 | ISC=1 130 | SVT=5001 3002 1 0 0 131 | OSC=1 132 | SVT=5001 3002 2 133 | CC=1 134 | C=7 0 2 8 1 2 0 135 | CPC=0 136 | #NT=20018 0 137 | PC=4 138 | name=1 v=5000 lambert 139 | posx=1 v=2003 -149.099 140 | posy=1 v=2003 152.985 141 | compoundassignment=1 v=2001 1 142 | group=-1 143 | ISC=2 144 | SVT=5001 3002 1 0 0 145 | SVT=5001 3002 2 0 0 146 | OSC=1 147 | SVT=5001 2003 3 148 | CC=1 149 | C=8 0 3 9 0 1 0 150 | CPC=0 151 | #NT=20023 0 152 | PC=4 153 | name=1 v=5000 lambert 154 | posx=1 v=2003 63.5021 155 | posy=1 v=2003 171.577 156 | compoundassignment=1 v=2001 1 157 | group=-1 158 | ISC=1 159 | SVT=5001 2003 1 0 0 160 | OSC=1 161 | SVT=5001 2003 2 162 | CC=1 163 | C=9 0 2 10 0 1 0 164 | CPC=0 165 | #NT=20026 0 166 | PC=2 167 | posx=1 v=2003 247.093 168 | posy=1 v=2003 252.166 169 | group=-1 170 | ISC=2 171 | SVT=5001 2003 1 0 0 172 | SVT=5001 3002 2 0 0 173 | OSC=1 174 | SVT=5001 3002 3 175 | CC=1 176 | C=10 0 3 11 0 1 0 177 | CPC=0 178 | #NT=20016 0 179 | PC=3 180 | name=1 v=5000 color 181 | posx=1 v=2003 423.288 182 | posy=1 v=2003 339.726 183 | group=-1 184 | ISC=2 185 | SVT=5001 3002 1 0 0 186 | SVT=5001 3002 2 0 0 187 | OSC=1 188 | SVT=5001 3002 3 189 | CC=1 190 | C=11 0 3 12 4 5 0 191 | CPC=0 192 | #NT=20020 0 193 | PC=3 194 | name=1 v=5000 outColor 195 | posx=1 v=2003 598.63 196 | posy=1 v=2003 284.931 197 | group=-1 198 | ISC=6 199 | SVT=5001 2003 1 0 0 200 | SVT=5001 2003 2 0 0 201 | SVT=5001 3001 3 0 0 202 | SVT=5001 2003 4 0 0 203 | SVT=5001 3002 5 0 0 204 | SVT=5001 2003 6 0 0 205 | OSC=3 206 | SVT=5001 3001 7 207 | CC=0 208 | SVT=5001 3002 8 209 | CC=0 210 | SVT=5001 3003 9 211 | CC=1 212 | C=12 2 9 4 0 1 0 213 | CPC=0 214 | #NT=20017 0 215 | PC=2 216 | posx=1 v=2003 408.219 217 | posy=1 v=2003 524.657 218 | group=-1 219 | ISC=0 220 | OSC=1 221 | SVT=5001 2003 1 222 | CC=1 223 | C=13 0 1 12 5 6 0 224 | CPC=0 225 | #NT=20112 0 226 | PC=2 227 | posx=1 v=2003 -556.482 228 | posy=1 v=2003 99.5242 229 | group=-1 230 | ISC=1 231 | SVT=5001 3002 1 0 0 232 | OSC=1 233 | SVT=5001 3002 2 234 | CC=1 235 | C=14 0 2 16 0 1 0 236 | CPC=0 237 | #NT=20001 0 238 | PC=4 239 | posx=1 v=2003 1378.13 240 | posy=1 v=2003 0.256368 241 | config=2 e=0 v=5012 1 242 | saveshadertodisk=2 e=0 v=5015 243 | group=-1 244 | ISC=3 245 | SVT=2002 2002 3 0 0 246 | SVT=5001 5016 1 0 0 247 | SVT=5001 5003 2 0 0 248 | OSC=0 249 | #NT=20021 0 250 | PC=3 251 | name=1 v=5000 lightDir 252 | posx=1 v=2003 -347.999 253 | posy=1 v=2003 120.241 254 | group=-1 255 | ISC=1 256 | SVT=5001 3002 1 0 0 257 | OSC=1 258 | SVT=5001 3002 2 259 | CC=1 260 | C=16 0 2 8 0 1 0 261 | CPC=0 262 | #NT=20014 0 263 | PC=3 264 | name=1 v=5000 normal 265 | posx=1 v=2003 -1147.54 266 | posy=1 v=2003 274.591 267 | group=-1 268 | ISC=0 269 | OSC=2 270 | SVT=5001 3003 1 271 | CC=0 272 | SVT=5001 3002 2 273 | CC=1 274 | C=17 1 2 19 0 1 0 275 | CPC=0 276 | #NT=20064 0 277 | PC=2 278 | posx=1 v=2003 -1139.35 279 | posy=1 v=2003 430.329 280 | group=-1 281 | ISC=0 282 | OSC=1 283 | SVT=5001 4900 1 284 | CC=1 285 | C=18 0 1 19 1 2 0 286 | CPC=0 287 | #NT=20016 0 288 | PC=3 289 | name=1 v=5000 normal 290 | posx=1 v=2003 -940.985 291 | posy=1 v=2003 327.417 292 | group=-1 293 | ISC=2 294 | SVT=5001 3002 1 0 0 295 | SVT=5001 4900 2 0 0 296 | OSC=1 297 | SVT=5001 3002 3 298 | CC=1 299 | C=19 0 3 20 1 2 0 300 | CPC=0 301 | #NT=20015 0 302 | PC=5 303 | name=1 v=5000 worldNormal 304 | posx=1 v=2003 -692.148 305 | posy=1 v=2003 328.304 306 | texcoordname=1 v=5000 worldNormal 307 | tweaktexcoord=1 v=2001 1 308 | group=-1 309 | ISC=2 310 | SVT=5001 5000 1 0 0 311 | SVT=5001 3002 2 0 0 312 | OSC=1 313 | SVT=5001 3002 3 314 | CC=1 315 | C=20 0 3 7 0 1 0 316 | CPC=0 317 | #NT=20130 0 318 | PC=3 319 | posx=1 v=2003 -758.038 320 | posy=1 v=2003 54.338 321 | lightindex=2 e=0 v=2002 1 322 | group=-1 323 | ISC=1 324 | SVT=2002 2002 1 0 0 325 | OSC=1 326 | SVT=5001 3002 2 327 | CC=1 328 | C=21 0 2 14 0 1 0 329 | CPC=0 330 | #NT=20004 0 331 | PC=2 332 | posx=1 v=2003 289.742 333 | posy=1 v=2003 -169.04 334 | group=-1 335 | ISC=3 336 | SVT=5001 3003 1 0 0 337 | SVT=5001 1002 4 0 0 338 | SVT=5001 3003 2 0 0 339 | OSC=1 340 | SVT=5001 5005 3 341 | CC=1 342 | C=22 0 3 6 1 2 0 343 | CPC=0 344 | #NT=20012 0 345 | PC=2 346 | posx=1 v=2003 -0.315034 347 | posy=1 v=2003 -303.433 348 | group=-1 349 | ISC=0 350 | OSC=2 351 | SVT=5001 3003 1 352 | CC=1 353 | C=23 0 1 22 0 1 0 354 | CPC=0 355 | SVT=5001 3002 2 356 | CC=0 357 | #NT=20012 0 358 | PC=2 359 | posx=1 v=2003 -1884.98 360 | posy=1 v=2003 -374.722 361 | group=-1 362 | ISC=0 363 | OSC=2 364 | SVT=5001 3003 1 365 | CC=0 366 | SVT=5001 3002 2 367 | CC=1 368 | C=24 1 2 39 0 1 0 369 | CPC=0 370 | #NT=20081 0 371 | PC=2 372 | posx=1 v=2003 -342.299 373 | posy=1 v=2003 26.8906 374 | group=-1 375 | ISC=0 376 | OSC=1 377 | SVT=5001 4900 1 378 | CC=1 379 | C=25 0 1 26 1 2 0 380 | CPC=0 381 | #NT=20016 0 382 | PC=3 383 | name=1 v=5000 position 384 | posx=1 v=2003 -89.8132 385 | posy=1 v=2003 -96.8512 386 | group=-1 387 | ISC=2 388 | SVT=5001 3003 1 0 0 389 | SVT=5001 4900 2 0 0 390 | OSC=1 391 | SVT=5001 3003 3 392 | CC=1 393 | C=26 0 3 27 1 2 0 394 | CPC=0 395 | #NT=20015 0 396 | PC=7 397 | name=1 v=5000 position 398 | posx=1 v=2003 97.7552 399 | posy=1 v=2003 -100.234 400 | texcoordname=1 v=5000 position 401 | semantic=1 v=5000 SV_Position 402 | semantictype=1 v=5012 2 403 | tweaktexcoord=1 v=2001 1 404 | group=-1 405 | ISC=2 406 | SVT=5001 5000 1 0 0 407 | SVT=5001 3003 2 0 0 408 | OSC=1 409 | SVT=5001 3003 3 410 | CC=1 411 | C=27 0 3 22 2 2 0 412 | CPC=0 413 | #NT=20032 0 414 | PC=3 415 | name=1 v=5000 r 416 | posx=1 v=2003 -1335.26 417 | posy=1 v=2003 -354.431 418 | group=-1 419 | ISC=1 420 | SVT=5001 3001 1 0 0 421 | OSC=1 422 | SVT=5001 2003 2 423 | CC=2 424 | C=28 0 2 32 1 2 1 425 | CPC=0 426 | C=28 0 2 37 1 2 0 427 | CPC=0 428 | #NT=20034 0 429 | PC=2 430 | posx=1 v=2003 -899.999 431 | posy=1 v=2003 -177.333 432 | group=-1 433 | ISC=1 434 | SVT=5001 2003 1 0 0 435 | OSC=1 436 | SVT=5001 2003 2 437 | CC=1 438 | C=29 0 2 35 1 2 0 439 | CPC=0 440 | #NT=20017 0 441 | PC=5 442 | name=1 v=5000 PI 443 | posx=1 v=2003 -1272.0 444 | posy=1 v=2003 -441.333 445 | value=2 e=0 v=2003 3.14159 446 | global=1 v=2001 1 447 | group=-1 448 | ISC=0 449 | OSC=1 450 | SVT=5001 2003 1 451 | CC=1 452 | C=30 0 1 32 0 1 0 453 | CPC=0 454 | #NT=20017 0 455 | PC=4 456 | name=1 v=5000 Frequency 457 | posx=1 v=2003 -1292.0 458 | posy=1 v=2003 -206.667 459 | defineinheader=2 e=0 v=2001 1 460 | group=-1 461 | ISC=0 462 | OSC=1 463 | SVT=5001 2003 1 464 | CC=1 465 | C=31 0 1 32 1 2 0 466 | CPC=0 467 | #NT=20016 0 468 | PC=3 469 | posx=1 v=2003 -1069.33 470 | posy=1 v=2003 -205.333 471 | supportmulticonnections=1 v=2001 1 472 | group=-1 473 | ISC=2 474 | SVT=5001 2003 1 0 0 475 | SVT=5001 2003 2 0 0 476 | OSC=1 477 | SVT=5001 2003 3 478 | CC=1 479 | C=32 0 3 29 0 1 0 480 | CPC=0 481 | #NT=20086 0 482 | PC=3 483 | posx=1 v=2003 -1493.28 484 | posy=1 v=2003 -126.667 485 | previewswatch=1 v=2002 1 486 | group=-1 487 | ISC=0 488 | OSC=1 489 | SVT=5001 2003 1 490 | CC=1 491 | C=33 0 1 32 1 2 2 492 | CPC=0 493 | #NT=20017 0 494 | PC=3 495 | posx=1 v=2003 -1491.97 496 | posy=1 v=2003 -28.0 497 | value=2 e=0 v=2003 100.0 498 | group=-1 499 | ISC=0 500 | OSC=1 501 | SVT=5001 2003 1 502 | CC=0 503 | #NT=20016 0 504 | PC=2 505 | posx=1 v=2003 -720.702 506 | posy=1 v=2003 -250.32 507 | group=-1 508 | ISC=2 509 | SVT=5001 2003 1 0 0 510 | SVT=5001 2003 2 0 0 511 | OSC=1 512 | SVT=5001 2003 3 513 | CC=1 514 | C=35 0 3 37 0 1 0 515 | CPC=0 516 | #NT=20017 0 517 | PC=4 518 | name=1 v=5000 Amplitude 519 | posx=1 v=2003 -886.667 520 | posy=1 v=2003 -294.667 521 | defineinheader=2 e=0 v=2001 1 522 | group=-1 523 | ISC=0 524 | OSC=1 525 | SVT=5001 2003 1 526 | CC=1 527 | C=36 0 1 35 0 1 0 528 | CPC=0 529 | #NT=20027 0 530 | PC=3 531 | name=1 v=5000 y 532 | posx=1 v=2003 -541.333 533 | posy=1 v=2003 -193.333 534 | group=-1 535 | ISC=2 536 | SVT=5001 2003 1 0 0 537 | SVT=5001 2003 2 0 0 538 | OSC=1 539 | SVT=5001 2003 3 540 | CC=1 541 | C=37 0 3 38 1 2 0 542 | CPC=0 543 | #NT=20020 0 544 | PC=2 545 | posx=1 v=2003 -344.079 546 | posy=1 v=2003 -202.588 547 | group=-1 548 | ISC=6 549 | SVT=5001 2003 1 0 0 550 | SVT=5001 2003 2 0 0 551 | SVT=5001 3001 3 0 0 552 | SVT=5001 2003 4 0 0 553 | SVT=5001 3002 5 0 0 554 | SVT=5001 2003 6 0 0 555 | OSC=3 556 | SVT=5001 3001 7 557 | CC=0 558 | SVT=5001 3002 8 559 | CC=0 560 | SVT=5001 3003 9 561 | CC=1 562 | C=38 2 9 26 0 1 0 563 | CPC=0 564 | #NT=20108 0 565 | PC=2 566 | posx=1 v=2003 -1702.58 567 | posy=1 v=2003 -468.609 568 | group=-1 569 | ISC=1 570 | SVT=5001 3002 1 0 0 571 | OSC=6 572 | SVT=5001 2003 2 573 | CC=2 574 | C=39 0 2 40 0 1 0 575 | CPC=0 576 | C=39 0 2 38 0 1 0 577 | CPC=0 578 | SVT=5001 2003 3 579 | CC=0 580 | SVT=5001 3001 4 581 | CC=0 582 | SVT=5001 2003 5 583 | CC=2 584 | C=39 3 5 40 1 2 0 585 | CPC=0 586 | C=39 3 5 38 3 4 0 587 | CPC=0 588 | SVT=5001 3002 6 589 | CC=0 590 | SVT=5001 2003 7 591 | CC=0 592 | #NT=20020 0 593 | PC=6 594 | posx=1 v=2003 -1519.94 595 | posy=1 v=2003 -457.736 596 | x=1 v=2003 0.0 597 | y=1 v=2003 0.0 598 | z=1 v=2003 0.0 599 | w=1 v=2003 0.0 600 | group=-1 601 | ISC=6 602 | SVT=5001 2003 1 0 0 603 | SVT=5001 2003 2 0 0 604 | SVT=5001 3001 3 0 0 605 | SVT=5001 2003 4 0 0 606 | SVT=5001 3002 5 0 0 607 | SVT=5001 2003 6 0 0 608 | OSC=3 609 | SVT=5001 3001 7 610 | CC=1 611 | C=40 0 7 28 0 1 0 612 | CPC=0 613 | SVT=5001 3002 8 614 | CC=0 615 | SVT=5001 3003 9 616 | CC=0 617 | -------------------------------------------------------------------------------- /cmdReporterHighlighter.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | 3 | # The MIT License (MIT) 4 | # 5 | # Copyright (c) 2014-2023 Mack Stone 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | # this software and associated documentation files (the "Software"), to deal in 9 | # the Software without restriction, including without limitation the rights to 10 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | # the Software, and to permit persons to whom the Software is furnished to do so, 12 | # subject to the following conditions: 13 | # 14 | # The above copyright notice and this permission notice shall be included in all 15 | # copies or substantial portions of the Software. 16 | # 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | # How to use it 25 | # open script editor and run 26 | # 27 | # import cmdReporterHighlighter as crHighlighter 28 | # crHighlighter.highlightCmdReporter() 29 | # 30 | # using userSetup.py 31 | # added follow line to your userSetup.py 32 | # 33 | # from maya import utils 34 | # import cmdReporterHighlighter as crHighlighter 35 | # utils.executeDeferred(crHighlighter.launchFromCmdWndIcon) 36 | 37 | import sys 38 | import os 39 | import re 40 | import keyword 41 | 42 | from maya import (cmds, mel) 43 | import maya.OpenMayaUI as omui 44 | 45 | try: 46 | from PySide2.QtCore import * 47 | from PySide2.QtGui import * 48 | from PySide2.QtWidgets import * 49 | from shiboken2 import wrapInstance 50 | except ImportError: 51 | from PySide6.QtCore import * 52 | from PySide6.QtGui import * 53 | from PySide6.QtWidgets import * 54 | from shiboken6 import wrapInstance 55 | 56 | def launchFromCmdWndIcon(): 57 | '''launch from maya command line script editor icon.''' 58 | def cmdWnd(arg=None): 59 | cmds.ScriptEditor() 60 | highlightCmdReporter() 61 | 62 | # get command line formLayout 63 | gCommandLineForm = mel.eval('$tempVar = $gCommandLineForm') 64 | commandLineForm = cmds.formLayout(gCommandLineForm, q=1, ca=1)[0] 65 | # get cmdWndIcon button 66 | cmdWndIcon = cmds.formLayout(commandLineForm, q=1, ca=1)[-1] 67 | # change the command of the button 68 | cmds.symbolButton(cmdWndIcon, e=1, c=cmdWnd) 69 | 70 | # change the main manu item command 71 | #menuName = 'wmScriptEditor' 72 | #if cmds.menuItem(menuName, q=1, ex=1): 73 | #cmds.menuItem(menuName, e=1, c=cmdWnd) 74 | 75 | def getMayaWindowWidget(): 76 | '''get maya window widget for Qt''' 77 | mwin = None 78 | try: 79 | mwinPtr = omui.MQtUtil.mainWindow() 80 | mwin = wrapInstance(int(mwinPtr), QMainWindow) 81 | except: 82 | mapp = QApplication.instance() 83 | for widget in mapp.topLevelWidgets(): 84 | if widget.objectName() == 'MayaWindow': 85 | mwin = widget 86 | break 87 | return mwin 88 | 89 | def highlightCmdReporter(): 90 | '''find cmdScrollFieldReporter and highlight it''' 91 | mwin = getMayaWindowWidget() 92 | cmdReporters = cmds.lsUI(type='cmdScrollFieldReporter') 93 | if not cmdReporters: return 94 | # only setup for the first one 95 | cmdReporter = mwin.findChild(QWidget, cmdReporters[0]) 96 | highlighter = Highlighter(parent=mwin) 97 | highlighter.setDocument(cmdReporter.document()) 98 | 99 | class Highlighter(QSyntaxHighlighter): 100 | """syntax highlighter""" 101 | def __init__(self, parent=None): 102 | super(Highlighter, self).__init__(parent) 103 | 104 | self.__rules = [] 105 | 106 | # numeric color 107 | self._numericFormat = QTextCharFormat() 108 | self._numericFormat.setForeground(QColor('#9ACD32')) 109 | 110 | # mel command options started with - 111 | melOpsFormat = QTextCharFormat() 112 | melOpsFormat.setForeground(QColor('#B8860B')) 113 | self.__rules.append((re.compile('-[a-zA-Z]+\\b'), melOpsFormat)) 114 | 115 | # keywords color 116 | self._keywordColor = QColor(0, 128, 255) 117 | 118 | self._numeric() 119 | self._keywordFormat() 120 | self._cmdsFunctionFormat() 121 | 122 | # maya api format 123 | mapiFormat = QTextCharFormat() 124 | mapiFormat.setForeground(self._keywordColor) 125 | self.__rules.append((re.compile('\\bM\\w+\\b'), mapiFormat)) 126 | # Qt 127 | self.__rules.append((re.compile('\\bQ\\w+\\b'), mapiFormat)) 128 | 129 | # quotation 130 | self._quotationFormat = QTextCharFormat() 131 | self._quotationFormat.setForeground(Qt.green) 132 | # quote: "" 133 | self.__rules.append((re.compile('".*"'), self._quotationFormat)) 134 | # single quotes for python: '' 135 | self.__rules.append((re.compile("'.*'"), self._quotationFormat)) 136 | 137 | # sing line comment 138 | self._commentFormat = QTextCharFormat() 139 | # orange red 140 | self._commentFormat.setForeground(QColor(255, 128, 64)) 141 | # // mel comment 142 | self.__rules.append((re.compile('//[^\n]*'), self._commentFormat)) 143 | # # python comment 144 | self.__rules.append((re.compile('#[^\n]*'), self._commentFormat)) 145 | 146 | # function and class format 147 | funcFormat = QTextCharFormat() 148 | funcFormat.setFontWeight(QFont.Bold) 149 | self.__rules.append((re.compile('\\b(\\w+)\(.*\):'), funcFormat)) 150 | 151 | # mel warning 152 | warningFormat = QTextCharFormat() 153 | warningFormat.setForeground(QColor('#FF9ACD32')) 154 | warningFormat.setBackground(Qt.yellow) 155 | warningFormat.setFontWeight(QFont.Bold) 156 | self.__rules.append((re.compile('// Warning:[^\n]*//'), warningFormat)) 157 | 158 | # mel error 159 | errorFormat = QTextCharFormat() 160 | errorFormat.setForeground(QColor('#FF9ACD32')) 161 | errorFormat.setBackground(Qt.red) 162 | errorFormat.setFontWeight(QFont.Bold) 163 | self.__rules.append((re.compile('// Error:[^\n]*//'), errorFormat)) 164 | 165 | # Quotes 166 | self._singleQuotes = QRegExp("'''") 167 | self._doubleQuotes = QRegExp('"""') 168 | 169 | # mel multi-line comment: /* */ 170 | self._melMLComStart = re.compile('/\\*') 171 | self._melMLComEnd = re.compile('\\*/') 172 | 173 | def _numeric(self): 174 | '''set up numeric format''' 175 | num_01 = re.compile('\\b[+-]?[0-9]+[lL]?\\b') 176 | num_02 = re.compile('\\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\\b') 177 | num_03 = re.compile('\\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\\b') 178 | num_regs = (num_01, num_02, num_03) 179 | for nr in num_regs: 180 | self.__rules.append((nr, self._numericFormat)) 181 | 182 | def _keywordFormat(self): 183 | '''set up keyword format''' 184 | # mel keyword 185 | melKeywords = ['false', 'float', 'int', 'matrix', 'off', 'on', 'string', 186 | 'true', 'vector', 'yes', 'alias', 'case', 'catch', 'break', 187 | 'case', 'continue', 'default', 'do', 'else', 'for', 'if', 'in', 188 | 'while', 'alias', 'case', 'catch', 'global', 'proc', 'return', 'source', 'switch'] 189 | # python keyword 190 | pyKeywords = keyword.kwlist + ['False', 'True', 'None'] 191 | 192 | keywords = {}.fromkeys(melKeywords) 193 | keywords.update({}.fromkeys(pyKeywords)) 194 | # keyword format 195 | keywordFormat = QTextCharFormat() 196 | keywordFormat.setForeground(self._keywordColor) 197 | keywordFormat.setFontWeight(QFont.Bold) 198 | kwtext = '\\b(' + "|".join(keywords) + ')\\b' 199 | self.__rules.append((re.compile(kwtext), keywordFormat)) 200 | 201 | def _cmdsFunctionFormat(self): 202 | '''set up maya.cmds functions''' 203 | mayaBinDir = os.path.dirname(sys.executable) 204 | cmdsList = os.path.join(mayaBinDir, 'commandList') 205 | functions = '\\b(' 206 | with open(cmdsList) as phile: 207 | for line in phile: 208 | functions += line.split(' ')[0] + '|' 209 | 210 | # global MEL procedures 211 | melProcedures = cmds.melInfo() 212 | maxlen = 1400 213 | stop = int(len(melProcedures) / maxlen) 214 | melProc = [] 215 | melProc.append('\\b(' + '|'.join(melProcedures[:maxlen]) + ')\\b') 216 | for i in range(1, stop - 1): 217 | start = maxlen * i 218 | end = maxlen * (i + 1) 219 | melProc.append('\\b(' + '|'.join(melProcedures[start:end]) + ')\\b') 220 | melProc.append('\\b(' + '|'.join(melProcedures[maxlen*stop:]) + ')\\b') 221 | 222 | # TODO: should update it when a plug-in was load. 223 | # function from plug-ins 224 | plugins = cmds.pluginInfo(q=1, listPlugins=1) 225 | for plugin in plugins: 226 | funcFromPlugin = cmds.pluginInfo(plugin, q=1, command=1) 227 | if funcFromPlugin: 228 | functions += '|'.join(funcFromPlugin) 229 | functions = functions[:-1] + ')\\b' 230 | 231 | # function format 232 | funcFormat = QTextCharFormat() 233 | funcFormat.setForeground(self._keywordColor) 234 | self.__rules.append((re.compile(functions), funcFormat)) 235 | for mp in melProc: 236 | self.__rules.append((re.compile(mp), funcFormat)) 237 | 238 | def _melMLCommentFormat(self, text): 239 | '''set up mel multi-line comment: /* */''' 240 | startIndex = 0 241 | commentLen = 0 242 | self.setCurrentBlockState(0) 243 | if self.previousBlockState() != 1: 244 | searchStart = self._melMLComStart.search(text) 245 | if searchStart: 246 | startIndex = searchStart.start() 247 | searchEnd = self._melMLComEnd.search(text) 248 | if searchEnd: 249 | commentLen = searchEnd.end() - startIndex 250 | else: 251 | self.setCurrentBlockState(1) 252 | commentLen = len(text) - startIndex 253 | else: 254 | searchEnd = self._melMLComEnd.search(text) 255 | if searchEnd: 256 | commentLen = searchEnd.end() 257 | else: 258 | self.setCurrentBlockState(1) 259 | commentLen = len(text) 260 | if commentLen > 0: 261 | self.setFormat(startIndex, commentLen, self._commentFormat) 262 | 263 | def quotesFormat(self, text, regExp, state): 264 | '''set up single or double quotes strings format''' 265 | if self.previousBlockState() == state: 266 | startIndex = 0 267 | add = 0 268 | else: 269 | startIndex = regExp.indexIn(text) 270 | add = regExp.matchedLength() 271 | 272 | while startIndex >= 0: 273 | end = regExp.indexIn(text, startIndex + add) 274 | if end >= add: 275 | quotesLen = end - startIndex + regExp.matchedLength() 276 | self.setCurrentBlockState(0) 277 | else: 278 | self.setCurrentBlockState(state) 279 | quotesLen = len(text) - startIndex + add 280 | self.setFormat(startIndex, quotesLen, self._quotationFormat) 281 | startIndex = regExp.indexIn(text, startIndex + quotesLen) 282 | 283 | if self.currentBlockState() == state: 284 | return True 285 | else: 286 | return False 287 | 288 | def highlightBlock(self, text): 289 | '''highlight text''' 290 | for regExp, tformat in self.__rules: 291 | match = regExp.search(text) 292 | while match: 293 | self.setFormat(match.start(), match.end() - match.start(), tformat) 294 | match = regExp.search(text, match.end()) 295 | 296 | # blocks 297 | self._melMLCommentFormat(text) 298 | quotesState = self.quotesFormat(text, self._singleQuotes, 2) 299 | if not quotesState: 300 | self.quotesFormat(text, self._doubleQuotes, 3) 301 | --------------------------------------------------------------------------------