Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: Please help! About BRDF

  1. #11
    Junior Member Regular Contributor
    Join Date
    May 2016
    I don't know about BRDF datasets. All I can imagine is vertex buffers, which is what I have in my code. I haven't gotten around to adding my model class to use Blender models which I did in my DirectX 11 engine. Assimp is a library that people often use to load model data. But at this point, the models in my example code are hand coded by loading vertex buffers. That's basically what something like Assimp is going to do except it builds the vertex buffer for you so you don't have to. It always has to be turned into a vertex buffer before it goes to the graphics card whether you do that or a library does that for you.

    Possibly what you mean with datasets is similar to terrains. I've written on that pretty extensively. Blinn-Phong works fine with terrains. For a terrain, you have an array of data that represents the height of every corner of every square in a grid. All the grid squares are square and equal distance on the X/Z plane, but their Y heights are taken from the array with one value for every corner of every grid square. You build a vertex buffer out of that data and display it. I have XNA code examples of that here.

    Anyway, this should be a direct link to download all of the source code. It's all the files for the engine that calls the GLSL shader including the shader code. It's probably just a little too much code to just copy and paste here. Plus, it uses several libraries. I think it uses GLFW, GLM, GLEW, and FreeImage. That's pretty standard stuff that you would most likely want to use anyway. I think that's all of the libraries. But it's all on the web page where I posted it. There is even a link on the page where I've zipped up the exact versions of the libraries that I used although you might want to go to the websites for each of those libraries and make/build them yourself to produce fresh binaries. There may be newer versions that what I used by now. I had to make/build a few of them myself.

    I've never done cube mapping. I think I mostly understand the basic concept. I used actual textured cubes for my skybox's in the past. I haven't really had a need for cubemaps on any of the projects I've done so far and there were other things that were much more high priority for me to learn. A lot of the PBR stuff seems to use them from what I've observed. So, I may be forced to learn to use cubemaps pretty soon.

    The cubemaps themselves should be just like texturing a cube. I have several here that I used for skybox's. I think that using cubemaps for reflections, it uses a special texture sampler that knows the texture is a cube. GL_TEXTURE_CUBE_MAP and samplercube are a different sampler than I use. I treat the cubemap as a regular 2D texture in the stuff I've done, but I think the cube map sampler works slightly different. Here is what I assume is a pretty good discussion on it having never done it myself.

    Up until I started learning about PBR, the only use for cube maps I knew of were A) an alternate method of making skyboxes and B) reflections. The PBR stuff seems to treat them as light sources. So, I'm not sure exactly how that works. I could imagine that you could take the position of the object in the scene and render 6 different camera shots to build the six sides of the cube. I've considered doing this for other things. Seems awfully expensive to do that for every item in the scene. Still, PBR allows for lots of metalic stuff like chrome which essentially requires that. Graphics cards are getting pretty fast but I can't imagine rendering 6 images for every object in these scene with thousands of objects in the scene just so you can draw 1 frame. I would image they are cheating and only rendering 6 images for the entire scene and reusing them on every object whether they are accurate or not. Until the camera rotates they should be relatively accurate and then you can build another cube. They may even completely cheat and pre-render the single cube. I haven't gotten deep enough into the PBR stuff to see exactly how it's done.

    But PBR seems to work basically the same as using cubemaps for reflection where the light rays are sampled with a cubemap index. The difference being that with reflection that's all it does and with PBR you don't just merely reflect the incoming light ray but choose how much of the ray to reflect, which frequencies of light to reflect in what amount, and how much sub-surface scattering to perform as well as which colors are absorbed. So, you're combining reflection with a bunch of other calculations. The stuff I've seen is Fresnel and Cook-Torrance.

    But from what I've observed recently cube-mapping similar to the way you use it for reflections is at the heart of a lot of the PBR stuff. They just build on that an make it more complex from there. So, understanding cube-mapping is not necessary to understand Blinn-Phong or to implement it. Cube-mapping for reflection has traditionally been used instead of Blinn-Phong I believe, not with it. You could modify the Blinn-Phong shader to use a cube-map instead of a directional light I suppose. I'm not sure if that makes sense. I'm not sure if Blinn-Phong can be modified to use cube-maps the way I've seen them used in PBR. Almost all the PBR stuff I've seen uses Fresnel and Cook-Torrance instead of Blinn-Phong. That's why I don't even tend to think of Blinn-Phong as a BRDF because I don't think it's a PBR BRDF.

    With Blinn-Phong you actually have two types of shading: Gouraud and Blinn-Phong. Gouraud shading draws the model and Blinn-Phong adds the specular highlight to it. I suppose you could use the cube-map to determine the light color of the incoming rays of light rather than a single directional light. Then you would have something much more complex and it would no longer be Gouraud. Probably something more like Cook-Torrance at that point. And then Blinn-Phong probably would no longer make sense.

    The PBR stuff I've seen handles specular entirely differently than Blinn-Phong. In PBR specular becomes micro-surface "roughness" in a calculation that determines on average how much light is reflected and how much is scattered.

    So anyway, I'm not certain if you can combine cube-maps with Blinn-Phong without turning it into something much more like Cook-Torrance or some other algorithm.
    Last edited by BBeck1; 01-18-2017 at 04:55 AM.

  2. #12
    May I ask for a whole project source code of blinn phong or other brdf model with glsl and opengl?
    I want a runnable project to study about that as many shader code given on the web is unable to compile with my environment.

  3. #13
    Junior Member Newbie
    Join Date
    Jan 2017
    BRDF simply is the ratio between the incomping radiance and the out going radiance.. it's hard to use most renderig models assume that the surface is Lambertien where the diffuse radiance is equal and the BRDF of lambertien surface is giving = 1 / Pi (Pi = 3.14....) and for the mirror effect or any refraction they use simple tricks like cube maps and other things.. but you can program a BRDF specialist call this a global illumination algorithms which based on physics and light interaction with the scene and it's ongoing research field. i recommend to you to read Physically Based Rendering : from theory to implementation it is worth it if you are going for the long ride. but if you need something just for the sake of getting the job done please check out this web site :!PBR/Lighting you can find the theory smmury + code c++ opengl and shader 4.x i guess good luck

  4. #14
    Member Regular Contributor
    Join Date
    Jul 2012
    Quote Originally Posted by thedarkknight1717 View Post
    May I ask for a whole project source code of blinn phong or other brdf model with glsl and opengl?
    I want a runnable project to study about that as many shader code given on the web is unable to compile with my environment.
    Since you want a whole project, here it is. You'll have to create an account on github however. And this is big...

    Unreal Engine 4

    I'm not really sure, but I'm almost sure it does some kind of PBR:

    Open X-Ray

  5. #15
    Newbie Newbie
    Join Date
    Feb 2017
    I do not claim this is a perfect not even correct code, but it seems to work fine for me and if it can help you in some way, that'd be great. There are also a loooot of ressources online for BRDF if you google just a little bit, but examples are hard to come by unfortunately.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts