#how do i setup opengl for purely fragment shaders

126 messages · Page 1 of 1 (latest)

pure anchor
#

i dont really care about the vertex shader, I know the basics of creating opengl projects with glfw and glad, but the online setup guides seem to always use the vertex shaders for stuff outside of my interests

spark beacon
#

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

pure anchor
#

i came from shadertoy so i honestly have no idea what im doing

pure anchor
#

i'd just like to experiment with ray and path tracing

spark beacon
#

You probably want compute shaders, then. You can do whatever you want in the shader, then write colors to one or more storage images

feral rain
#

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

pure anchor
#

I'll go look at what compute shaders are

feral rain
#

VBOs are just buffers

pure anchor
#

yeah, so near the end of "Hello Triangle"

feral rain
#

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

pure anchor
#

isnt it all contained in the fragment shader tho

feral rain
#

?

#

Isn't what

pure anchor
#

why would i have to organize any data outside of it

feral rain
#

What kind of raytracing are you referring to

#

Raytracing against geometry? Or just doing SDF stuff like shadertoy

pure anchor
#

path tracing with accumulating a buffer then averaging the color in the main

feral rain
#

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

pure anchor
#

i already know how to do it i just have no clue how to implement it in openGL

feral rain
#

You've written software path tracers?

pure anchor
#

yes

feral rain
#

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

pure anchor
#

alreight

feral rain
#

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

spark beacon
#

I believe Raytracing in one Weekend talks about an acceleration structure

#

Might be Raytracing: The Next Week

feral rain
#

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

pure anchor
#

I only ever done stuff in shadertoy

feral rain
#

I thought you said you wrote a software path tracer

pure anchor
#

in shader toy

feral rain
#

No I mean like in C++

pure anchor
#

nahw

feral rain
#

You said you want to trace against geometry right?

pure anchor
#

like spphere and triangle intersetions? yeas

feral rain
#

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

pure anchor
#

damn , so should i still use opengl?

feral rain
#

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

pure anchor
#

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

feral rain
#

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

pure anchor
#

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

feral rain
#

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

pure anchor
#

i see

rose fog
#

You do not need any VBO/VAOs to draw a full-screen triangle, tbh

feral rain
#

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

pure anchor
#

true

timid coyote
#

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

spark beacon
#

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"

timid coyote
#

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

pure anchor
timid coyote
#

if all you want is to play with fragment shaders then you can skip that

pure anchor
#

yea but i need the two triangels for the dipsplay

timid coyote
#

yes, you can do hardcode that in your vertex shader

pure anchor
#

but then i dont know what i need and dont need in my main

#

Im like below noob in openGL and cpp

timid coyote
#

if you want to learn how to use opengl then keep following learnopengl

pure anchor
#

yay

timid coyote
#

buffers aren't technically required for that

pure anchor
#

ig but its cool without shortcuts

timid coyote
#

it all depends on what your goal is

pure anchor
#

My goal is now debugging why i cant have more than one triangle

#

Oop nvm

timid coyote
#

solved?

pure anchor
#

silly me

timid coyote
#

lol

pure anchor
#

I'll skip EBO stuff

timid coyote
#

from the looks of things you can skip the third component of your vertices too

pure anchor
#

wat

#

ohh

#

true

#

Do i really have to turn the shader code into this weird thing every time

timid coyote
#

no

#

you can load shaders from disk just fine

#

or use raw strings

#

people who write shaders like this still just enjoy hurting themselves

pure anchor
#

how

timid coyote
#

I'm sure you are capable of figuring that out without my help :^)

pure anchor
#

okayta

timid coyote
#

no need to spell it out

pure anchor
#

Oh yea i forgot

#

I thought glsl 330 wouldnt support that stuff or something

timid coyote
#

supported since the beginning :)

pure anchor
#

oh i see i cant pass gl_Position

timid coyote
#

pass?

pure anchor
#

out from the vertex shader in to the fragment

timid coyote
#

fragment shaders don't declare it implicitly no

#

you can use gl_FragPos (or smth like that) or just define your own output

#

the former is in screen space however

pure anchor
#

oh cool

#

how do i get window resolution in the fragment

timid coyote
#

a uniform

#

defining your own output would probably be better tho