摘要: 转眼间,研究生毕业已经10年了,从2009年到2019年,整整10年。今天是2020年2月8日,正月十五元宵节。2020年,是本命年,一开始就发生了很多事情,武汉发生新型冠状病毒肺炎,科比直升机坠毁去世。到今天为止,全国共确诊新型冠状病毒肺炎病例31774例,其中重症病例6101例,累计死亡病例72 阅读全文
posted @ 2020-02-08 16:52 Pulaski 阅读(2670) 评论(16) 推荐(22) 编辑
摘要: http://blog.csdn.net/weiqubo/article/details/6913234 与玩游戏相比,写游戏要复杂上千万倍,除了需要掌握通用的编程技巧以外,还要有相当的图形学,物理,数学基础,特别是在国内,由于相关资料的缺乏,更是让初学者无从下手。下面总结了一些入门方法和比较容易入手的资料。首先你要精通一门高级语言,比如C++或者C#,其次,要有良好的英文阅读能力。对游戏开发者来说英文阅读能力是最重要也是最基本的工具之一,因为你遇到的大部分资源都将是英文的,不要总等着别人为你翻译。慢慢尝试着阅读英文资料,你会发现其实也并没有那么难:)刚开始,你要做的就是选择一门图形AP... 阅读全文
posted @ 2013-03-27 13:44 Pulaski 阅读(369) 评论(0) 推荐(0) 编辑

http://www.polycount.com/forum/showthread.php?t=117185

 

I am making some custom terrain shaders with strumpy's editor and I want to be able to create normals based on my blend mask. Does anyone know how I can turn grayscale data into basic normal mapping info? I have seen someone do this in unreal but I can't remember where.

 

You probably want to get the difference of the values pixel-by-pixel using ddx, I think.

Off the top of my head... for CG/HLSL;

float heightmap = your height map value;
float3 normal;
normal.x = ddx(heightmap);
normal.y = ddy(heightmap);
normal.z = sqrt(1 - normal.x*normal.x - normal.y * normal.y); // Reconstruct z component to get a unit normal.

For OpenGL, I think the functions are dFdx and dFdy.

DirectX11 has ddx_fine and ddy_fine which I think give more accurate results.


That'll give you the normal in, ehr... screen space I think?

Otherwise you can sample the heightmap multiple times, offsetting it by a pixel and working out the difference from those values. That should get you it in whatever space the base normal is in.

Nicked frm here; http://www.gamedev.net/topic/594781-...mal-algorithm/

float me = tex2D(heightMapSampler,IN.tex).x;
float n = tex2D(heightMapSampler,float2(IN.tex.x,IN.tex.y+1.0/heightMapSizeY)).x;
float s = tex2D(heightMapSampler,float2(IN.tex.x,IN.tex.y-1.0/heightMapSizeY)).x;
float e = tex2D(heightMapSampler,float2(IN.tex.x+1.0/heightMapSizeX,IN.tex.y)).x;
float w = tex2D(heightMapSampler,float2(IN.tex.x-1.0/heightMapSizeX,IN.tex.y)).x;                

//find perpendicular vector to norm:        
float3 temp = norm; //a temporary vector that is not parallel to norm
if(norm.x==1)
    temp.y+=0.5;
else
    temp.x+=0.5;

//form a basis with norm being one of the axes:
float3 perp1 = normalize(cross(norm,temp));
float3 perp2 = normalize(cross(norm,perp1));

//use the basis to move the normal in its own space by the offset        
float3 normalOffset = -bumpHeightScale*(((n-me)-(s-me))*perp1 + ((e-me)-(w-me))*perp2);
norm += normalOffset;
norm = normalize(norm);

 

Gave it a try out of curiosity.

Here's the multi-sample method in a stripped-down surface shader.

I had to change the handedness from the code above to match Unity (changing the sign of the operation when sampling the e and w values from + to - and vice versa).

 

Shader "Debug/Normal Map From Height" {
    Properties {
        _Color ("Main Color", Color) = (1,1,1,1)
        _MainTex ("Diffuse (RGB) Alpha (A)", 2D) = "white" {}
        _BumpMap ("Normal (Normal)", 2D) = "bump" {}
        _HeightMap ("Heightmap (R)", 2D) = "grey" {}
        _HeightmapStrength ("Heightmap Strength", Float) = 1.0
        _HeightmapDimX ("Heightmap Width", Float) = 2048
        _HeightmapDimY ("Heightmap Height", Float) = 2048
    }

    SubShader{
        Tags { "RenderType" = "Opaque" }

        CGPROGRAM

            #pragma surface surf NormalsHeight
            #pragma target 3.0

            struct Input
            {
                float2 uv_MainTex;
            };

            sampler2D _MainTex, _BumpMap, _HeightMap;
            float _HeightmapStrength, _HeightmapDimX, _HeightmapDimY;

            void surf (Input IN, inout SurfaceOutput o)
            {
                o.Albedo = fixed3(0.5);

                float3 normal = UnpackNormal(tex2D(_BumpMap, IN.uv_MainTex));

                float me = tex2D(_HeightMap,IN.uv_MainTex).x;
                float n = tex2D(_HeightMap,float2(IN.uv_MainTex.x,IN.uv_MainTex.y+1.0/_HeightmapDimY)).x;
                float s = tex2D(_HeightMap,float2(IN.uv_MainTex.x,IN.uv_MainTex.y-1.0/_HeightmapDimY)).x;
                float e = tex2D(_HeightMap,float2(IN.uv_MainTex.x-1.0/_HeightmapDimX,IN.uv_MainTex.y)).x;
                float w = tex2D(_HeightMap,float2(IN.uv_MainTex.x+1.0/_HeightmapDimX,IN.uv_MainTex.y)).x;

                float3 norm = normal;
                float3 temp = norm; //a temporary vector that is not parallel to norm
                if(norm.x==1)
                    temp.y+=0.5;
                else
                    temp.x+=0.5;

                //form a basis with norm being one of the axes:
                float3 perp1 = normalize(cross(norm,temp));
                float3 perp2 = normalize(cross(norm,perp1));

                //use the basis to move the normal in its own space by the offset
                float3 normalOffset = -_HeightmapStrength * ( ( (n-me) - (s-me) ) * perp1 + ( ( e - me ) - ( w - me ) ) * perp2 );
                norm += normalOffset;
                norm = normalize(norm);

                o.Normal = norm;
            }

            inline fixed4 LightingNormalsHeight (SurfaceOutput s, fixed3 lightDir, fixed3 viewDir, fixed atten)
            {
                viewDir = normalize(viewDir);
                lightDir = normalize(lightDir);
                s.Normal = normalize(s.Normal);
                float NdotL = dot(s.Normal, lightDir);
                _LightColor0.rgb = _LightColor0.rgb;

                fixed4 c;
                c.rgb = float3(0.5) * saturate ( NdotL ) * _LightColor0.rgb * atten;
                c.a = 1.0;
                return c;
            }

        ENDCG
    }
    FallBack "VertexLit"
}

 

Derivative method works, but it's fucking ugly 'cause it's in screen space - really noisy.

ddx_fine might give better results in DX11, but it looks like crap in DX9.

posted @ 2014-07-25 14:16 Pulaski 阅读(531) 评论(0) 推荐(0) 编辑
摘要: 原创作品,允许转载,转载时请务必以超链接形式标明文章原始出处、作者信息和本声明。否则将追究法律责任。http://rangercyh.blog.51cto.com/1444712/1394348小斯同学花了几周的时间,终于把我们的服务端和客户端从vs2005升级到vs2013了。真是不得不给个赞。升... 阅读全文
posted @ 2014-07-12 13:05 Pulaski 阅读(4362) 评论(0) 推荐(3) 编辑
摘要: http://stackoverflow.com/questions/7328424/point-in-obb-oriented-bounding-box-algorithmGiven a center point, width, height and angle forming an OBB, h... 阅读全文
posted @ 2014-07-08 17:58 Pulaski 阅读(1095) 评论(0) 推荐(0) 编辑
摘要: http://answers.unity3d.com/questions/147988/how-to-pause-the-main-camera-.htmlI would simply pause the game with Time.timeScale = 0, and then do the f... 阅读全文
posted @ 2014-05-21 14:40 Pulaski 阅读(955) 评论(0) 推荐(0) 编辑
摘要: http://www.u3dblog.com/?p=441有时候场景中一大批物体都需要制作成预制物体,但是unity只能手动一个一个的创建,感觉非常的蹩脚,下面一个编辑器类的方法解决你的麻烦。static Object CreatePrefab(GameObject go, string name)... 阅读全文
posted @ 2014-05-11 12:07 Pulaski 阅读(3142) 评论(0) 推荐(0) 编辑
摘要: http://stackoverflow.com/questions/2767/recommended-add-ons-plugins-for-microsoft-visual-studioNUGetVisual Assist XAnkhSvn- (FREE) SVN Source Control ... 阅读全文
posted @ 2014-05-10 12:59 Pulaski 阅读(284) 评论(0) 推荐(0) 编辑
摘要: http://forum.unity3d.com/threads/148078-Reducing-script-compile-time-or-a-better-workflow-to-reduce-excessive-recompilingSOLUTIONS:Each of these solut... 阅读全文
posted @ 2014-05-09 14:35 Pulaski 阅读(506) 评论(0) 推荐(0) 编辑
摘要: 法一:http://forum.unity3d.com/threads/161685-How-to-build-and-debug-external-DLLs http://docs.unity3d.com/Documentation/Manual/UsingDLL.html法二:http:/... 阅读全文
posted @ 2014-05-09 14:27 Pulaski 阅读(3112) 评论(0) 推荐(0) 编辑
摘要: http://aras-p.info/texts/CompactNormalStorage.htmlIntroBaseline: store X&Y&ZMethod 1: X&YMethod 3: Spherical CoordinatesMethod 4: Spheremap TransformMethod 7: Stereographic projectionMethod 8: Per-pixel View SpacePerformance ComparisonQuality ComparisonChangelogIntroVarious deferred shad 阅读全文
posted @ 2013-10-21 15:39 Pulaski 阅读(488) 评论(0) 推荐(0) 编辑
点击右上角即可分享
微信分享提示