#Shader help

7 messages · Page 1 of 1 (latest)

prisma bloom
#

Hi, new to shaders in general and WGSL. I want to play around with this shader in bevy: https://godotshaders.com/shader/2d-perspective/ so Im gonna have to port it over.

Problem is I have no idea what I'm doing, lol. So im trying my best here to figure it out on my own, but the resources im finding are not being helpful, or its just a skill issue.

But honestly, I feel like if I can just figure out the "setup" portion (where you define the input bindings) I think i can take care of the rest.

So my current questions are:

  1. where can I find the documentation on the @group(x) stuff, cus im not sure which ones to use. Im assuming the bindings are just like array indexes, starting at 0.

So far I have this for the uniform definitions from the godot shader:

@group(2) @binding(0) var<uniform> fov: f32;
@group(2) @binding(1) var<uniform> cull_back: bool;
@group(2) @binding(2) var<uniform> y_rot: f32;
@group(2) @binding(3) var<uniform> x_rot: f32;
@group(2) @binding(4) var<uniform> inset: f32;

Of course, idk if I should be using group 2 for all of them but the answer to this question will help me figure that out.

[gonna ask more question(s) in a second message]

Hei

This shader “fakes” a 3D-camera perspective on CanvasItems. The shader...

#
  1. I'm not sure what the bevy equivalents would be for this part:
varying flat vec2 o;
varying vec3 p;

I know in Godot varying means "To send data from the vertex to the fragment function". But like, the examples i see take in a VertexOutput as a parameter so I figured thats how you would handle it. I haven't defined a vertex function yet, but I see an example in the bevy repo. It looks like I have to make my own VertexOutput and have the vertex function return that, instead of using mesh2d_vertex_output::VertexOutput which is what I copy pasted from a different example. So assuming thats correct, which im sure it is, the only thing that I find puzzling here is the "flat" keyword. Godot docs says Certain values are interpolated during the shading pipeline. You can modify how these interpolations are done by using interpolation qualifiers. Flat: The value is not interpolated. Smooth: The value is interpolated in a perspective-correct fashion. This is the default.
Does bevy do any of that? I guess my implementation of p will need to be interpolated and I dont think the godot shader has the code for that.

blissful blaze
#

Check out the examples under shaders, the docs are quite good. As for your question about bindings and groups — you can usually use the encase crate (DW bevy reexports this) to derive ShaderType (which again, is what the bevy examples use). But, for a deeper understanding try the learn-wgpu or even the crate wgpu-rs’ content and examples. Be warned, it’s not a simple couple of hours in the docs and it’ll all suddenly click kinda thing — shaders are no joke.

#

there's a cheatsheet and a bunch of examples there -- including info on how to 'get data from your rust side of things into a shader'

prisma bloom
blissful blaze
#

Should do