{"id":583,"date":"2007-10-10T14:48:20","date_gmt":"2007-10-10T14:48:20","guid":{"rendered":"http:\/\/www.gisdeveloper.co.kr\/?p=583"},"modified":"2025-02-24T12:24:41","modified_gmt":"2025-02-24T03:24:41","slug":"opengl-shader-28","status":"publish","type":"post","link":"http:\/\/www.gisdeveloper.co.kr\/?p=583","title":{"rendered":"OpenGL Shader &#8211; 28"},"content":{"rendered":"<div align=\"center\"><strong>GLSL \uc608\uc81c : Lighting(Point Light Per Pixel) &#8211; 5\/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 \ud29c\ud130\ub9ac\uc5bc\uc740 Directional Lights\uc758 \ucf54\ub4dc\uc758 99% \uc0c1\ub2f9 \ubd80\ubd84\uc5d0 \uae30\ubc18\ud558\uace0 \uc788\ub2e4. \uc774 \ud29c\ud1a0\ub9ac\uc5bc\uc740 Directional Light\uc640 Point Light\uc758 \ucc28\uc774\uc810\uc5d0 \ub300\ud574 \uae30\ubc18\ud55c\ub2e4. Directional Light\ub294 \ubb34\ud55c\uc774 \uba40\ub9ac \uc788\ub2e4\uace0 \uac00\uc815\ub418\ubbc0\ub85c \ube5b\uc5d0 \ub300\ud55c \uad11\uc120\uc774 \ubaa8\ub4e0 \ubb3c\uccb4\uc5d0 \ub3c4\ub2ec\ud560\ub54c \ud3c9\ud589\ud558\ub2e4.\u00a0 \ubc18\uba74\uc5d0, Point Light\ub294 \uc704\uce58\ub97c \uac00\uc9c0\uace0 \uc788\uc73c\uba70 \ubaa8\ub4e0 \ubc29\ud5a5\uc5d0\uc11c \uad11\uc120\uc744 \ubcf4\ub0b8\ub2e4. \ub354\uc6b1\uc774 Point Light\uc5d0\uc11c\ub294, \ubc84\ud14d\uc2a4\uc640\uc758 \uac70\ub9ac\uac00 \uba40\uc5b4\uc9c8 \uc218 \ub85d \ube5b\uc758 \uac15\ub3c4\uac00 \uac10\uc1c4\ud55c\ub2e4.<\/p>\n<p>OpenGL \uc5b4\ud50c\ub9ac\ucf00\uc774\uc158\uc758 \uad00\uc810\uc73c\ub85c\ubd80\ud130, Directional Light\uc640 Point Light \uc0ac\uc774\uc5d0\ub294 \ub450\uac00\uc9c0 \ucc28\uc774\uc810\uc774 \uc788\ub2e4.<\/p>\n<ul>\n<li>\uad11\uc6d0\uc758 \uc704\uce58 \ud544\ub4dc\uc911 w \uc694\uc18c : Directional Light\uc5d0\uc11c\ub294 \uc774 \uac12\uc740 0\uc774\uc9c0\ub9cc Point Light\uc5d0\uc11c\ub294 1\uc774\ub2e4.<\/li>\n<li>\ube5b\uc758 \uac10\uc1c4\ub294 \uc138\uac1c\uc758 \uacc4\uc218\uc5d0 \uae30\ubc18\ud55c\ub2e4 : \uc0c1\uc218\ud56d, 1\ucc28\ud56d, 2\ucc28\ud56d<\/li>\n<\/ul>\n<p>\uacc4\uc0b0\uc2dd \uad00\uc810\uc5d0\uc11c \uc774\ub4e4 \ucc28\uc774\ub97c \uc0b4\ud3b4\ubd10\uc57c\ud55c\ub2e4. Directional Light\uc758 \uacbd\uc6b0, \ube5b\uc758 \uad11\uc120\uc758 \ubc29\ud5a5\uc740 \ubaa8\ub4e0 \ubc84\ud14d\uc2a4\uc5d0 \ub300\ud574\uc11c \uc77c\uc815\ud558\uc9c0\ub9cc, Point Light\uc758 \uacbd\uc6b0, \ube5b\uc758 \uc704\uce58\uc5d0\uc11c \uc2dc\uc791\ud574\uc11c \uac01 \ubc84\ud14d\uc2a4\uae4c\uc9c0\uc758 \ubca1\ud130\uc774\ub2e4. \uadf8\ub7ec\ubbc0\ub85c \ubc84\ud14d\uc2a4 \uc250\uc774\ub354\uc5d0\uc11c \ubcc0\uacbd\ud574\uc57c\ud560 \uac83\uc740 \ube5b\uc758 \ubc29\ud5a5\uc744 \uacc4\uc0b0\ud558\ub294 \uac83\uc774\ub2e4. \ube5b\uc758 \uac10\uc1c4\ub294 OpenGL\uc5d0\uc11c \ub2e4\uc74c \uacf5\uc2dd\uc5d0 \uae30\ubc18\ud558\uc5ec \uacc4\uc0b0\ub41c\ub2e4.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/1\/1242067915.gif\" alt=\"\" width=\"214\" height=\"71\" \/>k0\uc740 \uc0c1\uc218\ud56d \uac10\uc1c4\uc774\uace0, k1\uc740 1\ucc28\ud56d \uac10\uc1c4, k2\ub294 2\ucc28\ud56d\uac10\uc1c4\uc774\uba70 d\ub294 \ube5b\uc758 \uc704\uce58\uc640 \ubc84\ud14d\uc2a4 \uc0ac\uc774\uc758 \uac70\ub9ac\uc774\ub2e4.<\/p>\n<p>\uc8fc\uc758\ud560\uac83\uc740, \ube5b\uc758 \uac10\uc1c4 \ubaa8\ub378\uc740 \uac70\ub9ac\uc5d0 \ub530\ub978 \uc120\ud615\ud68c\uadc0\uac00 \uc544\ub2c8\ub77c\ub294 \uc810\uc774\ub2e4. \uadf8\ub798\uc11c \ubc84\ud14d\uc2a4\uc5d0 \ub300\ud574 \uac10\uc1c4\ub97c \uacc4\uc0b0\ud560 \uc218 \uc5c6\uc73c\uba70 \ud504\ub808\uadf8\uba3c\ud2b8 \uc250\uc774\ub354\uc5d0\uc11c \ubcf4\uac04\ub41c \uac12\uc744 \uc0ac\uc6a9\ud560 \uc218 \uc5c6\ub2e4. \uadf8\ub7ec\ub098 \uc6b0\ub9ac\ub294 \ubc84\ud14d\uc2a4 \uc250\uc774\ub354\uc5d0\uc11c \uac70\ub9ac\ub97c \uacc4\uc0b0\ud560 \uc218 \uc788\uace0 \ud504\ub808\uadf8\uba3c\ud2b8 \uc250\uc774\ub354\uc5d0\uc11c \ubcf4\uac04\ub41c \uac70\ub9ac\ub97c \uc0ac\uc6a9\ud574 \uac10\uc1c4\ub97c \uacc4\uc0b0\ud560 \uc218 \uc788\ub2e4.<\/p>\n<p>Point Light\uc5d0 \ub300\ud55c \uc0c9\uc0c1\uc5d0 \ub300\ud55c \uacf5\uc2dd\uc740 \ub2e4\uc74c\uacfc \uac19\ub2e4.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/1\/1407993066.jpg\" alt=\"\" width=\"451\" height=\"25\" \/>\uc704\uc758 \uacf5\uc2dd\uc744 \ubcf4\uba74, ambient\ud56d\uc740 \ubc18\ub4dc\uc2dc 2\uac1c\ub85c \ub098\ub220\uc57c \ud55c\ub2e4: \uad11\uc6d0 \ubaa8\ub378 Ambient \uc124\uc815\uc744 \uc774\uc6a9\ud55c \uc804\uc5ed Ambient \ud56d\uacfc \ube5b\uc5d0 \ub300\ud55c \uc77c\ubc18 Ambient \ud56d. \ubc84\ud14d\uc2a4 \uc250\uc774\ub354\ub294 \uc815\ud655\ud558\uac8c Ambient \ud56d\uc758 \uacc4\uc0b0\uc744 \uad6c\ubd84\ud574\uc57c \ud55c\ub2e4. \uc544\ub798\ub294 \uc0c8\ub85c\uc6b4 \ubc84\ud14d\uc2a4 \uc250\uc774\ub354\uc5d0 \ub300\ud55c \ucf54\ub4dc\uc774\ub2e4.<\/p>\n<pre><code class=\"html\">varying vec4 diffuse,ambientGlobal,ambient;\r\nvarying vec3 normal,lightDir,halfVector;\r\nvarying float dist;\r\n\t\r\nvoid main()\r\n{\t\r\n    vec4 ecPos;\r\n    vec3 aux;\r\n\t\t\r\n    normal = normalize(gl_NormalMatrix * gl_Normal);\r\n\t\t\r\n    \/* these are the new lines of code to compute the light's direction *\/\r\n    ecPos = gl_ModelViewMatrix * gl_Vertex;\r\n    aux = vec3(gl_LightSource[0].position-ecPos);\r\n    lightDir = normalize(aux);\r\n    dist = length(aux);\r\n\t\r\n    halfVector = normalize(gl_LightSource[0].halfVector.xyz);\r\n\t\t\r\n    \/* Compute the diffuse, ambient and globalAmbient terms *\/\r\n    diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;\r\n\t\t\r\n    \/* The ambient terms have been separated since one of them *\/\r\n    \/* suffers attenuation *\/\r\n    ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;\r\n    ambientGlobal = gl_LightModel.ambient * gl_FrontMaterial.ambient;\r\n\t\r\n    gl_Position = ftransform();\r\n}<\/code><\/pre>\n<p>\ud504\ub798\uadf8\uba3c\ud2b8 \uc250\uc774\ub354\ub294 \uac10\uc1c4\ub97c \uacc4\uc0b0\ud574\uc57c \ud55c\ub2e4. \ud574\uc11d\ub41c \ube5b\uc758 \ubc29\ud5a5\uc744 \uc815\uaddc\ud654\ub3c4 \ud574\uc57c\ud574\uc57c \ud558\ub294\ub370, \ubc29\ud5a5\uc740 \ubaa8\ub4e0 \ubc84\ud14d\uc2a4\uc5d0 \ub300\ud574\uc11c \ub2e4\ub974\uae30 \ub54c\ubb38\uc774\ub2e4.<\/p>\n<pre><code class=\"html\">varying vec4 diffuse,ambientGlobal, ambient;\r\nvarying vec3 normal,lightDir,halfVector;\r\nvarying float dist;\t\r\n\t\r\nvoid main()\r\n{\r\n    vec3 n,halfV,viewV,ldir;\r\n    float NdotL,NdotHV;\r\n    vec4 color = ambientGlobal;\r\n    float att;\r\n\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\r\n    \/* compute the dot product between normal and normalized lightdir *\/\r\n    NdotL = max(dot(n,normalize(lightDir)),0.0);\r\n\t\r\n    if (NdotL > 0.0) {\r\n        att = 1.0 \/ (gl_LightSource[0].constantAttenuation +\r\n              gl_LightSource[0].linearAttenuation * dist +\r\n              gl_LightSource[0].quadraticAttenuation * dist * dist);\r\n        color += att * (diffuse * NdotL + ambient);\r\n\t\t\r\n        halfV = normalize(halfVector);\r\n        NdotHV = max(dot(n,halfV),0.0);\r\n        color += att * gl_FrontMaterial.specular * \r\n                 gl_LightSource[0].specular * \r\n                 pow(NdotHV,gl_FrontMaterial.shininess);\r\n    }\r\n\r\n    gl_FragColor = color;\r\n}<\/code><\/pre>\n<p>\uc544\ub798\uc758 \uc774\ubbf8\uc9c0\ub294 Point Light\uc640 OpenGL\uc758 \uace0\uc815 \uae30\ub2a5\uc5d0 \uc758\ud574 \uacc4\uc0b0\ub41c \ube5b\uc5d0 \ub300\ud55c \ucc28\uc774\ub97c \ubcf4\uc5ec\uc900\ub2e4. \ud558\ub098\ub294 \ubc84\ud14d\uc2a4\uc5d0 \ub300\ud55c \uad11\uc6d0\uc774\uace0 \ub2e4\ub978 \ud558\ub098\ub294 \uc774 \ud29c\ud130\ub9ac\uc5bc\uc758 \uc250\uc774\ub354\ub97c \uc774\uc6a9\ud55c \ud53d\uc140\uc5d0 \ub300\ud55c \uad11\uc6d0\uc774\ub2e4.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/1\/1006901206.jpg\" alt=\"\" width=\"412\" height=\"143\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>GLSL \uc608\uc81c : Lighting(Point Light Per Pixel) &#8211; 5\/6 \uc6d0\ubb38 : http:\/\/www.lighthouse3d.com\/opengl\/glsl\/index.php?dirlightpix \uc774 \ud29c\ud130\ub9ac\uc5bc\uc740 Directional Lights\uc758 \ucf54\ub4dc\uc758 99% \uc0c1\ub2f9 \ubd80\ubd84\uc5d0 \uae30\ubc18\ud558\uace0 \uc788\ub2e4. \uc774 \ud29c\ud1a0\ub9ac\uc5bc\uc740 Directional Light\uc640 Point Light\uc758 \ucc28\uc774\uc810\uc5d0 \ub300\ud574 \uae30\ubc18\ud55c\ub2e4. Directional Light\ub294 \ubb34\ud55c\uc774 \uba40\ub9ac \uc788\ub2e4\uace0 \uac00\uc815\ub418\ubbc0\ub85c \ube5b\uc5d0 \ub300\ud55c \uad11\uc120\uc774 \ubaa8\ub4e0 \ubb3c\uccb4\uc5d0 \ub3c4\ub2ec\ud560\ub54c \ud3c9\ud589\ud558\ub2e4.\u00a0 \ubc18\uba74\uc5d0, Point Light\ub294 \uc704\uce58\ub97c \uac00\uc9c0\uace0 \uc788\uc73c\uba70 \ubaa8\ub4e0 \ubc29\ud5a5\uc5d0\uc11c \uad11\uc120\uc744 \ubcf4\ub0b8\ub2e4. \ub354\uc6b1\uc774 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.gisdeveloper.co.kr\/?p=583\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;OpenGL Shader &#8211; 28&#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-583","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\/583","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=583"}],"version-history":[{"count":2,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/583\/revisions"}],"predecessor-version":[{"id":3556,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/583\/revisions\/3556"}],"wp:attachment":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=583"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}