#how do i setup opengl for purely fragment shaders
126 messages · Page 1 of 1 (latest)
You can't use a fragment shader without a vertex shader
You could draw a full screen triangle with your vertex shader, then do whatever in your fragment shader
You might also be interested in compute shaders
i came from shadertoy so i honestly have no idea what im doing
yea im not interested in rendering stuff through the vertex shader, im ok with the bare minimum to get the fragment shader working
i'd just like to experiment with ray and path tracing
You probably want compute shaders, then. You can do whatever you want in the shader, then write colors to one or more storage images
You can also just render to a fullscreen triangle/quad
But yeah for ray and path tracing compute might be better in the long run
You will have to learn the API at least somewhat to use it though since you're still going to need to be experienced with buffers and the way data is passed to the pipeline so I would recommend with just following the first few chapters of LearnOpenGL to get to that point
And then you'll know everything you need to whip up an environment that's good for RT
I've stopped at around the VBO/VAO stuff because i knew i would never wanna use that
I'll go look at what compute shaders are
VBOs are just buffers
yeah, so near the end of "Hello Triangle"
Which you will need to be intimately familiar with to have any hope of doing serious raytracing
Since that's where you'll be organizing all your data
isnt it all contained in the fragment shader tho
why would i have to organize any data outside of it
What kind of raytracing are you referring to
Raytracing against geometry? Or just doing SDF stuff like shadertoy
path tracing with accumulating a buffer then averaging the color in the main
I would look into raytracing in one weekend or scratchapixel first then
You need to learn how to do it in software before trying to make a GPU implementation
i already know how to do it i just have no clue how to implement it in openGL
You've written software path tracers?
yes
It's not any different mathematically but you need to put all your geometry and acceleration structure into GPU buffers so that they can be accessed as SSBOs in a compute shader
I'm not aware of any guides that teach only the bare minimum necessary for raytracing, I would just progress through the normal usage of the API for a while
alreight
Once you have gotten to UBOs in learnopengl then you can skip to the parts about offscreen rendering and compute shaders
You can put all those things together to implement raytracing
I believe Raytracing in one Weekend talks about an acceleration structure
Might be Raytracing: The Next Week
I'm assuming he's done acceleration structures before
If not then yeah you'll want to learn that on the CPU first
GPU raytracing is a pain in the ass
idk what that is
I only ever done stuff in shadertoy
I thought you said you wrote a software path tracer
in shader toy
No I mean like in C++
nahw
You said you want to trace against geometry right?
like spphere and triangle intersetions? yeas
That requires a ton of work to get running in a performant way
There will be a lot of work involved on the host side to get your data packaged into structures that allow for performant tracing on the GPU
damn , so should i still use opengl?
I don't really know what your goals are
But it sounds like you aren't aware that 90% of real graphics programming happens outside of the shaders
It's only shadertoy where it's all inside the shaders because there is no host application there
i see, I guess I can just create a triangle covering the display. I'll keep going with the regular tutorial path, then see how I can transform it for my interests
Triangle covering the screen is the same, the way you generate the shader invocations doesn't matter
Either way your shader invocations are going to be tracing rays against an acceleration structure of your own construction
If you try to have each invocation just naively recursively trace rays against a flat buffer of geometry it's just going to hang your GPU and get your application killed by the driver lol
oh ok, I just thought the gpu could compute the same equation(fragment shader) much faster and parallelized than a cpu and thats all. Thank you
It can but it's not that simple, the calculation is not very parallel because the rays become incoherent which the GPU struggles with due to its execution model
So for a scene of any complexity you still can't just naively trace rays
Especially recursively
i see
You do not need any VBO/VAOs to draw a full-screen triangle, tbh
No but you will be waist-deep in buffers in general which was why I was saying you'll eventually just need to understand the API in general
It seems unlikely to me that you could find yourself an expert in dealing with buffers and memory in GL without having ever learned the basics of the API along the way
true
actually you can, it just writes (0,0,0,1) into gl_Position and calls it a day. you can see this if you render with GL_POINTS :p
anyway no buffers are needed for this. hardcode your vertices in your vertex shader and index then with gl_VertexID
glDrawArrays works just fine
you'll need a VAO bound, but it can be empty
That sounds like a Nvidia quirk
Chapter 11 of the spec states If the current vertex stage program object has no vertex shader, or no program object is current for the vertex stage, the results of programmable vertex processing are undefined
"undefined" means "Nvidia can emit 0, 0, 0, 1"
hmm maybe
figured that was cannon behaviour since that's what it does for disabled vertex arrays
anyway this just so happens to be one of the extremely few things i actually managed to write about lol
yea well my vertices doesnt render more than one triangle for some reason, ive been following learnOpenGL
if all you want is to play with fragment shaders then you can skip that
yea but i need the two triangels for the dipsplay
yes, you can do hardcode that in your vertex shader
see ^^^
but then i dont know what i need and dont need in my main
Im like below noob in openGL and cpp
if you want to learn how to use opengl then keep following learnopengl
yay
if all you want is to mess with frag shaders and that's it, then this is your shortcut
buffers aren't technically required for that
ig but its cool without shortcuts
it all depends on what your goal is
solved?
silly me
lol
I'll skip EBO stuff
from the looks of things you can skip the third component of your vertices too
wat
ohh
true
Do i really have to turn the shader code into this weird thing every time
no
you can load shaders from disk just fine
or use raw strings
people who write shaders like this still just enjoy hurting themselves
how
I'm sure you are capable of figuring that out without my help :^)
btw gl_Position = vec4(aPos, 1.0); also works
no need to spell it out
supported since the beginning :)
oh i see i cant pass gl_Position
pass?
out from the vertex shader in to the fragment