1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| CCEffect %{ techniques: - name: custom-lighting passes: - vert: custom-vs:vert frag: custom-fs:frag properties: &props mainTexture: { value: white } lightingModel: { value: 0, range: [0, 10] } customParam1: { value: 1.0, range: [0, 2] } customParam2: { value: 1.0, range: [0, 2] } customParam3: { value: 1.0, range: [0, 2] } customColor: { value: [1, 1, 1, 1], editor: { type: color } } }%
CCProgram custom-vs %{ #include <surface-vertex> }%
CCProgram custom-fs %{ #include <surface-fragment> uniform CustomProperties { int lightingModel; float customParam1; float customParam2; float customParam3; vec4 customColor; }; uniform sampler2D mainTexture; vec3 calculateCustomLighting(int model, SurfaceIn In, vec3 albedo, vec3 normal) { vec3 viewDir = normalize(cc_cameraPos.xyz - In.worldPos); vec3 lightDir = normalize(-cc_mainLitDir.xyz); vec3 lightColor = cc_mainLitColor.rgb * cc_mainLitColor.a; switch(model) { case 0: return calculatePBR(albedo, customParam1, customParam2, normal, viewDir, lightDir, lightColor); case 1: return OrenNayarDiffuse(albedo, normal, lightDir, viewDir, customParam1); case 2: return WardAnisotropic(normal, In.worldTangent.xyz, lightDir, viewDir, customParam1, customParam2, customColor.rgb); case 3: return SkinSSS(normal, lightDir, viewDir, albedo, customParam1, customColor.rgb); case 4: return KajiyaKayHair(In.worldTangent.xyz, lightDir, viewDir, albedo, customParam1); case 5: return SilkShading(normal, In.worldTangent.xyz, lightDir, viewDir, albedo, customParam1); case 6: return VelvetShading(normal, lightDir, viewDir, albedo, customParam1); case 7: return CarPaintShading(normal, lightDir, viewDir, albedo, customColor.rgb, customParam1); default: return calculatePBR(albedo, 0.0, 0.5, normal, viewDir, lightDir, lightColor); } } void surf (in SurfaceIn In, inout SurfaceOut Out) { vec4 albedo = texture(mainTexture, In.uv); vec3 normal = normalize(In.worldNormal); vec3 finalColor = calculateCustomLighting(lightingModel, In, albedo.rgb, normal); Out.albedo = vec4(finalColor, albedo.a); Out.normal = normal; } }%
|