1 / 11

OpenGL

OpenGL . Лекция 7 ( 21.11.2013). RenderMonkey ™ Toolsuite. http://developer.amd.com/resources/archive/archived-tools/gpu-tools-archive/rendermonkey-toolsuite/# download

totie
Download Presentation

OpenGL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. OpenGL Лекция 7 (21.11.2013)

  2. RenderMonkey™ Toolsuite • http://developer.amd.com/resources/archive/archived-tools/gpu-tools-archive/rendermonkey-toolsuite/#download • RenderMonkey is a rich shader development environment for both programmers and artists which facilitates the collaborative creation of real-time shader effects.

  3. RenderMonkey™ Toolsuite

  4. Установка текстуры в качестве константы шейдера • glActiveTexture(GL_TEXTURE0+iTextureUnit); glBindTexture(GL_TEXTURE_2D, uiTexture); glBindSampler(iTextureUnit, uiSampler); • intiSamplerLoc = glGetUniformLocation(spMain.getProgramID(), "gSampler"); • glUniform1i(iSamplerLoc, 0);

  5. Использование текстуры в шейдере. Фрагментный шейдер • in vec2 texCoord; • out vec4 outputColor; • uniform sampler2D gSampler; • void main() • { • outputColor = texture2D(gSampler, texCoord); • }

  6. Использование текстуры в шейдере. Вершинный шейдер • uniform mat4 projectionMatrix; • uniform mat4 modelViewMatrix;   • layout (location = 0) in vec3 inPosition; • layout (location = 1) in vec2 inCoord;   • out vec2 texCoord;   • void main() • { • gl_Position = projectionMatrix*modelViewMatrix*vec4(inPosition, 1.0); • texCoord = inCoord; • }

  7. Пример фрагментного шейдера • #ifdef GL_FRAGMENT_PRECISION_HIGH • precision highp float; • #else • precision mediump float; • #endif • uniform sampler2D BaseMap; • uniform vec4 lightDir; • varying vec2 texCoord; • varying vec3 normal; • void main(void) • { • vec4 base = texture2D(BaseMap, texCoord); • float diffuse = clamp(dot(normalize(normal), vec3(lightDir)), 0.0, 1.0); • gl_FragColor = vec4(0.3 + 0.7 * diffuse) * base; • }

  8. Освещение: Направленный свет Где 'I' - интенсивность отражения (reflection), Ld = диффузный цвет источника (gl_LightSource[0].diffuse), и Md - диффузный коэффициент материала (gl_FrontMaterial.diffuse). Эта формула известна как "LambertianReflection” ("Закон косинуса Ламберта“)

  9. Вершинный шейдер •     void main() {        vec3 normal, lightDir;        vec4 diffuse;        float NdotL;normal = normalize(gl_NormalMatrix * gl_Normal);lightDir = normalize(vec3(gl_LightSource[0].position));NdotL = max(dot(normal, lightDir), 0.0);diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;gl_FrontColor =  NdotL * diffuse;gl_Position = ftransform();    }

  10. Фрагментный шейдер • Всё, что остаётся на долю пикселного шейдера - установить цвет пикселов, используя varying-переменную gl_Color • void main()    {gl_FragColor = gl_Color;    }

  11. Мировое освещение •     void main()    {        vec3 normal, lightDir;        vec4 diffuse, ambient, globalAmbient;        float NdotL;        normal = normalize(gl_NormalMatrix * gl_Normal);lightDir = normalize(vec3(gl_LightSource[0].position));NdotL = max(dot(normal, lightDir), 0.0);        diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;        ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;globalAmbient = gl_LightModel.ambient * gl_FrontMaterial.ambient;gl_FrontColor =  NdotL * diffuse + globalAmbient + ambient;gl_Position = ftransform();    }

More Related