Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return a struct from function

Can structs in cg be used for anything outher than declaring pipeline semantics?

I'm using Unity3D and this code throws "Shader error in 'Implicit/Rose': redefinition of 'PetalData' at line 48 (on d3d11)".

How can I make it work? Am I missing something, or it's just a usage not supported by Unity?

struct PetalData {
    half radius;
    half2 center;
}

PetalData GetPetalData (half petalIndex, half totalPetals) {
    half p = petalIndex/totalPetals;
    PetalData petal;
    petal.radius = 0.03 * SShape(p) + 0.01;
    petal.center = sqrt(p) * AngleToDir(petalIndex);
    return petal;
}

half PetalField (half2 topology, PetalData petal) {
    half d = distance(topology, petal.center);
    d /= petal.radius;
    d = 1 - d;
    d *= _Ramp;
    return d;
}
like image 373
Emilio Martinez Avatar asked May 30 '26 07:05

Emilio Martinez


1 Answers

If I'm reading this correctly, I believe your struct definition needs a terminating semicolon.

struct PetalData {
    half radius;
    half2 center;
};
like image 151
Patrick Ferland Avatar answered Jun 01 '26 21:06

Patrick Ferland



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!