Home Technical Talk
The BRAWL² Tournament Challenge has been announced!

It starts May 12, and ends Sept 12. Let's see what you got!

https://polycount.com/discussion/237047/the-brawl²-tournament

LitSpheres in Max viewport

13

Replies

  • dralex789
    Offline / Send Message
    dralex789 polycounter lvl 7
    Got these badboys working in UDK over here incase anyone is curious Including a hacked world space option (instead of camera space).

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

    Thanks for all the info here, couldn't have done it without it.
  • garner
    I couldn't find an HLSL matcap shader that worked with XNA so I built this from the previous Unity one.

    1. #define MaxBones 59
    2. float4x4 Bones[MaxBones];
    3. float4x4 View;
    4. float4x4 Projection;
    5. float4x4 WorldInverseTranspose;
    6. float4x4 World;
    7.  
    8.  
    9. float4 MainColor = float4(1,1,1,1);
    10. float3 lightDir1 = float3(1,1,1);
    11. float3 lightDir2 = float3(-1,-1,-1);
    12. float4 specularPower = 30;
    13. float Kd = 1;
    14. float Ks = 1;
    15. float Kr = 1;
    16.  
    17.  
    18. bool useTextureMap = false;
    19. bool useSpecMap = true;
    20. bool useNormalMap = false;
    21. bool useEnvMap = false;
    22. bool useMatcap = false;
    23.  
    24. //Texture Map
    25. texture ColorMap;
    26. sampler C_Sampler = sampler_state {
    27. Texture = <ColorMap>;
    28. MinFilter = Linear;
    29. MagFilter = Linear;
    30. MipFilter = Linear;
    31. };
    32.  
    33. //Normal Map
    34. texture NormalMap;
    35. sampler N_Sampler = sampler_state {
    36. Texture = <NormalMap>;
    37. MinFilter = Linear;
    38. MagFilter = Linear;
    39. MipFilter = Linear;
    40. };
    41.  
    42. //Environment Map
    43. texture EnvironmentMap;
    44. sampler Env_Sampler = sampler_state{
    45. Texture = <EnvironmentMap>;
    46. MinFilter = Linear;
    47. MagFilter = Linear;
    48. MipFilter = Linear;
    49.  
    50. };
    51.  
    52. //Specular Map
    53. texture SpecularMap;
    54. sampler Spec_Sampler = sampler_state{
    55. Texture = <SpecularMap>;
    56. MinFilter = Linear;
    57. MagFilter = Linear;
    58. MipFilter = Linear;
    59. };
    60.  
    61.  
    62. //Matcap Map
    63. texture MatcapMap;
    64. sampler Matcap_Sampler = sampler_state{
    65. Texture = <MatcapMap>;
    66. MinFilter = Linear;
    67. MagFilter = Linear;
    68. MipFilter = Linear;
    69. };
    70.  
    71.  
    72. struct VS_INPUT
    73. {
    74. float4 Position : POSITION0;
    75. float2 TexCoord : TEXCOORD0; //Gets and stores the UV information
    76. float3 Normal : NORMAL0;
    77. float3 Tangent : TANGENT0;
    78. float4 BoneIndices : BLENDINDICES0;
    79. float4 BoneWeights : BLENDWEIGHT0;
    80. float3 TtoV0 : TEXCOORD1;
    81. float3 TtoV1 : TEXCOORD2;
    82. };
    83.  
    84. struct VS_OUTPUT
    85. {
    86. float4 Position : POSITION0;
    87. float2 TexCoord : TEXCOORD0; //UV coord output
    88. float3 Data1 : TEXCOORD1;
    89. float3 Data2 : TEXCOORD2;
    90. float3 Data3 : TEXCOORD3;
    91. float3 Tangent : TEXCOORD6;
    92. float3 TtoV0 : TEXCOORD4;
    93. float3 TtoV1 : TEXCOORD5;
    94. };
    95.  
    96. VS_OUTPUT VSBasic(VS_INPUT input) {
    97. VS_OUTPUT output;
    98.  
    99. //For every bone transform
    100. float4x4 skinTransform = 0;
    101. skinTransform += Bones[input.BoneIndices.x] * input.BoneWeights.x;
    102. skinTransform += Bones[input.BoneIndices.y] * input.BoneWeights.y;
    103. skinTransform += Bones[input.BoneIndices.z] * input.BoneWeights.z;
    104. skinTransform += Bones[input.BoneIndices.w] * input.BoneWeights.w;
    105.  
    106. //Transforming the point with the bone transforms, then view matrix and projection matrix
    107. float4 pos = mul(input.Position, skinTransform);
    108. float3 eyeLoc = mul(View._m30_m31_m32, transpose(View));
    109. float3 eyeDir = eyeLoc - pos;
    110.  
    111. pos = mul(pos,View);
    112. pos = mul(pos,Projection);
    113.  
    114. //The normals
    115. float3 nml = mul(input.Normal, skinTransform);
    116. nml = normalize(nml); //Normalize the normal
    117.  
    118. output.Position = pos;
    119. output.TexCoord = input.TexCoord;
    120.  
    121. output.Data1 = nml;
    122. output.Data2 = eyeDir;
    123. output.Data3 = 0;
    124. return output;
    125. }
    126.  
    127. //Vertex shader for normal calculations
    128. VS_OUTPUT VSNormals(VS_INPUT input) {
    129. VS_OUTPUT output;
    130.  
    131. //For every bone transform
    132. float4x4 skinTransform = 0;
    133. skinTransform += Bones[input.BoneIndices.x] * input.BoneWeights.x;
    134. skinTransform += Bones[input.BoneIndices.y] * input.BoneWeights.y;
    135. skinTransform += Bones[input.BoneIndices.z] * input.BoneWeights.z;
    136. skinTransform += Bones[input.BoneIndices.w] * input.BoneWeights.w;
    137.  
    138. //Transforming the point with the bone transforms, then view matrix and projection matrix
    139. float4 pos = mul(input.Position, skinTransform);
    140. float3 eyeLoc = mul(View._m30_m31_m32, transpose(View));
    141. float3 eyeDir = eyeLoc - pos;
    142.  
    143. pos = mul(pos,View);
    144. pos = mul(pos,Projection);
    145.  
    146. //Tangent, normal, binormal
    147. float3x3 tangentSpace;
    148. tangentSpace[0] = mul(input.Tangent, skinTransform);
    149. tangentSpace[1] = mul(cross(input.Tangent, input.Normal), skinTransform);
    150. tangentSpace[2] = mul(input.Normal, skinTransform);
    151. float3 tgtLightDir1 = mul(tangentSpace, lightDir1);
    152. float3 tgtLightDir2 = mul(tangentSpace, lightDir2);
    153.  
    154. output.Position = pos;
    155. output.TexCoord = input.TexCoord;
    156.  
    157. output.Data1 = normalize(tgtLightDir1);
    158. output.Data2 = normalize(tgtLightDir2);
    159. output.Data3 = normalize(mul(tangentSpace,eyeDir));
    160.  
    161. output.Tangent = input.Tangent;
    162.  
    163. output.TtoV0 = tgtLightDir1;
    164. output.TtoV1 = tgtLightDir2;
    165.  
    166. output.TtoV0 = normalize(mul(tangentSpace, WorldInverseTranspose[0].xyz));
    167. output.TtoV1 = normalize(mul(tangentSpace, WorldInverseTranspose[1].xyz));
    168.  
    169. return output;
    170. }
    171.  
    172.  
    173. float4 PSNormals(VS_OUTPUT input) : COLOR0{
    174.  
    175. float4 outColor = tex2D(C_Sampler, input.Tangent);
    176. float3 normal = 2 * tex2D(N_Sampler, input.Tangent)- 1.0;
    177. normal = normalize(normal);
    178. half2 vn;
    179. vn.x = dot(input.TtoV0, normal);
    180. vn.y = dot(input.TtoV1, normal);
    181.  
    182.  
    183. float4 matcapLookup = tex2D(Matcap_Sampler, vn*0.5 + 0.5);
    184.  
    185. if (useTextureMap){
    186. matcapLookup.a = tex2D(C_Sampler, input.Tangent).a*0.5;
    187. matcapLookup.rgb += tex2D(C_Sampler, input.Tangent).rgb*0.5-0.4;
    188. }
    189.  
    190.  
    191. return matcapLookup;
    192. }
    193.  
    194.  
    195. technique Technique1
    196. {
    197. pass Pass1
    198. {
    199. VertexShader = compile vs_2_0 VSNormals();
    200.  
    201. ZEnable = true;
    202. //CullMode = CCW;
    203. PixelShader = compile ps_2_0 PSNormals();
    204. }
    205. }
  • Joost
    Offline / Send Message
    Joost polycount sponsor
    This thread deserves a necro. Great shader for previewing surfaces and smoothing.

    It works fine for me with nitrous in 2012, but unfortunately it doesn't work with SSAO.
    I'd pay for a matcap shader with working SSAO :(
  • RGhost
    Offline / Send Message
    RGhost polycounter lvl 14
    I fixed Matballz shader to get it work with directx11 and wrote maxscript for creating material library with matcaps. http://veda3d.com/creating-lit-sphere-material-in-3dsmax/


  • musashidan
    Offline / Send Message
    musashidan high dynamic range
    RGhost said:
    I fixed Matballz shader to get it work with directx11 and wrote maxscript for creating material library with matcaps. http://veda3d.com/creating-lit-sphere-material-in-3dsmax/


    Thanks for your article. I renewed my interest in this a little while ago and came across your post. I didn't need to look any further, so thanks. I made a quick vid tut a while back, referencing your site and information. Hope you don't mind.

    https://www.youtube.com/watch?v=DpsfwnIquZY

  • RGhost
    Offline / Send Message
    RGhost polycounter lvl 14
    Thanks for your article. I renewed my interest in this a little while ago and came across your post. I didn't need to look any further, so thanks. I made a quick vid tut a while back, referencing your site and information. Hope you don't mind.
    Glad that you find this article useful. :) I like your vid, I will add link to it  in my article.
  • hansolocambo
    Offline / Send Message
    hansolocambo polycounter lvl 8
    Could someone please post the original fx version that worked with DirectX 9 ? The link at the beginning of this threat or on veda3D is dead. And I really need (for plugins reasons) to stick with 3DSMax 2013 which doesn't have DirectX11 available in the viewports Display Drivers !
    Hope someone still have the file ! (Matballz.fx )
  • RGhost
    Offline / Send Message
    RGhost polycounter lvl 14
    Could someone please post the original fx version that worked with DirectX 9 ? The link at the beginning of this threat or on veda3D is dead. And I really need (for plugins reasons) to stick with 3DSMax 2013 which doesn't have DirectX11 available in the viewports Display Drivers !
    Hope someone still have the file ! (Matballz.fx )

    I fixed link to original shader, you can download from the page of my article.
13
Sign In or Register to comment.