{"id":581,"date":"2007-10-10T01:20:12","date_gmt":"2007-10-10T01:20:12","guid":{"rendered":"http:\/\/www.gisdeveloper.co.kr\/?p=581"},"modified":"2025-02-24T12:24:41","modified_gmt":"2025-02-24T03:24:41","slug":"opengl-shader-27","status":"publish","type":"post","link":"http:\/\/www.gisdeveloper.co.kr\/?p=581","title":{"rendered":"OpenGL Shader &#8211; 27"},"content":{"rendered":"<p>&nbsp;<\/p>\n<div align=\"center\"><strong>GLSL \uc608\uc81c : Lighting(Directional Light Per Pixel) &#8211; 3\/6<\/strong><\/div>\n<p>\uc6d0\ubb38 : <a href=\"http:\/\/www.lighthouse3d.com\/opengl\/glsl\/index.php?dirlightpix\">http:\/\/www.lighthouse3d.com\/opengl\/glsl\/index.php?dirlightpix<\/a><\/p>\n<p>\uc774 \uc158\uc139\uc5d0\uc11c\ub294 \uc774\uc804 \uc155\uc13c\uc5d0\uc11c\uc758 \uc250\uc774\ub354\ub97c Directional Light\ub97c \ud53d\uc140 \ub9c8\ub2e4 \uacc4\uc0b0\ud558\ub3c4\ub85d \uc218\uc815\ud560 \uac83\uc774\ub2e4.<\/p>\n<p>\uba3c\uc800 \ubc84\ud14d\uc2a4 \ub2f9 \uc6b0\ub9ac\uac00 \ubc1b\ub294 \uc815\ubcf4\ub97c \uc0b4\ud3b4\ubcf4\uba74, &#8230;<\/p>\n<ul>\n<li>\ubc95\uc120\ubca1\ud130<\/li>\n<li>Half \ubca1\ud130<\/li>\n<li>\ube5b\uc758 \ubc29\ud5a5<\/li>\n<\/ul>\n<p>\ubc95\uc120\ubca1\ud130\ub97c \uce74\uba54\ub77c \uacf5\uac04 \uc88c\ud45c\uacc4\ub85c \ubcc0\ud658\ud558\uace0 \uc815\uaddc\ud654\ud574\uc57c\ud55c\ub2e4. \ub610\ud55c \uc774\ubbf8 \uce74\uba54\ub77c \uacf5\uac04 \uc88c\ud45c\uacc4\uc778 Half \ubca1\ud130\uc640 \ube5b\uc758 \ubc29\ud5a5 \ubca1\ud130 \uc5ed\uc2dc \uc815\uaddc\ud654\ud574\uc57c \ud55c\ub2e4. \uc774\ub4e4 \uc815\uaddc\ud654\ub41c \ubca1\ud130\ub294 \ubcf4\uac04\ub418\uc5b4\uc9c8 \uac83\uc774\uace0 \ud504\ub808\uadf8\uba3c\ud2b8 \uc250\uc774\ub354\ub85c \ubcf4\ub0b4\uc9c0\ub294\ub370, \uc774\ub97c \uc704\ud574\uc11c \uc815\uaddc\ud654\ub41c \ubca1\ud130\ub97c \uc720\uc9c0\ud558\uae30 \uc704\ud574\uc11c varying \ubcc0\uc218\ub97c \uc120\uc5b8\ud560 \ud544\uc694\uac00 \uc788\ub2e4.<\/p>\n<p>\ubc84\ud14d\uc2a4 \uc250\uc774\ub354\uc5d0\uc11c\ub294 \uad11\uc6d0\uc124\uc815\uac12\uacfc \uc7ac\uc9c8\uc744 \uc870\ud569\ud558\ub294 \uba87\uac00\uc9c0 \uc5f0\uc0b0\uc744 \uc218\ud589\ud560 \uc218 \uc788\ub2e4.<\/p>\n<p>\uc544\ub798\ub294 \ubc84\ud14d\uc2a4 \uc250\uc774\ub354\uc758 \ucf54\ub4dc\uc774\ub2e4.<\/p>\n<pre><code class=\"html\">varying vec4 diffuse,ambient;\r\nvarying vec3 normal,lightDir,halfVector;\r\n\t\r\nvoid main()\r\n{\t\r\n    \/* first transform the normal into eye space and \r\n    normalize the result *\/\r\n    normal = normalize(gl_NormalMatrix * gl_Normal);\r\n\t\t\r\n    \/* now normalize the light's direction. Note that \r\n       according to the OpenGL specification, the light \r\n       is stored in eye space. Also since we're talking about \r\n       a directional light, the position field is actually direction *\/\r\n    lightDir = normalize(vec3(gl_LightSource[0].position));\r\n\t\r\n    \/* Normalize the halfVector to pass it to the fragment shader *\/\r\n    halfVector = normalize(gl_LightSource[0].halfVector.xyz);\r\n\t\t\t\t\t\r\n    \/* Compute the diffuse, ambient and globalAmbient terms *\/\r\n    diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;\r\n    ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;\r\n    ambient += gl_LightModel.ambient * gl_FrontMaterial.ambient;\r\n\t\r\n    gl_Position = ftransform();\r\n}<\/code><\/pre>\n<p>\uc774\uc81c \ud504\ub808\uadf8\uba3c\ud2b8 \uc250\uc774\ub354\uc5d0 \ub300\ud574\uc11c \uc0b4\ud3b4\ubcf4\uc790. \ub3d9\uc77c\ud55c Varying \ubcc0\uc218\uac00 \uc120\uc5b8\ub418\uc5b4\uc57c \ud55c\ub2e4. \ubc95\uc120\ubca1\ud130\ub97c \ub2e4\uc2dc \uc815\uaddc\ud654\ud574\uc57c\ud55c\ub2e4. \ud558\uc9c0\ub9cc \ube5b\uc758 \ubc29\ud5a5\ubca1\ud130\ub294 \ub2e4\uc2dc \uc815\uaddc\ud654\ud560 \ud544\uc694\uac00 \uc5c6\ub2e4. \uc6b0\ub9ac\ub294 Directional Light\uc5d0 \ub300\ud574 \uc774\uc57c\uae30 \ud558\uace0 \uc788\uc73c\ubbc0\ub85c \uc774 \ub9c8\uc9c0\ub9c9 \ubca1\ud130\ub294 \ubaa8\ub4e0 \ubc84\ud14d\uc2a4\uc5d0 \uacf5\ud1b5\uc774\ub2e4(\uc329\ub6b1\ub9de\uc740 \ub9d0\uac19\uc740\ub370&#8230;&#8230;. =_=). \ub450\uac1c\uc758 \ub3d9\uc77c\ud55c \ubca1\ud130 \uc0ac\uc774\uc758 \ubcf4\uac04\uc5d0 \ub300\ud55c \uacb0\uacfc\ub294 \uac19\uc740 \ubca1\ud130\uc774\ubbc0\ub85c, \ub2e4\uc2dc \uc815\uaddc\ud654\ud560 \ud544\uc694\uac00 \uc5c6\ub294 \uac83\uc774\ub2e4. \ub2e4\uc74c\uc73c\ub85c \uc6b0\ub9ac\ub294 \ubcf4\uac04\ub418\uace0 \uc815\uaddc\ud654\ub41c \ubc95\uc120\ubca1\ud130\uc640 \ube5b\uc758 \ubc29\ud5a5 \ubca1\ud130\ub97c \ub0b4\uc801\uacc4\uc0b0\ud55c\ub2e4. \uc544\ub798\uac00 \uc5ec\uae30\uc11c \uc5b8\uae09\ud55c \ud504\ub808\uadf8\uba3c\ud2b8 \uc250\uc774\ub354\uc5d0 \ub300\ud55c \uc2dc\uc791 \ubd80\ubd84\uc5d0 \ub300\ud55c \ucf54\ub4dc\uc774\ub2e4.<\/p>\n<pre><code class=\"html\">varying vec4 diffuse,ambient;\r\nvarying vec3 normal,lightDir,halfVector;\r\n\r\nvoid main()\r\n{\r\n    vec3 n,halfV;\r\n    float NdotL,NdotHV;\r\n\t\t\r\n    \/* The ambient term will always be present *\/\r\n    vec4 color = ambient;\r\n\t\t\r\n    \/* a fragment shader can't write a varying variable, hence we need\r\n       a new variable to store the normalized interpolated normal *\/\r\n    n = normalize(normal);\r\n\t\t\r\n    \/* compute the dot product between normal and ldir *\/\r\n    NdotL = max(dot(n,lightDir),0.0);\r\n\t\r\n    ....\r\n}<\/code><\/pre>\n<p>\ub9cc\uc57d NdotL\uc774 0\ubcf4\ub2e4 \ud06c\ub2e4\uba74, Diffuse \uc694\uc18c\ub97c \uacc4\uc0b0\ud574\uc57c \ud558\ub294\ub370, \ubc84\ud14d\uc2a4 \uc250\uc774\ub354\ub85c\ubd80\ud130 \ubc1b\uc740 Diffuse \uc124\uc815\uac12\uc740 \ub0b4\uc801\uac12\uc73c\ub85c \uacf1\ud574\uc9c4\ub2e4. Specular \uc694\uc18c\ub3c4 \ubc18\ub4dc\uc2dc \uacc4\uc0b0\ud574\uc57c \ud55c\ub2e4. Specular \uc694\uc18c\ub97c \uacc4\uc0b0\ud558\uae30 \uc704\ud574\uc11c\ub294 \uba3c\uc800 \ubc84\ud14d\uc2a4 \uc250\uc774\ub354\ub85c\ubd80\ud130 \ubc1b\uc740 halfVector\ub97c \uc815\uaddc\ud654\ud574\uc57c\ud558\uace0, halfVector\uc640 normal \uac04\uc758 \ub0b4\uc801 \uacc4\uc0b0\uc744 \ud55c\ub2e4.<\/p>\n<pre><code class=\"html\">    ....\r\n\r\n    if (NdotL > 0.0) {\r\n        color += diffuse * NdotL;\r\n        halfV = normalize(halfVector);\r\n        NdotHV = max(dot(n,halfV),0.0);\r\n        color += gl_FrontMaterial.specular * \r\n        gl_LightSource[0].specular * \r\n        pow(NdotHV, gl_FrontMaterial.shininess);\r\n    }\r\n\t\r\n    gl_FragColor = color;\r\n}\r\n<\/code><\/pre>\n<p>\ub2e4\uc74c \uc774\ubbf8\uc9c0\ub294 Per Pixel\uacfc Per Vertex \uad11\uc6d0\uc5d0 \ub300\ud55c \uacb0\uacfc\ud654\uba74\uc774\ub2e4.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/1\/1328828940.jpg\" alt=\"\" width=\"300\" height=\"109\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; GLSL \uc608\uc81c : Lighting(Directional Light Per Pixel) &#8211; 3\/6 \uc6d0\ubb38 : http:\/\/www.lighthouse3d.com\/opengl\/glsl\/index.php?dirlightpix \uc774 \uc158\uc139\uc5d0\uc11c\ub294 \uc774\uc804 \uc155\uc13c\uc5d0\uc11c\uc758 \uc250\uc774\ub354\ub97c Directional Light\ub97c \ud53d\uc140 \ub9c8\ub2e4 \uacc4\uc0b0\ud558\ub3c4\ub85d \uc218\uc815\ud560 \uac83\uc774\ub2e4. \uba3c\uc800 \ubc84\ud14d\uc2a4 \ub2f9 \uc6b0\ub9ac\uac00 \ubc1b\ub294 \uc815\ubcf4\ub97c \uc0b4\ud3b4\ubcf4\uba74, &#8230; \ubc95\uc120\ubca1\ud130 Half \ubca1\ud130 \ube5b\uc758 \ubc29\ud5a5 \ubc95\uc120\ubca1\ud130\ub97c \uce74\uba54\ub77c \uacf5\uac04 \uc88c\ud45c\uacc4\ub85c \ubcc0\ud658\ud558\uace0 \uc815\uaddc\ud654\ud574\uc57c\ud55c\ub2e4. \ub610\ud55c \uc774\ubbf8 \uce74\uba54\ub77c \uacf5\uac04 \uc88c\ud45c\uacc4\uc778 Half \ubca1\ud130\uc640 \ube5b\uc758 \ubc29\ud5a5 \ubca1\ud130 \uc5ed\uc2dc &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.gisdeveloper.co.kr\/?p=581\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;OpenGL Shader &#8211; 27&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,153],"tags":[3,25],"class_list":["post-581","post","type-post","status-publish","format-standard","hentry","category-opengl","category-shader","tag-opengl","tag-shader"],"_links":{"self":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/581","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=581"}],"version-history":[{"count":1,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/581\/revisions"}],"predecessor-version":[{"id":3557,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/581\/revisions\/3557"}],"wp:attachment":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=581"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=581"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=581"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}