• <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, 評論 - 14, 引用 - 0
            數據加載中……

            圖形學學習筆記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第三個參數的作用了,用于給程序中賦值的索引

            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:世界坐標系

                         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); // 法線與視線平行的點認為是標遠,給予黑色溝邊

            }

             

            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傳進來的,POSITION:頂點坐標,NORMAL法線,去看看hlsl的語意定義

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

             [U3]m下標gls,為材料的光澤度

             [U4]得到的是vsout出來的值

             [U5]texture_unit中得到,順序根據定義的順序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 閱讀(759) 評論(0)  編輯 收藏 引用 所屬分類: 圖形學

            老男人久久青草av高清| 久久99精品国产| 狠狠色丁香久久婷婷综合蜜芽五月 | 久久久精品2019免费观看| 久久99精品国产99久久| 国产午夜福利精品久久| 中文字幕久久亚洲一区| 国产精品久久久久jk制服| 久久久无码精品午夜| 人妻精品久久无码区| 日产久久强奸免费的看| 亚洲熟妇无码另类久久久| 国产成人精品久久一区二区三区av | 久久国产色AV免费观看| 久久久久久久久久久免费精品| 久久人人爽人人爽人人片AV东京热| 亚洲国产成人久久综合一 | 91精品国产高清久久久久久91| 日本加勒比久久精品| 久久精品这里热有精品| 狠狠色婷婷久久一区二区 | 少妇久久久久久被弄到高潮| 日本福利片国产午夜久久| 一本一道久久综合狠狠老| 香蕉久久夜色精品国产2020| 久久国产精品免费| 国产成人精品久久亚洲高清不卡 | 久久精品无码专区免费青青| 久久久久久国产a免费观看黄色大片 | 久久久精品免费国产四虎| 激情伊人五月天久久综合| 亚洲综合日韩久久成人AV| 国内精品久久久久影院亚洲| 久久久久亚洲AV成人网| 精品国产婷婷久久久| 伊人丁香狠狠色综合久久| 91精品国产综合久久四虎久久无码一级| 国产精品久久久久久一区二区三区 | 亚洲狠狠婷婷综合久久久久| 亚洲国产欧美国产综合久久| 亚洲AV日韩精品久久久久久 |