{"id":587,"date":"2007-10-10T16:07:23","date_gmt":"2007-10-10T16:07:23","guid":{"rendered":"http:\/\/www.gisdeveloper.co.kr\/?p=587"},"modified":"2025-02-24T12:24:40","modified_gmt":"2025-02-24T03:24:40","slug":"opengl-shader-29","status":"publish","type":"post","link":"http:\/\/www.gisdeveloper.co.kr\/?p=587","title":{"rendered":"OpenGL Shader &#8211; 29"},"content":{"rendered":"<div align=\"center\"><strong>GLSL \uc608\uc81c : Lighting(Spot Light Per Pixel) &#8211; 6\/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 \uac15\uc88c\ub294 \uc774\uc804 \uac15\uc88c\uc5d0\uc11c \uc81c\uacf5\ub418\ub294 \ucf54\ub4dc\uc758\u00a0 90% \uc774\uc0c1\uc758 \ub0b4\uc6a9\uc5d0 \uae30\ubc18\ud558\uace0 \uc788\ub2e4. Point Light\uc640 \ube44\uad50\ud574 Spot Light\uc5d0\uc11c \uc720\uc77c\ud558\uac8c \ucc28\uc774\uc810\uc740, Point Light\ub294 \ubaa8\ub4e0 \ubc29\ud5a5\uc73c\ub85c \ube5b\uc744 \ubc29\uc0ac\ud558\ub294\ub370 \ubc18\ud574\uc11c Spot Light\ub294 \uc81c\ud55c \uc601\uc5ed\uc5d0\ub9cc \ube5b\uc744 \ubc1b\ub294\ub2e4\ub294 \uc810\uc774\ub2e4.<\/p>\n<p>OpenGL \uc5b4\ud50c\ub9ac\ucf00\uc774\uc158\uc758 \uad00\uc810\uc5d0\uc11c \ub2e4\uc74c\uacfc \uac19\uc740 \ucc28\uc774\ub4e4\uc774 \uc788\ub2e4.<\/p>\n<ul>\n<li>Spot Light\ub294 \ubc29\ud5a5\uc744 \uac00\uc9c0\uace0 \uc788\uc73c\uba70(spotDirection) \uc774 \ubc29\ud5a5\uc740 Spot Light\uc758 Cone\uc758 \ucd95\uc774\ub2e4.<\/li>\n<li>Cone\uc758 \uac01\ub3c4\uac00 \uc788\ub2e4. GLSL\uc740 \uc5b4\ud50c\ub9ac\ucf00\uc774\uc158\uc5d0\uc11c \uc9c0\uc815\ub418\uc5b4\uc9c4 \uac83\uc73c\ub85c\uc368\uc640 spotCosCutoff\ub77c\ub294 cosine \ubcc0\uc218\ub85c\uc368, \uc774\ub458 \ubaa8\ub450\ub97c \uc81c\uacf5\ud55c\ub2e4.<\/li>\n<li>\ub9c8\uc9c0\ub9c9\uc73c\ub85c \uac10\uc1c4 \ube44\uc728\uc774 \uc788\ub2e4(spotExponent). \uc608\ub97c\ub4e4\uc5b4\uc11c, \ube5b\uc758 \uac15\ub3c4\uac00 Cone\uc758 \uc6d0 \ubaa8\uc591\uc758 \ubc11\ubc14\ub2e5\uc758 \uc911\uc2ec\uc810\uc73c\ub85c\ubd80\ud130 \uc5b4\ub5a4\uc2dd\uc73c\ub85c \uac10\uc18c\ud558\ub294\uc9c0\ub97c \uce21\uc815\ud558\ub294 \uac83\uc774\ub2e4.<\/li>\n<\/ul>\n<p>\ubc84\ud14d\uc2a4 \uc250\uc774\ub354\ub294 \uc774\uc804 \uac15\uc88c\uc758 Point Light\uc640 \ub3d9\uc77c\ud558\uace0 \ud504\ub808\uadf8\uba3c\ud2b8 \uc250\uc774\ub354\uc5d0\uc11c \uba87\uac00\uc9c0 \ubcc0\uacbd\uc774 \uc788\ub2e4. Diffuse, Specular \uadf8\ub9ac\uace0 Ambient \uc694\uc18c\ub294 \uc624\uc9c1 \ube5b\uc758 Cone\uc758 \uc548\ucabd\uc5d0\uc11c \ud504\ub808\uadf8\uba3c\ud2b8\uc5d0\ub9cc \uc601\ud5a5\uc744 \ubbf8\uce5c\ub2e4. \uadf8\ub7ec\ubbc0\ub85c \uc6b0\ub9ac\uac00 \uba3c\uc800 \ud574\uc57c\ud560 \uccab\ubc88\uc9f8\uac83\uc740 Cone \uc548\ucabd\uc758 \ud504\ub808\uadf8\uba3c\ud2b8\uc758 \uac80\uc0ac\uc774\ub2e4.<\/p>\n<p>\ubc84\ud14d\uc2a4 \ubca1\ud130\uc5d0\uc11c \ube5b \uc0ac\uc774\uc758 Cosine \uac01\ub3c4\uc640 Spot \ubc29\ud5a5\uc740 \ubc18\ub4dc\uc2dc spotCosCutoff\ubcf4\ub2e4 \ub113\uc5b4\uc57c \ud55c\ub2e4. \ub9cc\uc57d \uadf8\ub807\uc9c0 \uc54a\uc73c\uba74, \ud504\ub808\uadf8\uba3c\ud2b8\ub294 Cone\uc758 \ubc14\uae53\uc5d0 \uc788\uace0 \ub2e8\uc9c0 \uc804\uc5ed Ambient \uc694\uc18c\uc758 \uad11\uc6d0 \ud6a8\uacfc\ub9cc \ubc1b\uac8c \ub41c\ub2e4.<\/p>\n<pre><code class=\"html\">    ...\r\n\r\n    n = normalize(normal);\r\n\r\n    \/* compute the dot product between normal and ldir *\/\r\n    NdotL = max(dot(n,normalize(lightDir)),0.0);\r\n\r\n    if (NdotL > 0.0) {\r\n        spotEffect = dot(normalize(gl_LightSource[0].spotDirection), \r\n                         normalize(-lightDir));\r\n        if (spotEffect> gl_LightSource[0].spotCosCutoff) {\r\n\t\r\n            <strong>\/* compute the illumination in here *\/<\/strong>\r\n\r\n        }\r\n    }\r\n\t\r\ngl_FragColor = ...<\/code><\/pre>\n<p>\uc870\ub3c4\uc758 \uacc4\uc0b0\uc740 Point Light\uc758 \uacbd\uc6b0\uc5d0 \ub9e4\uc6b0 \ub9ce\uc774 \ube44\uc2b7\ud55c\ub370, \uc720\uc77c\ud55c \ucc28\uc774\uc810\uc740 \uac10\uc1c4\uac12\uc740 \uc544\ub798\uc758 \uacf5\uc2dd\uc758 Spot Light\uc758 \ud6a8\uacfc(spotEffect)\uc640 \uacf1\ud574\uc838\uc57c \ud55c\ub2e4\ub294 \uac83\uc774\ub2e4.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/1\/1242545046.gif\" alt=\"\" width=\"429\" height=\"47\" \/>spotDirection\uc740 \ube5b\uc758 \uc0c1\ud0dc\ub85c\ubd80\ud130 \uc5bb\uc5b4\uc9c4 \uac12\uc774\uba70, lightDir\uc740 \uad11\uc6d0\uc73c\ub85c\ubd80\ud130 \ubc84\ud14d\uc2a4\uae4c\uc9c0\uc758 \ubca1\ud130\uc774\uba70, spotExp\ub294 Spot\uc758 \uac10\uc1c4\ube44\uc728\uc774\ub2e4. \uc774\uac83 \uc5ed\uc2dc OpenGL\uc758 \uc0c1\ud0dc\ub85c\ubd80\ud130 \uac00\uc838\uc624\uba70, \ube5b\ub4e4\uc758 \uac15\ub3c4\uac00 Cone\uc758 \uc911\uc2ec\uc73c\ub85c\ubd80\ud130 Cone\uc758 \uacbd\uacc4\uae4c\uc9c0 \uc5b4\ub5bb\uac8c \uc810\uc810 \uac10\uc1c4\ud558\ub294\uc9c0\ub97c \uc870\uc815\ud55c\ub2e4. \uac12\uc774 \ud06c\uba74 \ud074\uc218\ub85d \ub354 \ube68\ub9ac \ube5b\uc758 \uac15\ub3c4\uac00 \uac10\uc1c4\ud558\uba70, Zero(0)\uc758 \uc758\ubbf8\ub294 \ube5b\uc758 Cone \uc548\uc5d0\uc11c \uc77c\uc815\ud55c \ube5b\uc758 \uac15\ub3c4\ub97c \uc758\ubbf8\ud55c\ub2e4.<\/p>\n<pre><code class=\"html\">spotEffect = pow(spotEffect, gl_LightSource[0].spotExponent);\r\natt = spotEffect \/ (gl_LightSource[0].constantAttenuation +\r\n      gl_LightSource[0].linearAttenuation * dist +\r\n      gl_LightSource[0].quadraticAttenuation * dist * dist);\r\n\r\ncolor += att * (diffuse * NdotL + ambient);\r\n\r\nhalfV = normalize(halfVector);\r\nNdotHV = max(dot(n,halfV),0.0);\r\ncolor += att * gl_FrontMaterial.specular * \r\n         gl_LightSource[0].specular * \r\n         pow(NdotHV,gl_FrontMaterial.shininess);<\/code><\/pre>\n<p>\uc544\ub798\uc758 \uc774\ubbf8\uc9c0\ub294 OpenGL\uc758 \uace0\uc815\uae30\ub2a5\uc758 \uacb0\uacfc\uc640 \uc6b0\ub9ac\uc758 Spot Light Per Pixel\uc5d0 \ub300\ud55c \uacb0\uacfc\uc774\ub2e4. OpenGL\uc758 \uace0\uc815\uae30\ub2a5\uc740 \ubc84\ud14d\uc2a4\uc5d0 \ub300\ud574\uc11c \ube5b\uc758 \ud6a8\uacfc\ub97c \uacc4\uc0b0\ud558\ub294\ub370 \ubc18\ud574 \uc6b0\ub9ac\uc758 Spot Light\ub294 \ud53d\uc140(\ud504\ub808\uadf8\uba3c\ud2b8)\uc5d0 \ub300\ud574 \ube5b\uc758 \ud6a8\uacfc\ub97c \uacc4\uc0b0\ud55c\ub2e4.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/1\/1244300973.jpg\" alt=\"\" width=\"335\" height=\"153\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>GLSL \uc608\uc81c : Lighting(Spot Light Per Pixel) &#8211; 6\/6 \uc6d0\ubb38 : http:\/\/www.lighthouse3d.com\/opengl\/glsl\/index.php?dirlightpix \uc774 \uac15\uc88c\ub294 \uc774\uc804 \uac15\uc88c\uc5d0\uc11c \uc81c\uacf5\ub418\ub294 \ucf54\ub4dc\uc758\u00a0 90% \uc774\uc0c1\uc758 \ub0b4\uc6a9\uc5d0 \uae30\ubc18\ud558\uace0 \uc788\ub2e4. Point Light\uc640 \ube44\uad50\ud574 Spot Light\uc5d0\uc11c \uc720\uc77c\ud558\uac8c \ucc28\uc774\uc810\uc740, Point Light\ub294 \ubaa8\ub4e0 \ubc29\ud5a5\uc73c\ub85c \ube5b\uc744 \ubc29\uc0ac\ud558\ub294\ub370 \ubc18\ud574\uc11c Spot Light\ub294 \uc81c\ud55c \uc601\uc5ed\uc5d0\ub9cc \ube5b\uc744 \ubc1b\ub294\ub2e4\ub294 \uc810\uc774\ub2e4. OpenGL \uc5b4\ud50c\ub9ac\ucf00\uc774\uc158\uc758 \uad00\uc810\uc5d0\uc11c \ub2e4\uc74c\uacfc \uac19\uc740 \ucc28\uc774\ub4e4\uc774 \uc788\ub2e4. Spot Light\ub294 \ubc29\ud5a5\uc744 \uac00\uc9c0\uace0 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.gisdeveloper.co.kr\/?p=587\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;OpenGL Shader &#8211; 29&#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-587","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\/587","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=587"}],"version-history":[{"count":2,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/587\/revisions"}],"predecessor-version":[{"id":3554,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/587\/revisions\/3554"}],"wp:attachment":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=587"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=587"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=587"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}