0

Basically I am trying to create an SDF shader that runs entirely off a data stream. The problem is the inside the mapping function is a loop to process and unify the data from the various shapes. However the results from each shape need to be stored before they can be combined ideally in an Array making them easier to access in future. However by using an array assignment inside an Array it forces the loop to unroll, and as the number of shapes is not predefined this causes the compilation to fail.

I believe this is due to the shader wanting to run multiple occurances of the loop simultaneously, it is just a shame that the array cannot be accessed by the loop counter on its own, thus preventing data crossover with different iterations, without forcing unrolling.

Does anyone know of a method around this? Is there a different method by which the results can be stored preventing this crossover.

The problem is unrolling the shaders completely means they take 3-5mins to compile when the shapes are coded into the code making its usage impractical. Hence trying to make it totally data driven.

Basically the following code is fine and does not unroll until the commented line is uncommented at which point the shader fails to compile due to forced unrolling.

` for (int h=min(0,shaderData.numFormats); h<shaderData.numFormats;h++) {
        // plus 12 means colors start at position 13 (index 12)  in data floatArray.
        sFormatData format;
        float forCode = da(offset); //fStyle*64.0+fType
        float col0 = da(offset+1.0); //color.rg
        float col1 = da(offset+2.0); //color.bs
        
        int forType=int(mod(forCode,32.0));
        int forStyle=int(floor(mod(forCode/32.0,32.0)));
        float texID=floor(forCode/2048.0);
        format.forType = forType;
        format.forStyle = forStyle;
        format.texID = texID;
        format.color.x = fract(floor(col0/2048.0)/256.0);
        format.color.y = fract(col0/256.0);
        format.color.z = fract(floor(col1/2048.0)/256.0);
        format.color.w = fract(col1/256.0);
        format.color = shaderData.formats[h].color * colAdjustment; // 255->1.0
        offset+=3.0;
        
        if (forType>0) { // these is surface displacement
            // get displacementData
            // is it a texture or a displacement style?
            switch (forType) {
                case 2: //worley (2) worType is format.style
                    format.forData.x =  da(offset); // clamp
                    format.forData.y =  da(offset+1.0); // bumpiness
                    format.forData.z =  0.0; // ?
                    format.forData.w = 0.0; // ?
                    offset+=2.0; break;
                case 3: //texture (3)
                    format.forData.x =  da(offset); // u
                    format.forData.y =  da(offset+1.0); // v
                    format.forData.z =  da(offset+2.0); // bumpiness
                    format.forData.w = 0.0;  // ?
                    offset+=3.0; break;
                case 4: // other function
                    break;
                // etc..
            }
        }
        //shaderData.formats[h] = format;
    }`
Simon
  • 1
  • 1

0 Answers0