Quantcast
Channel: Questions in topic: "shader programming"
Viewing all articles
Browse latest Browse all 169

Change generated mesh texture based on dot product

$
0
0
I am generating a hexagon map and want to change the normal maps depending on the elevation rising. I initially thought i can base it on a dot product but i keep getting the wrong results out of it. This is what i get ![alt text][1] This is the area i wanted to be affected by the red part. It's the elevation to a higher level hexagon. ![alt text][2] This is the code, it currently passes onto the albedo instead of o.Normal to visualize it better. The code is based on [catlikecoding][3]. //frag void surf (Input IN, inout SurfaceOutputStandardSpecular o) { //pass normal in again to counteract bug IN.worldNormal = WorldNormalVector(IN, float3(0,0,1)); fixed4 c = //last coordinate is texarray index GetTerrainColor(IN, 0) + GetTerrainColor(IN, 1) + GetTerrainColor(IN, 2); //DP for normalmap float3 dir = _HexCellData_TexelSize - IN.worldPos; float t = 0.5 + sign(dot(dir, o.Normal)) * 0.5; o.Albedo = c.rgb * lerp(_Color2.rgb, _Color.rgb, t); The _HexCellData_TexelSize is from a separate C# script on the object and passes the following onto a cginc file that's included. Shader.SetGlobalVector("_HexCellData_TexelSize", new Vector4(1f / x, 1f / z, x, z)); Maybe i pass the wrong Vector? I still dont fully understand the whole syntax around dot products. Any help appreciated thank you. [1]: /storage/temp/192143-help.png [2]: /storage/temp/192144-areaofeffect.png [3]: https://catlikecoding.com/unity/tutorials/hex-map/part-20/

Viewing all articles
Browse latest Browse all 169

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>