• <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>

            腳踏實(shí)地

            心 勿噪

            2021年3月8日 #

            fixed function pipeline

            //******************************************************************
            //
            // OpenGL ES 2.0 vertex shader that implements the following
            // OpenGL ES 1.1 fixed function pipeline
            //
            // - compute lighting equation for up to eight directional/point/
            // - spot lights
            // - transform position to clip coordinates
            // - texture coordinate transforms for up to two texture coordinates
            // - compute fog factor
            // - compute user clip plane dot product (stored as v_ucp_factor)
            //
            //******************************************************************
            #define NUM_TEXTURES 2
            #define GLI_FOG_MODE_LINEAR 0
            #define GLI_FOG_MODE_EXP 1
            #define GLI_FOG_MODE_EXP2 2
            struct light {
                vec4 position;  // light position for a point/spot light or
                                // normalized dir. for a directional light
                vec4 ambient_color;
                vec4 diffuse_color;
                vec4 specular_color;
                vec3 spot_direction;
                vec3 attenuation_factors;
                float spot_exponent;
                float spot_cutoff_angle;
                bool compute_distance_attenuation;
            };
            struct material {
                vec4 ambient_color;
                vec4 diffuse_color;
                vec4 specular_color;
                vec4 emissive_color;
                float specular_exponent;
            };
            const float c_zero = 0.0;
            const float c_one = 1.0;
            const int indx_zero = 0;
            const int indx_one = 1;
            uniform mat4 mvp_matrix; // combined model-view + projection matrix
            uniform mat4 modelview_matrix; // model view matrix
            uniform mat3 inv_modelview_matrix; // inverse model-view
            // matrix used
            // to transform normal
            uniform mat4 tex_matrix[NUM_TEXTURES]; // texture matrices
            uniform bool enable_tex[NUM_TEXTURES]; // texture enables
            uniform bool enable_tex_matrix[NUM_TEXTURES]; // texture matrix enables
            uniform material material_state;
            uniform vec4 ambient_scene_color;
            uniform light light_state[8];
            uniform bool light_enable_state[8]; // booleans to indicate which of eight
                                                // lights are enabled
            uniform int num_lights; // number of lights enabled = sum of
                                    // light_enable_state bools set to TRUE
            uniform bool enable_lighting; // is lighting enabled
            uniform bool light_model_two_sided; // is two-sided lighting enabled
            uniform bool enable_color_material; // is color material enabled
            uniform bool enable_fog; // is fog enabled
            uniform float fog_density;
            uniform float fog_start, fog_end;
            uniform int fog_mode; // fog mode - linear, exp, or exp2
            uniform bool xform_eye_p; // xform_eye_p is set if we need
                                      // Peye for user clip plane,
                                      // lighting, or fog
            uniform bool rescale_normal; // is rescale normal enabled
            uniform bool normalize_normal; // is normalize normal enabled
            uniform float rescale_normal_factor; // rescale normal factor if
                                                 // glEnable(GL_RESCALE_NORMAL)
            uniform vec4 ucp_eqn; // user clip plane equation –
                                  // - one user clip plane specified
            uniform bool enable_ucp; // is user clip plane enabled
            //******************************************************
            // vertex attributes - not all of them may be passed in
            //******************************************************
            attribute vec4 a_position; // this attribute is always specified
            attribute vec4 a_texcoord0;// available if enable_tex[0] is true
            attribute vec4 a_texcoord1;// available if enable_tex[1] is true
            attribute vec4 a_color; // available if !enable_lighting or
                                    // (enable_lighting && enable_color_material)
            attribute vec3 a_normal; // available if xform_normal is set
                                     // (required for lighting)
            //************************************************
            // varying variables output by the vertex shader
            //************************************************
            varying vec4 v_texcoord[NUM_TEXTURES];
            varying vec4 v_front_color;
            varying vec4 v_back_color;
            varying float v_fog_factor;
            varying float v_ucp_factor;
            //************************************************
            // temporary variables used by the vertex shader
            //************************************************
            vec4 p_eye;
            vec3 n;
            vec4 mat_ambient_color;
            vec4 mat_diffuse_color;
            vec4
            lighting_equation(int i)
            {
                vec4 computed_color = vec4(c_zero, c_zero, c_zero, c_zero);
                vec3 h_vec;
                float ndotl, ndoth;
                float att_factor;
                att_factor = c_one;
                if(light_state[i].position.w != c_zero)
                {
                    float spot_factor;
                    vec3 att_dist;
                    vec3 VPpli;
                    // this is a point or spot light
                    // we assume "w" values for PPli and V are the same
                    VPpli = light_state[i].position.xyz - p_eye.xyz;
                    if(light_state[i].compute_distance_attenuation)
                    {
                        // compute distance attenuation
                        att_dist.x = c_one;
                        att_dist.z = dot(VPpli, VPpli);
                        att_dist.y = sqrt(att_dist.z);
                        att_factor = c_one / dot(att_dist,
                        light_state[i].attenuation_factors);
                    }
                    VPpli = normalize(VPpli);
                    if(light_state[i].spot_cutoff_angle < 180.0)
                    {
                        // compute spot factor
                        spot_factor = dot(-VPpli, light_state[i].spot_direction);
                        if(spot_factor >= cos(radians(light_state[i].spot_cutoff_angle)))
                        {
                            spot_factor = pow(spot_factor,light_state[i].spot_exponent);
                        }
                        else{
                            spot_factor = c_zero;
                        }
                        att_factor *= spot_factor;
                    }
                }
                else
                {
                    // directional light
                    VPpli = light_state[i].position.xyz;
                }
                if(att_factor > c_zero)
                {
                    // process lighting equation --> compute the light color
                    computed_color += (light_state[i].ambient_color * mat_ambient_color);
                    ndotl = max(c_zero, dot(n, VPpli));
                    computed_color += (ndotl * light_state[i].diffuse_color * mat_diffuse_color);
                    h_vec = normalize(VPpli + vec3(c_zero, c_zero, c_one));
                    ndoth = dot(n, h_vec);
                    if (ndoth > c_zero)
                    {
                        computed_color += (pow(ndoth,material_state.specular_exponent) *
                                           material_state.specular_color *
                                           light_state[i].specular_color);
                    }
                    computed_color *= att_factor; // multiply color with
                                                  // computed attenuation factor
                                                  // * computed spot factor
                }
                return computed_color;
            }
            float compute_fog()
            {
                float f;
                
                // use eye Z as approximation
                if(fog_mode == GLI_FOG_MODE_LINEAR)
                {
                    f = (fog_end - p_eye.z) / (fog_end - fog_start);
                }
                else if(fog_mode == GLI_FOG_MODE_EXP)
                {
                    f = exp(-(p_eye.z * fog_density));
                }
                else
                {
                    f = (p_eye.z * fog_density);
                    f = exp(-(f * f));
                }
                f = clamp(f, c_zero, c_one);
                return f;
            }
            vec4 do_lighting()
            {
                vec4 vtx_color;
                int i, j;
                
                vtx_color = material_state.emissive_color +
                            (mat_ambient_color * ambient_scene_color);
                j = (int)c_zero;
                for (i=(int)c_zero; i<8; i++)
                {
                    if(j >= num_lights)
                        break;
                        
                    if (light_enable_state[i])
                    {
                        j++;
                        vtx_color += lighting_equation(i);
                    }
                }
                vtx_color.a = mat_diffuse_color.a;
                return vtx_color;
            }
            void main(void)
            {
                int i, j;
                // do we need to transform P
                if(xform_eye_p)
                    p_eye = modelview_matrix * a_position;
                    
                if(enable_lighting)
                {
                    n = inv_modelview_matrix * a_normal;
                    if(rescale_normal)
                        n = rescale_normal_factor * n;
                    if (normalize_normal)
                        n = normalize(n);
                    mat_ambient_color = enable_color_material ? a_color
                                                              : material_state.ambient_color;
                    mat_diffuse_color = enable_color_material ? a_color
                                                              : material_state.diffuse_color;
                    v_front_color = do_lighting();
                    v_back_color = v_front_color;
                    
                    // do 2-sided lighting
                    if(light_model_two_sided)
                    {
                        n = -n;
                        v_back_color = do_lighting();
                    }
                }
                else
                {
                    // set the default output color to be the per-vertex /
                    // per-primitive color
                    v_front_color = a_color;
                    v_back_color = a_color;
                }
                // do texture xforms
                v_texcoord[indx_zero] = vec4(c_zero, c_zero, c_zero, c_one);
                if(enable_tex[indx_zero])
                {
                    if(enable_tex_matrix[indx_zero])
                        v_texcoord[indx_zero] = tex_matrix[indx_zero] * a_texcoord0;
                    else
                        v_texcoord[indx_zero] = a_texcoord0;
                }
                v_texcoord[indx_one] = vec4(c_zero, c_zero, c_zero, c_one);
                if(enable_tex[indx_one])
                {
                    if(enable_tex_matrix[indx_one])
                        v_texcoord[indx_one] = tex_matrix[indx_one] * a_texcoord1;
                    else
                        v_texcoord[indx_one] = a_texcoord1;
                }
                v_ucp_factor = enable_ucp ? dot(p_eye, ucp_eqn) : c_zero;
                v_fog_factor = enable_fog ? compute_fog() : c_one;
                gl_Position = mvp_matrix * a_position;
            }

            posted @ 2021-03-08 22:05 LSH 閱讀(191) | 評論 (0)編輯 收藏

            2019年12月8日 #

            rayIntersect 重新修改


            ----------------------------------
            一段光線求交的場景!
            ----------------------------------


            posted @ 2019-12-08 00:59 LSH 閱讀(634) | 評論 (0)編輯 收藏

            2019年12月7日 #

            350行路徑追蹤渲染器online demo

            這是一個簡單的路徑追蹤demo
            移動視角:左鍵按下+鼠標(biāo)移動
            全屏查看:右鍵按下


            posted @ 2019-12-07 15:21 LSH 閱讀(575) | 評論 (0)編輯 收藏

            2019年11月3日 #

            關(guān)于向量的叉乘操作

            在三維中常常需要重算正交的基向量組,
            由于叉乘操作是有序的. 一般來說 : UxV不等于VxU, 
            所有往往記不住到底是哪個左向量乘哪個右向量求出
            第三個向量,由于吃了一些虧所以做了總結(jié).
            i,j,k三個基向量, 如果你使用的圖形引擎Z往屏幕外面,
            右手邊X和上方向Y規(guī)定為正方向的一組正交向量,如果
            你使用的模型的基向量組和它相同,那么放心用.
            ixj=k, kxi=j, jxk=i 
            但是你可能不總是那么幸運(yùn).也許你打算使用Z往屏幕里面,
            右手邊X和上方向Y規(guī)定為正方向的一組正交向量,這時你就
            需要改變叉乘方式了
            jxi=k, ixk=j, kxj=i 
            也就是統(tǒng)統(tǒng)反過來使用就可以了.
            但是如果你想使用Z往屏幕里面,右手邊X和下方向Y規(guī)定
            為正方向的一組正交向量時這時你又需要怎么弄呢?
            其實(shí)還是:
            ixj=k, kxi=j, jxk=i 
            如果你想使用Z往屏幕里面,左手邊X和下方向Y規(guī)定
            為正方向的一組正交向量時這時你又需要怎么弄呢?
            這時又是:
            jxi=k, ixk=j, kxj=i 
            也是統(tǒng)統(tǒng)反過來使用.
            這時怎么得到得結(jié)論?
            其實(shí)就是通過計(jì)算得到的
            以下都假設(shè)x右為正方向,y上為正方向,z往屏幕外為正方向設(shè)備的環(huán)境
            測試.

            var vec3 = glMatrix.vec3;
            console.log("-------------------->z軸往屏幕里為正的坐標(biāo)系");
            var u = vec3.fromValues(1,0,0)
            var v = vec3.fromValues(0,1,0)
            var w = vec3.fromValues(0,0,-1)

            console.log(vec3.cross(vec3.create(), w,v));
            console.log(vec3.cross(vec3.create(), u,w));
            console.log(vec3.cross(vec3.create(), v,u));
            console.log("-------------------->y軸向下為正的坐標(biāo)系");
            var u = vec3.fromValues(1,0,0)
            var v = vec3.fromValues(0,-1,0)
            var w = vec3.fromValues(0,0,1)

            console.log(vec3.cross(vec3.create(), w,v));
            console.log(vec3.cross(vec3.create(), u,w));
            console.log(vec3.cross(vec3.create(), v,u));
            console.log("-------------------->x軸向左為正的坐標(biāo)系");
            var u = vec3.fromValues(-1,0,0)
            var v = vec3.fromValues(0,1,0)
            var w = vec3.fromValues(0,0,1)

            console.log(vec3.cross(vec3.create(), w,v));
            console.log(vec3.cross(vec3.create(), u,w));
            console.log(vec3.cross(vec3.create(), v,u));
            console.log("-------------------->全部反為正坐標(biāo)系");
            var u = vec3.fromValues(-1,0,0)
            var v = vec3.fromValues(0,-1,0)
            var w = vec3.fromValues(0,0,-1)
            console.log(vec3.cross(vec3.create(), w,v));
            console.log(vec3.cross(vec3.create(), u,w));
            console.log(vec3.cross(vec3.create(), v,u));

            以上都能得到正確的向量組

            console.log("-------------------->z軸往屏幕外為正坐標(biāo)系");
            var u = vec3.fromValues(1,0,0)
            var v = vec3.fromValues(0,1,0)
            var w = vec3.fromValues(0,0,1)
            console.log(vec3.cross(vec3.create(), v,w));
            console.log(vec3.cross(vec3.create(), w,u));
            console.log(vec3.cross(vec3.create(), u,v));
            console.log("-------------------->任意兩個是為負(fù)數(shù)的坐標(biāo)系");
            var u = vec3.fromValues(-1,0,0)
            var v = vec3.fromValues(0,1,0)
            var w = vec3.fromValues(0,0,-1)
            console.log(vec3.cross(vec3.create(), v,w));
            console.log(vec3.cross(vec3.create(), w,u));
            console.log(vec3.cross(vec3.create(), u,v));

            以上也都能得到正確的向量組.
            結(jié)論就是如果偶數(shù)相反就正常使用,如果是奇數(shù)相反就
            用反過來用.

            posted @ 2019-11-03 23:34 LSH 閱讀(780) | 評論 (0)編輯 收藏

            2019年6月26日 #

            排列組合

            // 排列:正數(shù)n的全排列
            // n 正數(shù)n
            // return 數(shù)值
            function A(n) {
            if (n <= 0) return n;
            var sum = 1;
            for (var i = n; i > 0; --i) {
            sum *= i;
            }
            return sum;
            }

            // 組合:從n個中選擇m個來組合
            // n 正數(shù)n
            // m 正數(shù)m
            // return 數(shù)值
            function C(n, m) {
            return A(n) / (A(m) * A(n - m));
            }

            // 數(shù)組組合: 從array中選擇n個元素來組合
            // array 數(shù)組
            // n 正數(shù)n
            // return 多少種組合
            function ArrayComb(array, n) {
            var result = [], t = [], e;

            function Recursion(index, array, n, t, result) {
            if (t.length === n) { result.push(t.slice()); return };

            for (var i = index; i < array.length; ++i) {
            e = array[i];
            t.push(e);
            Recursion(i + 1, array, n, t, result);
            t.pop();
            }
            }

            Recursion(0, array, n, t, result);
            return result;
            }

            posted @ 2019-06-26 12:57 LSH 閱讀(244) | 評論 (0)編輯 收藏

            2018年3月23日 #

            rayIntersect

                 摘要: ---------------------------------- 一段光線求交的場景! ---------------------------------- 點(diǎn)我看源碼 Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --...  閱讀全文

            posted @ 2018-03-23 00:27 LSH 閱讀(336) | 評論 (0)編輯 收藏

            2017年1月19日 #

            矩陣計(jì)算器

                 摘要: Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><html><head><title>矩陣計(jì)算器 (1.0)</title><meta charset="utf-8">&l...  閱讀全文

            posted @ 2017-01-19 23:36 LSH 閱讀(598) | 評論 (0)編輯 收藏

            2016年12月16日 #

            Quine program

            c/c++
            //>this is a Quine program implement by c language.
            //>reference http://www.madore.org/~david/computers/quine.html
            #include <stdio.h>
            int main(void){
              char n='\n'; char g='\\'; char q='"'; char s=';';
              char*s1="http://>this is a Quine program implement by c language.%c//>reference http://www.madore.org/~david/computers/quine.html%c#include <stdio.h>%cint main(void){%c  char n='%cn'; char g='%c%c'; char q='%c'; char s=';';%c  char*s1=%c%s%c;%c  printf(s1,n,n,n,n,g,g,g,q,n,q,s1,q,n,s,n,s,n)%c%c  return 0%c%c}";
              printf(s1,n,n,n,n,g,g,g,q,n,q,s1,q,n,s,n,s,n);
              return 0;
            }
            javascript
            var c1='"'; var c2='\n'; var c3='\\'; var c4=';';
            var s1="var c1='%c1'; var c2='%c3n'; var c3='%c3%c3'; var c4=';';%c2var s1=%c1%s1%c1%c4%c2console.log((((((((((s1.replace('%c1', c1)).replace('%c1', c1)).replace('%c1', c1)).replace('%c2', c2)).replace('%c2', c2)).replace('%c3', c3)).replace('%c3', c3)).replace('%c3', c3)).replace('%c4', c4)).replace('%s1', s1))";
            console.log((((((((((s1.replace('%c1', c1)).replace('%c1', c1)).replace('%c1', c1)).replace('%c2', c2)).replace('%c2', c2)).replace('%c3', c3)).replace('%c3', c3)).replace('%c3', c3)).replace('%c4', c4)).replace('%s1', s1))

            posted @ 2016-12-16 16:44 LSH 閱讀(419) | 評論 (0)編輯 收藏

            2016年10月2日 #

            js模塊編程

            <script type="text/javascript">
             
                    void function(global)
                    {
                        var mapping = {}, cache = {};
                        global.define = function(id, func){
                            mapping[id] = func;
                        };
                        
                        global.require = function(id){
                            if(cache[id])
                                return cache[id];
                            else
                                return cache[id] = mapping[id]({});
                        };
                    }(this);
                    
                    define("moduleA", function(exports)
                    {
                        function ClassA(){
                        }
                        
                        ClassA.prototype.print = function(){
                            alert("moduleA.ClassA")
                        }
                        
                        exports.New = function(){
                            return new ClassA();
                        }
                    
                        return exports;
                        
                    });
                    
                    define("moduleB", function(exports)
                    {
                        function ClassB(){
                        }
                    
                        ClassB.prototype.print = function(){
                            alert("moduleB.ClassB")
                        }
                        
                        exports.New = function(){
                            return new ClassB();
                        }
                        
                        return exports;
                    });
                    
                    define("moduleC", function(exports)
                    {
                        function ClassC(){
                        }
                    
                        ClassC.prototype.print = function(){
                            var classA = require("moduleA").New();
                            classA.print();
                                
                            var classB = require("moduleB").New();
                            classB.print();
                                
                            alert("moduleC.ClassC")
                        }
                        
                        exports.New = function(){
                            return new ClassC();
                        }
                        
                        return exports;
                    });
                    
                    var classC = require("moduleC").New();
                    classC.print();
                    
                  </script>

            posted @ 2016-10-02 20:33 LSH 閱讀(221) | 評論 (0)編輯 收藏

            2016年9月19日 #

            trace.bat

            @echo off
            :Main
            setlocal EnableDelayedExpansion
            call :ShowInputIP
            call :CheckIP
            if %errorlevel% == 1 (
                call :TrackIP !IP! 1
            )
            setlocal DisableDelayedExpansion
            goto :Main
            ::---------------------------------------------------------------
            :TrackIP
            ping %1 -n 2 -i %2 >rs.txt
            set /a c=%2+1
            if %c% geq 65 (
                echo 超出TTL限制[65]
                ping %1 -n 1
                goto :eof
            )
            for /f "tokens=1-5* delims= " %%i in (rs.txt) do (
                if "%%i" == "來自" (
                    echo    追蹤到IP[%%j] TTL=%2
                    if %%j == !IP! (
                        echo 追蹤完成!!! 
                    ) else (
                        call :TrackIP %1 %c%
                    )
                    goto :eof
                ) else (
                    if "%%i" == "請求超時。" ( 
                        echo 跳躍TTL  [TTL=%2%] 
                        call :TrackIP %1 %c% 
                        goto :eof
                    )
                )
            )
            goto :eof
            ::---------------------------------------------------------------
            :ShowInputIP
            echo 請輸入要跟蹤 ip/域名 地址:
            set /p IP=
            goto :eof
            ::---------------------------------------------------------------
            :CheckIP
            ping %IP% -n 1 >temp.txt
            set context=
            for /f "tokens=1-5* delims= " %%i in (temp.txt) do (
                if "%%m" == "具有" (
                    set context=%%l
                    set IP=!context:~1,-1!
                    echo 解析域名 [%IP%] → IP [!IP!]
                    goto :CheckEnd
                )
            )
            :CheckEnd
            del temp.txt
            exit /b 1

            posted @ 2016-09-19 03:07 LSH 閱讀(273) | 評論 (0)編輯 收藏

            僅列出標(biāo)題  下一頁
            亚洲欧洲久久久精品| 色欲综合久久躁天天躁蜜桃| 久久久精品国产sm调教网站 | 精品熟女少妇AV免费久久| 韩国三级中文字幕hd久久精品 | 久久久久久久久久久久久久| 久久午夜福利电影| 久久久精品日本一区二区三区 | 老司机午夜网站国内精品久久久久久久久| 国产精品久久久久久久久| 久久不见久久见免费视频7| 亚洲AV无码久久精品色欲| 亚洲AV日韩精品久久久久久久| 久久久久久久波多野结衣高潮| 性高湖久久久久久久久AAAAA| 亚洲国产成人久久综合一区77 | 囯产极品美女高潮无套久久久| 久久婷婷是五月综合色狠狠| 久久久久av无码免费网| 亚洲级αV无码毛片久久精品| 久久影院综合精品| 国产精品天天影视久久综合网| 秋霞久久国产精品电影院| 国产女人aaa级久久久级| 伊人色综合久久天天网| 亚洲午夜久久久久久久久久| 久久久婷婷五月亚洲97号色| 韩国无遮挡三级久久| 久久久久九国产精品| 久久婷婷色综合一区二区| 国产亚洲综合久久系列| 99精品伊人久久久大香线蕉| 久久久久99这里有精品10| 久久99国产综合精品免费| 精品无码人妻久久久久久| yy6080久久| 国产精品美女久久久| 中文精品久久久久人妻| 国产精品久久国产精品99盘 | 久久一日本道色综合久久| 亚洲国产精品久久久久|