首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将着色玩具转移到TouchDesigner

将着色玩具转移到TouchDesigner
EN

Stack Overflow用户
提问于 2022-04-12 20:51:04
回答 1查看 183关注 0票数 1

我要把一些openGL从着色玩具转到TouchDesigner里。我认为问题在于“使用未声明的标识符'wave'”,因为我已经做了最明显的调整。

代码语言:javascript
复制
layout(location = 0) out vec4 fragColor;

uniform vec2 iResolution;
uniform float iTime;
uniform vec4 iMouse;

float material;
float rng;

float map (vec3 p)
{
    // time stretched with noise
    float t = iTime*1. + rng*0.9;
    
    // domain repetition
    float grid = 5.;
    vec3 cell = floor(p/grid);
    p = repeat(p,grid);
    
    // distance from origin
    float dp = length(p);
    
    // rotation parameter
    vec3 angle = vec3(.1,-.5,.1) + dp*.5 + p*.1 + cell;
    
    // shrink sphere size
    float size = sin(rng*3.14);
    
    // stretch sphere
    float wave = sin(-dp*1.+t+hash13(cell)*6.28)*.5;
    
    // kaleidoscopic iterated function
    const int count = 4;
    float a = 1.0;
    float scene = 1000.;
    float shape = 1000.;
    for (int index = 0; index < count; ++index)
    {
        // fold and translate
        p.xz = abs(p.xz)-(.5+wave)*a;
        
        // rotate
        p.xz *= rot(angle.y/a);
        p.yz *= rot(angle.x/a);
        p.yx *= rot(angle.z/a);
        
        // sphere
        shape = length(p)-0.2*a*size;
        
        // material blending
        material = mix(material, float(index), smoothing(shape, scene, 0.3*a));
        
        // add with a blend
        scene = smin(scene, shape, 1.*a);
        
        // falloff transformations
        a /= 1.9;
    }
        
    return scene;
}

// return color from pixel coordinate
void main()
{
    // reset color
    fragColor = vec4(0,0,0,1);
    material = 0.0;
    
    // camera coordinates
    vec2 uv = (gl_FragCoord.xy - iResolution.xy * 0.5) / iResolution.y;
    vec3 eye = vec3(1,1,1.);
    vec3 at = vec3(0,0,0);
    vec3 z = normalize(at-eye);
    vec3 x = normalize(cross(z, vec3(0,1,0)));
    vec3 y = cross(x, z);
    vec3 ray = normalize(vec3(z + uv.x * x + uv.y * y));
    vec3 pos = eye;
    
    // camera control
    vec2 M = 6.28*(iMouse.xy-.5);
    ray.xz *= rot(M.x), pos.xz *= rot(M.x);
    ray.xy *= rot(M.y), pos.xy *= rot(M.y);
    
    // white noise
    vec3 seed = vec3(gl_FragCoord.xy, iTime);
    rng = hash13(seed);
    
    // raymarch
    const float steps = 30.0;
    float index;
    for (index = steps; index > 0.0; --index)
    {
        // volume estimation
        float dist = map(pos);
        if (dist < 0.01)
        {
            break;
        }
        
        // dithering
        dist *= 0.9 + .1 * rng;
        
        // raymarch
        pos += ray * dist;
    }
    
    // ambient occlusion from steps count
    float shade = index/steps;

    // compute normal by NuSan (https://www.shadertoy.com/view/3sBGzV)
    vec2 off=vec2(.001,0);
    vec3 normal = normalize(map(pos)-vec3(map(pos-off.xyy), map(pos-off.yxy), map(pos-off.yyx)));

    // Inigo Quilez color palette (https://iquilezles.org/www/articles/palettes/palettes.htm)
    vec3 tint = .5+.5*cos(vec3(3,2,1)+material*.5+length(pos)*.5);

    // lighting
    float ld = dot(reflect(ray, normal), vec3(0,1,0))*0.5+0.5;
    vec3 light = vec3(1.000,0.502,0.502) * sqrt(ld);
    ld = dot(reflect(ray, normal), vec3(0,0,-1))*0.5+0.5;
    light += vec3(0.400,0.714,0.145) * sqrt(ld)*.5;

    // pixel color
    fragColor.rgb = (tint + light) * shade;

    // temporal buffer
    fragColor = max(fragColor, texture(sTD2DInputs[0], gl_FragCoord.xy/iResolution.xy) - 0.01);
}

像素阴影编译结果:

代码语言:javascript
复制
ERROR: 0:26: Invalid call of undeclared identifier 'repeat'
ERROR: 0:38: Invalid call of undeclared identifier 'hash13'
ERROR: 0:48: Use of undeclared identifier 'wave'
ERROR: 0:51: Invalid call of undeclared identifier 'rot'
ERROR: 0:52: Invalid call of undeclared identifier 'rot'
ERROR: 0:53: Invalid call of undeclared identifier 'rot'
ERROR: 0:59: Invalid call of undeclared identifier 'smoothing'
ERROR: 0:62: Invalid call of undeclared identifier 'smin'
ERROR: 0:90: Invalid call of undeclared identifier 'rot'
ERROR: 0:90: Invalid call of undeclared identifier 'rot'
ERROR: 0:91: Invalid call of undeclared identifier 'rot'
ERROR: 0:91: Invalid call of undeclared identifier 'rot'
ERROR: 0:95: Invalid call of undeclared identifier 'hash13'
EN

回答 1

Stack Overflow用户

发布于 2022-04-12 21:10:34

如果您正在尝试运行这是着色器,请注意它使用的是一个缓冲区(两次传递),而该缓冲区可能漏掉了。

看一下这段视频,在下半部分显示处理一个使用缓冲区(类似于您的)的着色玩具着色器。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71848965

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档