Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1075932 Posts in 44152 Topics- by 36119 Members - Latest Member: Royalhandstudios

December 29, 2014, 04:13:51 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Quick Question Regarding Shaders
Pages: [1]
Print
Author Topic: Quick Question Regarding Shaders  (Read 391 times)
okelly4408
Guest
« on: April 15, 2013, 05:36:33 PM »

Hello,
I am trying to understand how to use shaders to calculate noise & terrain values. I was wondering how one "calls in" the shader from their regular class and receives the values that the shader calculates. Sorry for this type of question, it is difficult to find much on this specific subject. Thanks for the help (any language is fine).
Logged
eigenbom
Level 10
*****



View Profile WWW
« Reply #1 on: April 15, 2013, 05:58:31 PM »

Well, usually you'd use the noise values directly to modify the positions of vertices or to colour them etc, so the data would be computed and stay on the GPU. In other words, none of it would come back to the CPU to be used in your main code.

If you really need to compute something on the GPU and feed that back into your CPU code, then you could write the values into a texture and then copy that into an image. How to do it depends on whether you're using OpenGL, DirectX, or a graphics engine. Also see OpenCL for a more generic way to do this.
Logged

BleakProspects
Level 4
****



View Profile WWW Email
« Reply #2 on: April 15, 2013, 06:43:31 PM »

Getting data from the GPU to the CPU is not easy without a GPU programming framework like CUDA or OpenCL. Like Eigenbom said, the only way I can think of doing this is to render a texture to a render target, and then read the texture on the CPU side.
Logged

JakobProgsch
Level 1
*



View Profile Email
« Reply #3 on: April 16, 2013, 12:17:10 AM »

Getting data from the GPU to the CPU is not easy without a GPU programming framework like CUDA or OpenCL.
It is about as easy/hard as it is with cuda or opencl :p. At least in OpenGL you can glGetTexImage to read from a texture, glReadPixels to read from the current framebuffer, glGetBufferSubData to read from a buffer or just map the buffer with glMapBuffer/glMapBufferRange (which tends to give the most control). Also you can use GetTexImage and ReadPixels to copy data into a pixel buffer object and then use the Buffer methods to access those. The only combination of methods OpenCL offers and OpenGL doesn't is directly mapping a texture/image object.
Logged

Crimsontide
Level 3
***


View Profile
« Reply #4 on: April 16, 2013, 02:33:07 AM »

I don't know about OpenCL but I'm pretty sure cuda has memory mapping, so both the CPU and GPU can read/write sections of memory at the same time (which obviously can lead to sychronization issues if you're not careful).
Logged
JakobProgsch
Level 1
*



View Profile Email
« Reply #5 on: April 16, 2013, 03:43:21 AM »

OpenCL as well as OpenGL have a notion of "mapping memory" it doesn't allow concurrent access from cpu and gpu though. Mapped in that case means "mapped for cpu" so trying to launch a kernel/draw call on mapped memory is probably either an error or undefined behavior.
Logged

Crimsontide
Level 3
***


View Profile
« Reply #6 on: April 16, 2013, 06:43:07 AM »

OpenCL as well as OpenGL have a notion of "mapping memory" it doesn't allow concurrent access from cpu and gpu though. Mapped in that case means "mapped for cpu" so trying to launch a kernel/draw call on mapped memory is probably either an error or undefined behavior.

Yes I understand that.  Cuda, if I remember correctly, (its been a while since I used it) has a notion of mapped memory space that can be directly accessed by both the CPU and GPU at the same time.  Different from the OpenGL/OpenCL/DirectX mapping notion.
Logged
okelly4408
Guest
« Reply #7 on: April 16, 2013, 02:03:32 PM »

Ah so what I will do then is just send the vertices to the glsl shaders to have them modified and probably do other calculations on the cpu until I am more comfortable with this. Thanks for all the replies/help, it is greatly appreciated!
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic