Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TSL texture reading / passed as argument in Fn does not work #30133

Open
Samsy opened this issue Dec 16, 2024 · 5 comments
Open

TSL texture reading / passed as argument in Fn does not work #30133

Samsy opened this issue Dec 16, 2024 · 5 comments
Labels
Enhancement TSL Three.js Shading Language

Comments

@Samsy
Copy link
Contributor

Samsy commented Dec 16, 2024

Description

Hello there !

Sampling a texture via inline materialnode look straightforward :

const uTex = texture( tex );

material.colorNode = uTex.sample(oneMinus( uv() ));

Using Fn and passing a texture as argument makes it challenging and not working ( tdisp.sample is not a function ) :

 const sampleTex = Fn(([tdisp])=> {
    
      	return tdisp.sample(oneMinus( uv() ) )
        
}).setLayout( {
        name: 'sampleTex',
        type: 'float',
        inputs: [
          {
            name: "sampleTex",
            //type: "texture"
            type: "sampler2D"
          }
        ]
} )


material.colorNode = Fn(()=>{

        return sampleTex(uTex)

})()

Been looking at the example folder, and there is no example of passing a texture in a Fn

The transpiler gives wrong results :

Screenshot 2024-12-16 at 11 02 45

But also, it all seems unclear how to use textures as uniforms / in nodes,

To test you can move the CASE variable from 0 to 1

Live example

https://jsfiddle.net/0w3mhbfa/107/

Screenshots

No response

Version

last

Device

Desktop

Browser

Chrome

OS

MacOS

@Mugen87 Mugen87 added the TSL Three.js Shading Language label Dec 16, 2024
@Samsy
Copy link
Contributor Author

Samsy commented Dec 23, 2024

Hey hello @sunag !

Bumping into this problem quite a few times,
Main trouble is, at the moment we can't defines a TSL Fn on an external file that are using a texture as input which makes it difficult to impossible a Fn library of nodes

@sunag
Copy link
Collaborator

sunag commented Dec 23, 2024

This feature is on the roadmap, for now you can use it without .setLayout().

@Samsy
Copy link
Contributor Author

Samsy commented Dec 23, 2024

Hey @sunag !

Thanks for the reply !

Here is the fiddle with the problem :

Screenshot 2024-12-23 at 15 08 13

tdisp.sampleis undefined

And I could not find any examples in the repo or the wiki passing a texture as an args into the setLayout

https://jsfiddle.net/0w3mhbfa/107/

Edit :

Sorry I mis-red your answer, I'll check without the setLayout

@Samsy
Copy link
Contributor Author

Samsy commented Dec 23, 2024

@sunag

Well, for my use-case I did try to implement without the setLayout, but using Fn without setlayout also does not work :

https://jsfiddle.net/yhp1gt0L/2/

It certainly work using inlines, but then it is not possible to assign / instantiate properties, varyings etc..

@sunag
Copy link
Collaborator

sunag commented Dec 23, 2024

Try using Fn( [ params ] ) => in Fn declaration: https://jsfiddle.net/zroj0bqv/1/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement TSL Three.js Shading Language
Projects
None yet
Development

No branches or pull requests

3 participants