• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Code Knight

            Programming is so cool
            隨筆 - 52, 文章 - 0, 評(píng)論 - 14, 引用 - 0
            數(shù)據(jù)加載中……

            圖形學(xué)學(xué)習(xí)筆記2(cel-shading分析)

             

            參看word文檔
            // -------------------------------

            // Cel Shading Section

            // -------------------------------

            vertex_program Ogre/CelShadingVP cg

            {

                source Example_CelShading.cg

                entry_point main_vp

                profiles vs_1_1 arbvp1

             

                default_params

                {

                    param_named_auto lightPosition light_position_object_space 0        param_named_auto eyePosition camera_position_object_space

                    param_named_auto worldViewProj worldviewproj_matrix

                    param_named shininess float 10

                }

            }

             

            fragment_program Ogre/CelShadingFP cg

            {

                source Example_CelShading.cg

                entry_point main_fp

                profiles ps_1_1 arbfp1 fp20

            }

             

             

            material Examples/CelShading

            {

                technique

                {

                    pass

                    {

                        vertex_program_ref Ogre/CelShadingVP

                        {

                            // map shininess from custom renderable param 1

                            param_named_auto shininess custom 1

            // 終于知道param_named_auto第三個(gè)參數(shù)的作用了,用于給程序中賦值的索引

            sub->setCustomParameter(CUSTOM_SHININESS, Vector4(10.0f, 0.0f, 0.0f, 0.0f)); CUSTOM_SHININESS == 1

                        }

                        fragment_program_ref Ogre/CelShadingFP

                        {

                            // map diffuse from custom renderable param 2

                            param_named_auto diffuse custom 2

                            // map specular from custom renderable param 2

                            param_named_auto specular custom 3

                        }

                        texture_unit

                        {

                            texture cel_shading_diffuse.png 1d

                            tex_address_mode clamp

                            filtering none

                        }

                        texture_unit

                        {

                            texture cel_shading_specular.png 1d

                            tex_address_mode clamp

                            filtering none

                        }

                        texture_unit

                        {

                            texture cel_shading_edge.png 1d

                            tex_address_mode clamp

                            filtering none

                        }

                    }

                }

               

            }

             

             

            ////////////////////////////////////////////////////////////////////////////////////下面是cg文件

            ////////////////////////////////////////////////////////////////////////////////

             

            /* Cel shading vertex program for single-pass rendering

               In this program, we want to calculate the diffuse and specular

               ramp components, and the edge factor (for doing simple outlining)

               For the outlining to look good, we need a pretty well curved model.

            */

            void main_vp(float4 position    : POSITION,

                         float3 normal      : NORMAL,[U1] 

                         // outputs

                         out float4 oPosition    : POSITION,

                         out float diffuse     : TEXCOORD0,

                         out float specular    : TEXCOORD1,

                         out float edge        : TEXCOORD2,[U2] 

                         // parameters

                         uniform float3 lightPosition, // object space:世界坐標(biāo)系

                         uniform float3 eyePosition,   // object space

                         uniform float4 shininess,

                         uniform float4x4 worldViewProj)

            {

                // calculate output position

                oPosition = mul(worldViewProj, position);

             

                // calculate light vector

                float3 N = normalize(normal);

                float3 L = normalize(lightPosition - position.xyz);

               

                // Calculate diffuse component

                diffuse = max(dot(N, L) , 0);

             

                // Calculate specular component

                float3 E = normalize(eyePosition - position.xyz);

                float3 H = normalize(L + E);

                specular = pow(max(dot(N, H), 0), shininess[U3] );

                // Mask off specular if diffuse is 0

                if (diffuse == 0) specular = 0;

             

                // Edge detection, dot eye and normal vectors

                edge = max(dot(N, E), 0); // 法線與視線平行的點(diǎn)認(rèn)為是標(biāo)遠(yuǎn),給予黑色溝邊

            }

             

            void main_fp(float diffuseIn    : TEXCOORD0,

                         float specularIn   : TEXCOORD1,

                         float edge         : TEXCOORD2,

            [U4]            

                         out float4 colour : COLOR,

                         

                         uniform float4 diffuse,

                         uniform float4 specular,

                         

                         uniform sampler1D diffuseRamp,

                         uniform sampler1D specularRamp,

                         uniform sampler1D edgeRamp[U5] )

            {

                // Step functions from textures

                diffuseIn = tex1D(diffuseRamp, diffuseIn).x;

                specularIn = tex1D(specularRamp, specularIn).x;

                edge = tex1D(edgeRamp, edge).x;

             

                colour = edge * ((diffuse * diffuseIn) +

                                (specular * specularIn));

            }


             [U1]這里是GPU傳進(jìn)來(lái)的,POSITION:頂點(diǎn)坐標(biāo),NORMAL法線,去看看hlsl的語(yǔ)意定義

             [U2]out都是輸出參數(shù),改變他們的值輸出之后被ps獲取

             [U3]m下標(biāo)gls,為材料的光澤度

             [U4]得到的是vsout出來(lái)的值

             [U5]texture_unit中得到,順序根據(jù)定義的順序texture_unit

                                 {

                                        texture cel_shading_diffuse.png 1d

                                        tex_address_mode clamp

                                        filtering none

                                 }

                                 texture_unit

                                 {

                                        texture cel_shading_specular.png 1d

                                        tex_address_mode clamp

                                        filtering none

                                 }

                                 texture_unit

                                 {

                                        texture cel_shading_edge.png 1d

                                        tex_address_mode clamp

                                        filtering none

                                 }

            posted on 2010-02-23 21:14 Code Knight 閱讀(763) 評(píng)論(0)  編輯 收藏 引用 所屬分類(lèi): 圖形學(xué)

            av无码久久久久不卡免费网站| 久久精品www人人爽人人| 青青热久久综合网伊人| 欧美精品乱码99久久蜜桃| 久久成人小视频| 久久这里有精品| 一本一道久久精品综合| 久久这里只有精品视频99| 日韩精品久久无码中文字幕| 99久久综合狠狠综合久久| 亚洲精品乱码久久久久久| 99久久久精品免费观看国产| 久久精品国产欧美日韩| 97久久超碰成人精品网站| 天天综合久久一二三区| 久久中文娱乐网| 久久免费视频1| 伊人久久综合热线大杳蕉下载| 久久综合九色综合网站| 国产精品亚洲美女久久久| 亚洲精品无码久久久久| 欧美亚洲日本久久精品| 国产亚洲美女精品久久久久狼| 久久er99热精品一区二区| 亚洲国产成人精品91久久久| 久久天堂电影网| 国产精品一区二区久久不卡| 四虎国产精品成人免费久久| 精品多毛少妇人妻AV免费久久 | 久久国产乱子精品免费女| 久久这里的只有是精品23| 欧美国产成人久久精品| 久久亚洲天堂| 亚洲性久久久影院| 久久99久久99精品免视看动漫 | 亚洲午夜无码AV毛片久久| 激情综合色综合久久综合| 久久久精品日本一区二区三区| 99久久精品国产综合一区| 久久国产香蕉视频| 青春久久|