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

            腳踏實地

            心 勿噪

            #

            shader 中避免if else

            // test less and equal zero
            // x小于,等于0返回0,x大于0返回1
            // if x <= 0 return 0 and x > 0 return 1.
            float LQZ(x){
               return max(0, sign(x));
               // return ceil(clamp(0.,1.,x));
            }

            // if x <= 0 return a and x > 0 return b
            // x小于,等于0返回a,x大于0返回b
            float v = mix(a, b, LQZ(x));  

            // if x is odd number (0~1,2~3,4~5,6~7) return a else return b
            // 奇數段(0~1,2~3,4~5,...)返回a,偶數段(1~2,3~4)返回b
            float v = mix(a, b, LQZ(mod(x,2.0) - 1.0));

            posted @ 2016-09-04 14:32 LSH| 編輯 收藏

            hlsl的 投影和view矩陣

            float4x4 LookAtMatrix(float3 eyePosition, float3 lookAt, float3 up)
            {
                float3 zaxis = normalize(lookAt - eyePosition);
                float3 yaxis = normalize(up);
                float3 xaxis = normalize(cross(yaxis, zaxis));
                yaxis = normalize(cross(zaxis, xaxis));
                
                float4x4 result = float4x4(xaxis.x, yaxis.x, zaxis.x, 0.0,
                                           xaxis.y, yaxis.y, zaxis.y, 0.0,
                                           xaxis.z, yaxis.z, zaxis.z, 0.0,
                 -dot(xaxis, eyePosition), -dot(yaxis, eyePosition), -dot(zaxis, eyePosition), 1.0);
                               
                return result;
            }
            #define MATH_PI_DIV_180  0.0174532925
            float4x4 DxPorjMatrix(float fov_y, float aspect, float zNear, float zFar)
            {
                // Left Hand
                float f_n = 1.0f / (zFar - zNear);
                float yScale = 1.0 / tan(MATH_PI_DIV_180 * (fov_y) * 0.5f);
                float xScale = yScale / aspect;
                float4x4 result = float4x4(xScale, 0.0, 0.0, 0.0,
                                           0.0, yScale, 0.0, 0.0,
                                           0.0, 0.0, zFar*f_n, 1.0,
                                           0.0, 0.0, -zNear * zFar * f_n, 1.0);
                return result;
            }

            biliner 插值

            posted @ 2015-10-24 10:38 LSH| 編輯 收藏

            game physics chapter 2.

            第二章 物理中的基礎概念
            在這一章中我們回顧一些物理的基礎概念,這些概念關系到(relevant)運動分析(analysis)和對剛體的影響。包含質量的類型區域被歸類于(classified)剛體。2.1,2.2節中的主題介紹了粒子的在absence力量下,在二維或者三維所呈現的曲線路徑。這些主題與運動學(kinematics)有關.而這一節的主題介紹了物理概念里的位置,速度,加速度。很多應用為更好的處理問題來選擇適合的坐標系。笛卡爾坐標系統通常很方便,但是我們還需極坐標系(polar coordinates),圓柱坐標系(cylindrical coordinates), 球坐標系(spherical coordinates)。還有單個粒子的運動學,還有粒子系統和實體系統的運動學。這些物理材質都屬于物理引擎,在第六章討論。
            這一章的其他剩余部分將介紹一些標準的物理概念。一條主線是從2.3節開始介紹牛頓運動法則,討論力的概論在2.4中,其書中具體例子涉及到重力,彈力,摩擦力。力矩和平衡也在這節出現。各種測量距在2.5節討論,包含了線性和角度距,一階距,這些與物體的質心,距,慣性息息相關。2.5的最后一部分展示了怎樣計算質量不變的實體多邊形的質心和慣性張量。在第6章中討論的物理引擎中需要實現的東西。功和能是本章最后討論的。在開發拉格朗日動態模型中,動能是重要的量。在處理保守力中勢能也是非常重要的量,如重力就是保守力。
            2.1 剛體類型
            剛體的特征(characterized)是質量存在于區域中。最簡單的剛體是一個質量為m的單粒子它處于位置x處。p是一個含有碰撞的有限數量的粒子所組成的粒子系統,第i個粒子的質量M i處于位置X i,l <= i <= p. 單粒子和粒子系統是粒子數目有限的松散材質的例子。一個粒子系統把各種物理量累加之和的標準樣子是:
                             p
            Q
                   = S Qi
                 total    
                            i=1
            Qi是一些物理量

            posted @ 2015-08-09 11:29 LSH| 編輯 收藏

            中心縮放公式

            按某中心為原點的縮放公式為.
            p' = o + (p - o) * s;
            p 為需要變換的點.
            o 為縮放中心點.
            s 縮放的值. (s >= 0)
            p' 為結果.

            posted @ 2015-05-19 17:33 LSH 閱讀(437) | 評論 (0)編輯 收藏

            Never call virtual function during construction or destruction.(用遠不要在構造函數或者析構函數中調用虛函數或純虛函數)

            the title is all about.

            posted @ 2015-05-05 16:33 LSH| 編輯 收藏

            please please please, make it smaller!

            http://www.iquilezles.org/blog/?p=2828

            I think size matters. However, unlike in real life, when programming the smaller the better. Generally. Also, the less branches the better, at least when programming for parallel systems. And also, the more compact and regular, the prettier (but this is my personal opinion only).
            Related to this, in the last 6 months I have pointed out / proposed this same optimization to at least five different people. Basically, it seems most people make this same “mistake” over and over again, which is to write this horrifying thing
            vec3 color = vec3(0.0);
            if (theta < 1.0) {
            color.r = 1.0;
            color.g = theta;
            }
            else if (theta < 2.0) {
            color.r = 2.0 - theta;
            color.g = 1.0;
            }
            else if (theta < 3.0) {
            color.g = 1.0;
            color.b = theta - 2.0;
            }
            else if (theta < 4.0) {
            color.g = 4.0 - theta;
            color.b = 1.0;
            }
            else if (theta < 5.0) {
            color.r = theta - 4.0;
            color.b = 1.0;
            }
            else {
            color.r = 1.0;
            color.b = 6.0 - theta;
            }
            return color;
            instead of this equivalent line:
            vec3 color = clamp( abs(mod(theta+vec3(0.,4.,2.),6.)-3.)-1., 0., 1. );

            posted @ 2015-01-05 14:22 LSH 閱讀(303) | 評論 (0)編輯 收藏

            please simplify me (again…)

            http://www.iquilezles.org/blog/?p=2848

            Yet another example of code simplification that people don’t seem to want to do. It must be the 5th ot 6th time I ask people to do this change when programming a point-to-line distance computation: please, replace this ugly
            float sdLine( vec2 a, vec2 b, vec2 p )
            {
                vec2 ba = b - a;
                vec2 pa = p - a;
                float dist = (ba.x*pa.y - ba.y*pa.x) / distance(a, b);
                if( dot(a-b,p-b) < 0.0 ) 
                    return distance(b, p);
                if( dot(b-a,p-a) < 0.0 ) 
                    return distance(a, p);
                return abs(dist);
            }
            by the much more beautiful:
            float sdLine( vec2 a, vec2 b, vec2 p )
            {
                vec2 pa = p - a;
                vec2 ba = b - a;
                float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
                return length( pa - ba*h );
            }
            Do it for the karma or something.  

            posted @ 2015-01-05 14:04 LSH 閱讀(290) | 評論 (0)編輯 收藏

            矢量直線,矢量點

             1 
             2 // 繪制點
             3 float point(vec2 p, vec2 center, float radius)
             4 {
             5     vec2 c2p = p-center;
             6     float d = dot(c2p,c2p); // c2p的長度平方
             7     if(d < radius * radius)
             8         return 1.0;
             9     
            10     return 0.0;
            11 }
            12 
            13 
            14 // 繪制直線
            15 float line(vec2 p, vec2 a, vec2 b, float w)
            16 {
            17     vec2 a2b = b - a;
            18     vec2 a2p = p - a;
            19     
            20     
            21     // 因為投影 proj(a2p,a2b) 等于 dot(a2p,a2b) / length(a2b)
            22     // 在把投影的值和a2b向量做比例關系。
            23     // 所以proj(a2p,a2b)/length(a2b) 等于 dot(a2p,a2b)/dot(a2b,a2b)
            24     
            25     float h = clamp( dot(a2p,a2b)/dot(a2b,a2b), 0.0, 1.0 );
            26     vec2 p1 = mix( a, b, h );
            27     if( length( p1 - p ) <= w )
            28         return 1.0;
            29     
            30     return 0.0;
            31 }
            32 
            33 void main(void)
            34 {
            35     vec2 uv = gl_FragCoord.xy / iResolution.y;
            36     uv.x = uv.x + (1.0 - iResolution.x/iResolution.y)*0.5;
            37     
            38     vec3 col = vec3(1.0,0,0) * point(uv, vec2(0.5,0.5), 0.05)
            39              + vec3(0,0,1.0) * line(uv, vec2(0.0,0.25), vec2(1.0,0.55), 0.05);
            40     
            41     gl_FragColor = vec4(col,1.0);
            42 }

            posted @ 2015-01-05 02:21 LSH 閱讀(274) | 評論 (0)編輯 收藏

            光照模型

            光照類型

            環境光(ambient): 沒有確切來源。各種光經過反射后的得到的結果。
            表示式 = 環境光強度 * 環境反射的顏色;

            散射光(diffuse): 在真實世界中,我們經常見到的光線都是由某些固定的光源發出的,它們總是從某一個方向照射到物體上,而不像我們在討論環境光時那樣不用考慮光線的方向。所以他需要方向。
            表達式 = 散射光強度  *(射出角度 點乘 面法線向量)* 散射的顏色  

            鏡面反射光(specular):在真實世界中,不僅要使用漫反射模型,同時還要接觸大量鏡面反射的情況。通過鏡面反射,可以看到物體表面的高光,或者是光源在光亮物體表面上的反射。
            表達式 = 反射系數 *  光照強度 * (cosA的反射指數 次方)

            發射光(emission):看起來發光,但不是光源,不能照亮環境。
            表達式 = 發射光

            光源的類型

            定向光:屬性:光照強度不雖距離的而變化。
            表達式 = 光源初始強度 * 光源的顏色

            點光源:屬性:光源強度雖距光源的距離而衰減。
            表達式 = 光源初始強度*光源的顏色 / 三個因子      其中三個因子為:常量因子,線性因子,二次因子

            聚光燈 :屬性:具有內錐(本影)和外錐(半影)。
            表達式分為內錐和外錐兩個。不在內錐和外錐范圍內不受光照影響。 

            posted @ 2010-05-17 02:23 LSH 閱讀(395) | 評論 (0)編輯 收藏

            僅列出標題
            共2頁: 1 2 
            日本WV一本一道久久香蕉| 丰满少妇人妻久久久久久4| 国产成人久久777777| 欧美一区二区精品久久| 一本久道久久综合狠狠躁AV| 狠狠精品久久久无码中文字幕| 国产精品久久久久AV福利动漫| 国内精品久久久久久久coent| 亚洲午夜久久久久久久久久| 国内精品久久人妻互换| 日韩影院久久| 久久久久久九九99精品| 久久久国产精华液| 国产69精品久久久久99尤物| 久久久久无码中| 精品久久一区二区| 男女久久久国产一区二区三区| 亚洲伊人久久综合中文成人网| 新狼窝色AV性久久久久久| 老男人久久青草av高清| 久久香蕉国产线看观看99| 久久久www免费人成精品| 亚洲性久久久影院| 9191精品国产免费久久| 久久精品免费一区二区三区| 久久久久久久免费视频| 日产久久强奸免费的看| 超级碰久久免费公开视频| 精品久久久无码人妻中文字幕豆芽| 久久综合狠狠综合久久97色| 久久久久这里只有精品 | 亚洲国产精品综合久久一线| 国产一区二区三区久久精品| 久久久久成人精品无码中文字幕 | 久久综合综合久久综合| 久久精品免费全国观看国产| 国产免费久久精品丫丫| 日本久久中文字幕| 久久国产AVJUST麻豆| 色天使久久综合网天天| 久久久久青草线蕉综合超碰|