Skip to content

TSL: Add support for returning value in Return() #33403

@shotamatsuda

Description

@shotamatsuda

Description

I might be missing something, but TSL doesn't support returning value in the early-return pattern in Fn. Yes, this can be worked around, but it can make the code less organized, and in some cases it may not even be feasible.

The invalid code below:

Fn(([x, y, z]) => {
  If(x.lessThan(0), () => {
    Return(0)
  })
  If(y.lessThan(0), () => {
    Return(0)
  })
  If(z.lessThan(0), () => {
    Return(0)
  })
  return add(x, y, z)
})

must be written as:

Fn(([x, y, z]) => {
  const result = float(0).toVar()
  If(x.lessThan(0).not(), () => {
    If(y.lessThan(0).not(), () => {
      If(z.lessThan(0).not(), () => {
        result.assign(add(x, y, z))
      })
    })
  })
  return result
})

Solution

Add support for returning value in Return().

Alternatives

No response

Additional context

A jsfiddle to demonstrate the issue: https://jsfiddle.net/shotamatsuda/ntp4u9mk/

Metadata

Metadata

Assignees

No one assigned

    Labels

    TSLThree.js Shading Language

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions