|
|
@@ -0,0 +1,83 @@
|
|
|
+## 输入案例
|
|
|
+
|
|
|
+```glsl
|
|
|
+vec2 p=(FC.xy*2.-r)/r.y,l,v=p*(1.-(l+=abs(.7-dot(p,p))))/.2;for(float i;i++<8.;o+=(sin(v.xyyx)+1.)*abs(v.x-v.y)*.2)v+=cos(v.yx*i+vec2(0,i)+t)/i+.7;o=tanh(exp(p.y*vec4(1,-1,-2,0))*exp(-4.*l.x)/o);
|
|
|
+```
|
|
|
+
|
|
|
+## 输出案例
|
|
|
+
|
|
|
+```java
|
|
|
+private static float[] generateFrame(int width, int height, float time) {
|
|
|
+ float[] resolution = {(float) width, (float) height};
|
|
|
+ float[] imageData = new float[width * height * 3];
|
|
|
+ for (int y = 0; y < height; y++) {
|
|
|
+ for (int x = 0; x < width; x++) {
|
|
|
+ // 坐标归一化 (翻转y轴以适应图像坐标系)
|
|
|
+ float[] fragCoord = {(float) x, (float) (height - 1 - y)};
|
|
|
+ float[] p = {
|
|
|
+ (fragCoord[0] * 2.0f - resolution[0]) / resolution[1],
|
|
|
+ (fragCoord[1] * 2.0f - resolution[1]) / resolution[1]
|
|
|
+ };
|
|
|
+ float l = Math.abs(0.7f - dot(p, p));
|
|
|
+ float[] v = {
|
|
|
+ p[0] * (1.0f - l) / 0.2f,
|
|
|
+ p[1] * (1.0f - l) / 0.2f
|
|
|
+ };
|
|
|
+ float[] o = {0.0f, 0.0f, 0.0f, 0.0f}; // 输出颜色
|
|
|
+ // 分形噪声迭代
|
|
|
+ for (int i = 1; i <= 8; i++) {
|
|
|
+ float[] tempV = v.clone();
|
|
|
+ // v += cos(v.yx*i + vec2(0,i) + t)/i + 0.7
|
|
|
+ float[] cosInput = {
|
|
|
+ tempV[1] * i + time, // v.y * i + 0 + t
|
|
|
+ tempV[0] * i + i + time // v.x * i + i + t
|
|
|
+ };
|
|
|
+ float[] cosResult = {
|
|
|
+ (float) Math.cos(cosInput[0]),
|
|
|
+ (float) Math.cos(cosInput[1])
|
|
|
+ };
|
|
|
+ v[0] += cosResult[0] / i + 0.7f;
|
|
|
+ v[1] += cosResult[1] / i + 0.7f;
|
|
|
+ // o += (sin(v.xyyx) + 1.0) * abs(v.x - v.y) * 0.2
|
|
|
+ float[] sinInput = {v[0], v[1], v[1], v[0]}; // v.xyyx
|
|
|
+ float[] sinResult = new float[4];
|
|
|
+ for (int j = 0; j < 4; j++) {
|
|
|
+ sinResult[j] = (float) Math.sin(sinInput[j]);
|
|
|
+ }
|
|
|
+ float absDiff = Math.abs(v[0] - v[1]);
|
|
|
+ for (int j = 0; j < 4; j++) {
|
|
|
+ o[j] += (sinResult[j] + 1.0f) * absDiff * 0.2f;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 最终颜色计算: tanh(exp(p.y*vec4(1,-1,-2,0)) * exp(-4*l) / o)
|
|
|
+ float expL = (float) Math.exp(-4.0f * l);
|
|
|
+ float[] colorComponents = new float[3];
|
|
|
+ float[] multipliers = {1.0f, -1.0f, -2.0f};
|
|
|
+
|
|
|
+ for (int i = 0; i < 3; i++) {
|
|
|
+ float expPy = (float) Math.exp(p[1] * multipliers[i]);
|
|
|
+ colorComponents[i] = expPy * expL / (o[i] + 0.0001f); // 避免除零
|
|
|
+ colorComponents[i] = (float) Math.tanh(colorComponents[i]);
|
|
|
+ // 限制在 [0,1] 范围
|
|
|
+ colorComponents[i] = Math.max(0, Math.min(1, colorComponents[i]));
|
|
|
+ }
|
|
|
+ int index = (y * width + x) * 3;
|
|
|
+ imageData[index] = colorComponents[0]; // R
|
|
|
+ imageData[index + 1] = colorComponents[1]; // G
|
|
|
+ imageData[index + 2] = colorComponents[2]; // B
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return imageData;
|
|
|
+ }
|
|
|
+```
|
|
|
+
|
|
|
+## 实际输入
|
|
|
+
|
|
|
+```glsl
|
|
|
+for(float i,z,d,h;i++<8e1;o+=vec4(9,5,h+t,1)/d)
|
|
|
+{vec3 p=z*normalize(FC.rgb*2.-r.xyy),a;p.z+=9.;a=mix(dot(a+=.5,p)*a,p,sin(h=dot(p,p/p)-t))+cos(h)*cross(a,p);
|
|
|
+for(d=0.;d++<9.;a+=.3*sin(a*d).zxy);z+=d=length(a.xz)/15.;}
|
|
|
+o=tanh(o/1e4);
|
|
|
+```
|
|
|
+
|
|
|
+>参考输入输出的案例,将实际输入的glsl代码翻译为Java代码,仅输出对应的Java方法即可
|