Giter Club home page Giter Club logo

Comments (5)

sotrh avatar sotrh commented on July 19, 2024

The triangle is a rainbow because the GPU interpolates the values between the vertices in a process known as rasterization.

As far as getting access to the pixel coordinate inside the triangle you can use the @builtin(position) decorator on a vec4 to get the pixels coordinates in screen space. It's basically the same as gl_FragPosition in OpenGL.

from learn-wgpu.

pythops avatar pythops commented on July 19, 2024

when using @builtin(position) as input for the fragment shader, what's the coordinates system we're getting there ? is it possible to transform them in clip space ?

from learn-wgpu.

sotrh avatar sotrh commented on July 19, 2024

The coordinate system of @builtin(position) is in screen space, or in other words it uses the pixel coordinates of the viewport. You can transform them back to clip space, but it's simpler to just pass the clip space coords into the fragment shader from the vertex shader.

from learn-wgpu.

sotrh avatar sotrh commented on July 19, 2024

For a little more context in the @builtin(position), the top left corner of the viewport is (0,0) and the bottme right corner is (viewport_width, viewport_height). I believe the z component is the depth/array layer, though I'm not sure.

from learn-wgpu.

pythops avatar pythops commented on July 19, 2024

Thanks so much for your explanations 🙏

from learn-wgpu.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.