Member Daniko Posted July 17, 2014 Member Report Share Posted July 17, 2014 Hi, I will preface by saying i am not a programmer type, but wanted to make a change to one of the shaders i use with 3Dcoat. I opened up the hlsl file in notepad++, and managed to understand enough to find the variable that needed changing to get what i want. // 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; 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 LightColor; float4 main( const VS_OUTPUT v ) : COLOR { float mpl=1.0; float4 mxy=tex2D(CustomSampler1,v.Ps.xy); float4 myz=tex2D(CustomSampler1,v.Ps.zy); float4 mzx=tex2D(CustomSampler1,v.Ps.zx); float4 nxy=tex2D(CustomSampler2,v.Ps.xy); float4 nyz=tex2D(CustomSampler2,v.Ps.zy); float4 nzx=tex2D(CustomSampler2,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*c1.w); C.w=Opacity; return C*LightColor; } I highlighted the lines where i simply changed the .yz to .zy, and when viewing an example object in the vox room in 3d coat, i now have my bricks in this case, wrap around the wall or cube the way i was hoping. however, when i bake this to a retopo mesh, the textures still project as in the .yz orientation..... Can someone help me understand what changes i need to make so that the displayed voxel representation, and the low poly baked output are the same? Quote Link to comment Share on other sites More sharing options...
Member Daniko Posted July 17, 2014 Author Member Report Share Posted July 17, 2014 Sorry, the Highlights didn't show. The two lines where i flipped the .yz are line 71 and 75. Quote Link to comment Share on other sites More sharing options...
Carlosan Posted July 17, 2014 Report Share Posted July 17, 2014 changing variables.xml help ? Do you tested to use the shader ? Program Files\3D-Coat-V4\Shaders\Custom\Txtr_Tree01 Quote Link to comment Share on other sites More sharing options...
Member Daniko Posted July 17, 2014 Author Member Report Share Posted July 17, 2014 Hi, it seems the variables.xml is just exposing certain variables/slider options but i am changing a variable that isn't exposed through the interface. The txtr_tree01 does project/wrap the texture the same way i am looking for, but doesn't have the bump-mapping. If i could figure out how to add bump mapping to that shader, it would be fine too, but it seems easier for a total novice like me to just get the projection parameter changed in the shader with the bump-map. I am trying to study some 3d math/hlsl shader documents to see if i can understand what is going on in the matrix-math area of the shader.... but ....ugh..... Quote Link to comment Share on other sites More sharing options...
Carlosan Posted July 17, 2014 Report Share Posted July 17, 2014 bump map try bake (merge) into scene microverts more info related http://3d-coat.com/forum/index.php?showtopic=15039 Quote Link to comment Share on other sites More sharing options...
Member Daniko Posted July 17, 2014 Author Member Report Share Posted July 17, 2014 What i mean is, the normal map bakes just fine in the above shader, and that is the result want. If i can just figure out how to get the .zy - .yz projection of the texture to bake as it is displayed in the viewport, i'm good to go. The first image shows the viewport, the second image shows the result of baking, where the bricks go the wrong direction on the sides of the cube. Quote Link to comment Share on other sites More sharing options...
Contributor TimmyZDesign Posted July 17, 2014 Contributor Report Share Posted July 17, 2014 Have you tried the other shaders? Some of them have more variables exposed than others. The super shader has a bunch. Also some shaders don't bake well, while others bake fine. Quote Link to comment Share on other sites More sharing options...
Carlosan Posted July 18, 2014 Report Share Posted July 18, 2014 BRICKS.3dcpack Quote Link to comment Share on other sites More sharing options...
Member Daniko Posted July 18, 2014 Author Member Report Share Posted July 18, 2014 Right, so like i was saying, i want to get the brick-type wrap-around working with the normal-map shader. What i've discovered is that the bake settings seem to be hard-wired/called from the method <id> of the variable.xml file. So <ID>CubicTopSide</ID> method wraps the way i want, but doesn't bake the Normal mapping of the shader, and <ID>CubicNormalmap</ID> bakes the NormalMaps from the shader, but doesn't wrap around the object, regardless of the customized code in the .hlsl file itself. Maybe i'm out of luck? or maybe there is a place where i can modify the baking method? I guess this wasn't simple as i had hoped. 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.