MaterialFloat3 CustomExpression0(FMaterialPixelParameters Parameters)
{
return 1;
}

float MyFunction(float a)
{
return a;
}

    return 1;
}

#define Pi 3.14159265359
#define mix lerp

struct Gear
{
float t;			// Time
float teethH;		// Teeth height
float teethR;		// Teeth "roundness"
float teethCount;	// Teeth count
float diskR;		// Inner or outer border radius
float3 color;			// Color
};

float GearFunction(float2 uv, Gear g)
{
float r = length(uv);
float a = atan2(uv.y, uv.x);

// Gear polar function:
//  A sine squashed by a logistic function gives a convincing
//  gear shape!
float p = g.gearR-0.5*g.teethH +
g.teethH/(1.0+exp(g.teethR*sin(g.t + g.teethCount*a)));

float gear = r - p;
float disk = r - g.diskR;

return g.gearR > g.diskR ? max(-disk, gear) : max(disk, -gear);
}

float GearDe(float2 uv, Gear g)
{
float f = GearFunction(uv, g);
float2 eps = float2(0.0001, 0);
GearFunction(uv + eps.xy, g) - GearFunction(uv - eps.xy, g),
GearFunction(uv + eps.yx, g) - GearFunction(uv - eps.yx, g)) / (2.0*eps.x);

}

{
float r = length(uv + float2(0.1,0));
float de = r - g.diskR + 0.0*(g.diskR - g.gearR);
float eps = 0.4*g.diskR;
return smoothstep(eps, 0., abs(de));
}

void DrawGear(inout float3 color, float2 uv, Gear g, float eps)
{
float d = smoothstep(eps, -eps, GearDe(uv, g));
float s = 1.0 - 0.7*GearShadow(uv, g);
color = mix(s*color, g.color, d);
}
float aa()
{
return 0;





float t = 0.5*iTime;

//float uv = 2.0*(fragCoord - 0.5*iResolution.xy)/iResolution.y;
//float eps = 2.0/iResolution.y;
//float2 uv  = UV .xy * ScreenResolution.xy;

// Scene parameters;
float3 base;
base = float3(0.95, 0.7, 0.2);
const float count = 8.0;

Gear outer;
//outer = Gear(0.0, 0.8, 0.08, 4.0, 32.0, 0.9, base);
outer.t=0.0;
outer.gearR=0.8;
outer.teethH=0.08;
outer.teethR=4.0;
outer.teethCount=32.0;
outer.diskR=0.9;
outer.color=base;

Gear inner;
//inner = Gear(0.0, 0.4, 0.08, 4.0, 16.0, 0.3, base);
inner.t=0.0;
inner.gearR=0.4;
inner.teethH=0.08;
inner.teethR=4.0;
inner.teethCount=16.0;
inner.diskR=0.3;
inner.color=base;

// Draw inner gears back to front:
float3 color = float3(0.0,0.0,0.0);
for(float i=0.0; i<count; i++)
{
t += 2.0*Pi/count;
inner.t = 16.0*t;
inner.color = base*(0.35 + 0.6*i/(count-1.0));
DrawGear(color, uv+0.4*float2(cos(t),sin(t)), inner, eps);
}

// Draw outer gear:
DrawGear(color, uv, outer, eps);

return float4(color,1.0);


void FMyCustomShaderModule::StartupModule()
{
// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module
}

PS:调用函数的时候可以把函数放在struct RMfunction{};里，然后实例化RMfunction RM;就可调用里面的函数RM.function();

• 点赞 1
• 评论
• 分享
x

海报分享

扫一扫，分享海报

• 收藏 4
• 手机看

分享到微信朋友圈

x

扫一扫，手机阅读

• 打赏

打赏

萌小蛋

你的鼓励将是我创作的最大动力

C币 余额
2C币 4C币 6C币 10C币 20C币 50C币
• 一键三连

点赞Mark关注该博主, 随时了解TA的最新博文
10-24
09-11 6002

09-02
01-26
04-27
12-18
09-04 7101
09-17 5116
01-12 2896
05-12 3161