Advanced Member BluEgo Posted May 24, 2009 Advanced Member Report Share Posted May 24, 2009 Hello Akira! I am starting to to study cgshaders, but I have some difficulties. For example I really would like to know how you can create a matcap shader. Theorically I thought that for every normal you substitute a pixel of your ball image, but I am not sure. Can you give me some suggestions please ? Thank you ! Quote Link to comment Share on other sites More sharing options...
philnolan3d Posted May 24, 2009 Report Share Posted May 24, 2009 All I did for mine was create a sphere in LightWave, texture it how I liked, then render it. Quote Link to comment Share on other sites More sharing options...
Advanced Member BluEgo Posted May 24, 2009 Advanced Member Report Share Posted May 24, 2009 All I did for mine was create a sphere in LightWave, texture it how I liked, then render it. Sorry philnolan3d, I didn't mean how to use ball images, but how to write the code to use them Quote Link to comment Share on other sites More sharing options...
philnolan3d Posted May 24, 2009 Report Share Posted May 24, 2009 Oh I see, I misread. Quote Link to comment Share on other sites More sharing options...
Advanced Member akira Posted May 24, 2009 Advanced Member Report Share Posted May 24, 2009 Hello Akira!I am starting to to study cgshaders, but I have some difficulties. For example I really would like to know how you can create a matcap shader. Theorically I thought that for every normal you substitute a pixel of your ball image, but I am not sure. Can you give me some suggestions please ? Thank you ! Hi, I won't call them matcap shaders, I don't know how exactly matcap shaders work either. The basic idea of picmat shaders is to use view-space normal to index the pixel of the shader ball texture, you'll find good explanation here: see page 109 ~ 112 http://developer.nvidia.com/object/nvision08-bwotf.html Hope this helps. akira. Quote Link to comment Share on other sites More sharing options...
Advanced Member erklaerbar Posted May 24, 2009 Advanced Member Report Share Posted May 24, 2009 theres a GLSL version of it you could have a look at, which can be downloaded here: http://www.xsiforum.de/thread.php?postid=84424 Quote Link to comment Share on other sites More sharing options...
Advanced Member cakeller Posted October 23, 2009 Advanced Member Report Share Posted October 23, 2009 Sorry to hear that I'll keep on looking for a solution for this. Does these circles appear in GL version too? ARG, I have these rings! I assumed the rings were just an artifact and part of the way it was supposed to be (although they didn't look nice, I just don't use them) Anyway, I have the nVidia QuadroFX 3450 with 256MB and the rings show up in GL and DX... I still get all the same rings as mentioned before... any thoughts? Quote Link to comment Share on other sites More sharing options...
Advanced Member cakeller Posted December 7, 2009 Advanced Member Report Share Posted December 7, 2009 Sorry philnolan3d, I didn't mean how to use ball images, but how to write the code to use them if all you want is to create your own PicMat style shader, right click on any of the existing PicMat shaders (e.g. Red Plastic), and "Construct New Shader", then give it a name, then when the settings box comes up, Choose a new picmat image. you don't HAVE to write any code, because the shader code will be copied automatically for you. That's not to say you can't write shaders on your own... because you can. I have learned a lot just by opening up the shaders, copying them and experimenting. There are a few little quirky things to 3DC implementation of the GLSL and HLSL shaders but for the most part pretty standard vertex and pixel shaders. However, I think you really were just asking about how to use your picmat images, and the short answer - copy a shader, replace the picmat. the shader name is the name of the folder. couldn't be much more simple! Quote Link to comment Share on other sites More sharing options...
Member Heath_3d Posted January 5, 2010 Member Report Share Posted January 5, 2010 Hi Guys, I modified an existing shader to get this result, which is exactly what I'm after(essentially the tree shader with normal mapping for doing landscapes and the like). But a few things were amiss. First, I'm not getting any thumbnail showing up in the shader pallette. Second, when I try to bake out I'm just getting black on my color layer and my normal textures are being ignored. Third, My texture selection buttons don't work at all for the normal map. In short.... It's useless As I'm not a coder at all, I'm actually pretty surprised I got this far; but if anyone can see it in their heart to make their own modified shader to do this, or point me in the right direction I'd be really grateful. Here hoping, Heath Quote Link to comment Share on other sites More sharing options...
philnolan3d Posted January 5, 2010 Report Share Posted January 5, 2010 I can help you with the first problem at least, Just right click the icon and pick Refresh This Preview. That will generate the icon for you. Quote Link to comment Share on other sites More sharing options...
Member Heath_3d Posted January 5, 2010 Member Report Share Posted January 5, 2010 Thanks Phil, That got that problem solved. I think the others might be tied into the "Method" section of the variables XML for the shader. When I don't alter the XML file at all, the shader bakes, but only respects the sides color and normal maps. For those in the know, here's the HLSL code with the changes (don't laugh ). // Vertex shader float4x4 g_WorldViewProjectionMatrix; float4x4 g_WorldMatrix; float3 g_ViewerPos; float4 Sphere; float OverallScale; float4x4 ShadowTM; struct VS_INPUT { float3 Pos : POSITION; float3 Normal : TEXCOORD0; }; struct VS_OUTPUT { float4 Pos : POSITION; float3 N : TEXCOORD1; float3 Ps : TEXCOORD3; #ifdef SHADOWS float3 SPos : TEXCOORD2; #endif }; VS_OUTPUT main(const VS_INPUT In) { VS_OUTPUT Out; float4 P = float4(In.Pos, 1.0); Out.Pos = mul(P, g_WorldViewProjectionMatrix); Out.N = In.Normal; Out.Ps = In.Pos*0.005/OverallScale; #ifdef SHADOWS Out.SPos = mul(P, ShadowTM); Out.SPos.xy += float2(1.0/4096.0f,1.0/4096.0); #endif return Out; } // Pixel shader struct VS_OUTPUT { float4 Pos : POSITION; float3 N : TEXCOORD1; float3 Ps : TEXCOORD3; #ifdef SHADOWS float3 SPos : TEXCOORD2; #endif }; sampler ShadowSampler; sampler CustomSampler1; sampler CustomSampler2; sampler CustomSampler3; // Change number one added a couple of custom samplers sampler CustomSampler4; sampler CustomSampler5; float4 Color; float4 CurrColor; float4 ColorMod; float4 SpecularColor; float3 LDir; float3 VDir; float LDiffuse; float LAmbient; float Opacity; float ShadowMin; float Bumpness; float Specularity; float SpecularPower; float4 main( const VS_OUTPUT v ) : COLOR { float mpl=1.0; float4 mxy=tex2D(CustomSampler1,v.Ps.xy); float4 myz=tex2D(CustomSampler1,v.Ps.yz); // Change number Two changed custom sampler for zx float4 mzx=tex2D(CustomSampler4,v.Ps.zx); float4 nxy=tex2D(CustomSampler2,v.Ps.xy); float4 nyz=tex2D(CustomSampler2,v.Ps.yz); // Finally changed custom sampler for zx float4 nzx=tex2D(CustomSampler5,v.Ps.zx); float wxy=v.N.z*v.N.z; float wyz=v.N.x*v.N.x; float wzx=v.N.y*v.N.y; float3 dN=float3(nxy.x-0.5,0.5-nxy.y,0.0)*wxy*Bumpness; dN+=float3(0.0,nyz.x-0.5,0.5-nyz.y)*wyz*Bumpness; dN+=float3(0.5-nzx.y,0.0,nzx.x-0.5)*wzx*Bumpness; wxy*=wxy; wyz*=wyz; wzx*=wzx; mxy=(mxy*wxy+myz*wyz+mzx*wzx)/(wxy+wyz+wzx); #ifdef SHADOWS float3 m=tex2D(ShadowSampler,v.SPos).xyz; float3 d=float3(1.0,1.0/255.0,1.0/255.0/255.0); mpl=clamp(2.0-(v.SPos.z-dot(m,d))*120,ShadowMin,1); #endif float L=length(v.N); float3 N=normalize(v.N-dN); float3 refl = VDir-2.0*N*dot(VDir,N); float S = dot(refl,LDir); float dd=clamp(L-1.0,0.0,1.0); S=clamp(S,0.0,1.0); #ifdef AOPASS float D = LAmbient-LDiffuse*dot(N,LDir)*mpl; #else float D = -LDiffuse*dot(N,LDir)*mpl; #endif float4 C=ColorMod*D*mxy*2+SpecularColor*pow(S,SpecularPower*mxy.w)*Specularity*mpl*mpl*mxy.w; float4 c1=tex2D(CustomSampler3,float2(dd,0)); C=lerp(C,c1,dd); C.w=Opacity; return C; } Quote Link to comment Share on other sites More sharing options...
Member Heath_3d Posted January 6, 2010 Member Report Share Posted January 6, 2010 Ultimately I'd like to get a fully fledged terrain shader.I've been having a lot of fun using 3d coat for doing a mesa desert scene I'm working on and would like to do more, but take out a bit of the textureing work. The final custom settings I'd like are: Top col map Bottom col map side col map Top norm map Bottom norm map Side Norm map Slope (Top to Side Blend) Slider Bump Amount Slider Top Specular Amount Slider Side Specular Amount Slider Bottom Specular Amount Slider Cavity Col picker Cavity Col affects COL/SPEC check boxes Maybe this belongs in the features request thread, But as it's the ultimate goal of my current dilemma I thought I'd post it here. Any help appreciated, Heath Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.