Jump to content

realtime vertex paint without render preview


xdxxdy
 Share

Recommended Posts

string ParamID = "0x000001";

texture TextureMap_125 : DiffuseMap

<

string ResourceName = "";

string UIName = "Texture Map";

string ResourceType = "2D";

>;

sampler2D TextureMap_125Sampler = sampler_state

{

Texture = <TextureMap_125>;

MinFilter = LINEAR;

MagFilter = LINEAR;

MipFilter = LINEAR;

AddressU = WRAP;

AddressV = WRAP;

};

texture TextureMap_7516 : DiffuseMap

<

string ResourceName = "";

string UIName = "Texture Map";

string ResourceType = "2D";

>;

sampler2D TextureMap_7516Sampler = sampler_state

{

Texture = <TextureMap_7516>;

MinFilter = LINEAR;

MagFilter = LINEAR;

MipFilter = LINEAR;

AddressU = WRAP;

AddressV = WRAP;

};

int texcoord0 : Texcoord

<

int Texcoord = 0;

int MapChannel = 1;

string UIWidget = "None";

>;

int texcoord1 : Texcoord

<

int Texcoord = 1;

int MapChannel = 2;

string UIWidget = "None";

>;

int texcoord2 : Texcoord

<

int Texcoord = 2;

int MapChannel = 3;

string UIWidget = "None";

>;

int texcoord3 : Texcoord

<

int Texcoord = 3;

int MapChannel = 0;

string UIWidget = "None";

>;

int texcoord4 : Texcoord

<

int Texcoord = 4;

int MapChannel = -2;

string UIWidget = "None";

>;

float3 light1Pos : POSITION

<

string UIName = "Light 1 Position";

string Object = "PointLight";

string Space = "World";

int refID = 1;

> = {100.0f, 100.0f, 100.0f};

float4 light1Color : LIGHTCOLOR

<

int LightRef = 1;

string UIWidget = "None";

> = { 1.0f, 1.0f, 1.0f, 1.0f};

float4x4 wvp : WorldViewProjection < string UIWidget = "None"; >;

float4x4 worldI : WorldInverse < string UIWidget = "None"; >;

float4x4 worldIT : WorldInverseTranspose < string UIWidget = "None"; >;

float4x4 viewInv : ViewInverse < string UIWidget = "None"; >;

float4x4 world : World < string UIWidget = "None"; >;

struct a2v {

float4 position : POSITION;

float3 tangent : TANGENT;

float3 binormal : BINORMAL;

float3 normal : NORMAL;

float2 texCoord : TEXCOORD0;

float3 vertcol : TEXCOORD3;

float vertalpha : TEXCOORD4;

};

struct v2f {

float4 position : POSITION;

float3 light1Vec : TEXCOORD0;

float2 texCoord : TEXCOORD1;

float4 color : COLOR;

};

v2f v(a2v In, uniform float3 lightPosition)

{

v2f Out = (v2f)0;

Out.position = mul(In.position, wvp);

float3x3 objTangentXf;

#ifdef YUP

objTangentXf[0] = In.tangent;

objTangentXf[1] = -In.binormal;

#else

objTangentXf[0] = In.binormal;

objTangentXf[1] = -In.tangent;

#endif

objTangentXf[2] = In.normal;

float3 wsL1Pos = mul(In.position, world).xyz;

float3 wsL1Vec = light1Pos - wsL1Pos;

float3 osL1Vec = mul(wsL1Vec, worldI).xyz;

Out.light1Vec = mul(objTangentXf, osL1Vec);

Out.texCoord = In.texCoord;

Out.texCoord.y += 1.0f;

float4 VertColor = float4(In.vertcol.rgb, In.vertalpha.r);

Out.color = VertColor;

return Out;

}

float4 f(v2f In, uniform float4 lightColor) : COLOR

{

float4 TextureMap_125 = tex2D(TextureMap_125Sampler, In.texCoord.xy);

float4 TextureMap_7516 = tex2D(TextureMap_7516Sampler, In.texCoord.xy);

float4 INVertColor_5120 = In.color;

float3 MathLerp_8483 = lerp(TextureMap_125.rgb, TextureMap_7516.rgb, INVertColor_5120.r);

float3 input2 = MathLerp_8483;

float3 ret = float3(0,0,0);

float3 N = float3(0.0, 0.0, 1.0);

float3 L1 = normalize(In.light1Vec.xyz);

float3 light1 = saturate(dot(N, L1)) * light1Color.xyz * input2;

ret += light1;

float4 done = float4(ret, 1);

return done;

}

technique Complete

{

pass one

{

VertexShader = compile vs_1_1 v(light1Pos);

ZEnable = true;

ZWriteEnable = true;

CullMode = cw;

AlphaBlendEnable = false;

PixelShader = compile ps_3_0 f(light1Color);

}

}

save this in a .fx file

this is a shader to make interactive texture blend painting in max8

1° create a new material of kind directx 9 shader

2° load the effect .fx and chose the two texture that you want blend

3° add a vetex paint at the object that you want texturing

4° apply the material directx 9

5° start paint, you will see the blending in realtime.

Bye

ps. remember remane the material to respect the declaration in the materials.xml

Link to comment
Share on other sites

HI xdxxdy!

You could explain a little better how to apply the effect to the material? ^_^

I succeeded in creating the material DX9, but only I get a box for choosing 1 material (not 2 that you say) .... and I dont know how to load the file I created (with the notebook, and to renamed .fx) in 3DS MAX :unsure:

Thanks for all :)

Link to comment
Share on other sites

Galor' date='Apr 21 2008, 10:13 AM' post='519294']

HI xdxxdy!

You could explain a little better how to apply the effect to the material? ^_^

I succeeded in creating the material DX9, but only I get a box for choosing 1 material (not 2 that you say) .... and I dont know how to load the file I created (with the notebook, and to renamed .fx) in 3DS MAX :unsure:

Thanks for all :)

click on yellow button and select the .fx just created in notepad

t_fxm_f98796e.jpg

selected the two textures apply the material to the object and apply a vertexpaint modifier, now you can paint

t_matm_24f7746.jpg

Bye

Edited by xdxxdy
Link to comment
Share on other sites

Nice. This is what we used, but with normal map support as well (which is not needed).

On a side note, you may notice that normal maps don't blend well with the vertex colors though. They never smoothly blend.

Hi

this is a new version with normal bump maps blended and specular power, derived from alpha chanell of the diffuse textures, always blended by the vertex color .



string ParamID = "0x000001";




texture TextureMap_5818

<

	string ResourceName = "";

	string UIName = "diffuse";

	string ResourceType = "2D";

>;


sampler2D TextureMap_5818Sampler = sampler_state

{

	Texture = <TextureMap_5818>;

	MinFilter = LINEAR;

	MagFilter = LINEAR;

	MipFilter = LINEAR;

	AddressU = WRAP;

	AddressV = WRAP;

};


texture TextureMap_1132

<

	string ResourceName = "";

	string UIName = "self_illumination";

	string ResourceType = "2D";

>;


sampler2D TextureMap_1132Sampler = sampler_state

{

	Texture = <TextureMap_1132>;

	MinFilter = LINEAR;

	MagFilter = LINEAR;

	MipFilter = LINEAR;

	AddressU = WRAP;

	AddressV = WRAP;

};



int texcoord0 : Texcoord 

<

	int Texcoord = 0;

	int MapChannel = 1;

	string UIWidget = "None"; 

>;


int texcoord1 : Texcoord 

<

	int Texcoord = 1;

	int MapChannel = 2;

	string UIWidget = "None"; 

>;


int texcoord2 : Texcoord 

<

	int Texcoord = 2;

	int MapChannel = 3;

	string UIWidget = "None"; 

>;


int texcoord3 : Texcoord 

<

	int Texcoord = 3;

	int MapChannel = 0;

	string UIWidget = "None"; 

>;


int texcoord4 : Texcoord 

<

	int Texcoord = 4;

	int MapChannel = -2;

	string UIWidget = "None"; 

>;


float4 UIColor_1785

<

	string UIName = "bump_test";

	string UIWidget = "Color";

> = {0.0f, 0.0f, 0.0f, 1.0f };


float UIConst_7268

<

	string UIWidget = "Spinner";

	float UIMin = 0.0;

	float UIMax = 10.0;

	float UIStep = 0.1;

	string UIName = "specular";

> = 1.0;


texture NormalMap_2411 : NormalMap

<

	string ResourceName = "";

	string UIName = "bump_normal";

	string ResourceType = "2D";

>;


sampler2D NormalMap_2411Sampler = sampler_state

{

	Texture = <NormalMap_2411>;

	MinFilter = LINEAR;

	MagFilter = LINEAR;

	MipFilter = LINEAR;

	AddressU = WRAP;

	AddressV = WRAP;

};


texture NormalMap_5583 : NormalMap

<

	string ResourceName = "";

	string UIName = "distorsion";

	string ResourceType = "2D";

>;


sampler2D NormalMap_5583Sampler = sampler_state

{

	Texture = <NormalMap_5583>;

	MinFilter = LINEAR;

	MagFilter = LINEAR;

	MipFilter = LINEAR;

	AddressU = WRAP;

	AddressV = WRAP;

};


float UIConst_1094

<

	string UIWidget = "Spinner";

	float UIMin = 0.0;

	float UIMax = 1.0;

	float UIStep = 0.1;

	string UIName = "bump";

> = 1.0;






float3 light1Pos : POSITION 

< 

	string UIName = "Light 1 Position"; 

	string Object = "PointLight"; 

	string Space = "World"; 

		int refID = 1; 

> = {100.0f, 100.0f, 100.0f}; 




float4 light1Color : LIGHTCOLOR 

< 

		int LightRef = 1; 

		string UIWidget = "None"; 

> = { 1.0f, 1.0f, 1.0f, 1.0f}; 




float4x4 wvp : WorldViewProjection < string UIWidget = "None"; >;  

float4x4 worldI : WorldInverse < string UIWidget = "None"; >;  

float4x4 worldIT : WorldInverseTranspose < string UIWidget = "None"; >;  

float4x4 viewInv : ViewInverse < string UIWidget = "None"; >;  

float4x4 world : World < string UIWidget = "None"; >;  



	struct a2v { 

	float4 position		: POSITION; 

	float3 tangent		: TANGENT; 

	float3 binormal		: BINORMAL; 

	float3 normal		: NORMAL; 


	float2 texCoord		: TEXCOORD0; 

	float3 vertcol		: TEXCOORD3; 

	float vertalpha 	: TEXCOORD4; 


}; 



struct v2f { 

		float4 position			: POSITION; 

		float3 lightVec			: TEXCOORD0; 

		float3 eyeVec			: TEXCOORD1; 


		float2 texCoord			: TEXCOORD2; 

		float4 color			: COLOR; 


}; 



v2f v(a2v In, uniform float3 lightPosition) 

{ 

	v2f Out = (v2f)0; 

	Out.position = mul(In.position, wvp);


	float3x3 objTangentXf;

#ifdef YUP 

		objTangentXf[0] = In.tangent; 

		objTangentXf[1] = -In.binormal; 

#else 

		objTangentXf[0] = In.binormal; 

		objTangentXf[1] = -In.tangent; 

#endif 

		objTangentXf[2] = In.normal; 


	float3 wsLPos = mul(In.position, world).xyz;

	float3 wsLVec = lightPosition - wsLPos;

	float3 osLVec = mul(wsLVec, worldI).xyz;

	Out.lightVec = mul(objTangentXf, osLVec);


	float4 osIPos = mul(viewInv[3], worldI);

	float3 osIVec = osIPos.xyz - In.position.xyz;

	Out.eyeVec = mul(objTangentXf, osIVec);



	Out.texCoord = In.texCoord;

	Out.texCoord.y += 1.0f;


	float4 VertColor = float4(In.vertcol.rgb, In.vertalpha.r); 

	Out.color = VertColor; 



	return Out; 

} 



float4 f(v2f In, uniform float4 lightColor) : COLOR 

{ 

	float3 ret = float3(0,0,0); 

	float3 V = normalize(In.eyeVec);

	float3 L = normalize(In.lightVec);


	float4 TextureMap_5818 = tex2D(TextureMap_5818Sampler, In.texCoord.xy);

	float4 TextureMap_1132 = tex2D(TextureMap_1132Sampler, In.texCoord.xy);

	float4 INVertColor_8620 = In.color;

	float3 MathLerp_1532 = lerp(TextureMap_5818.rgb, TextureMap_1132.rgb, INVertColor_8620.r); 

	float3 MathLerp_2973 = lerp(MathLerp_1532, UIColor_1785, UIColor_1785); 

	float3 input2 = MathLerp_2973; 



	float MathLerp_4797 = lerp(TextureMap_5818.a, TextureMap_1132.a, INVertColor_8620.r); 

	float MathOperator_1853 = MathLerp_4797 * UIConst_7268;

	float input4 = MathOperator_1853; 



	float3 Normal = float3(0,0,1);

	float4 NormalMap_2411 = tex2D(NormalMap_2411Sampler, In.texCoord.xy);

	NormalMap_2411.xyzw = NormalMap_2411.wyzz;

	NormalMap_2411.xyz = NormalMap_2411.xyz * 2 - 1;

	NormalMap_2411.z = sqrt(1 - NormalMap_2411.x * NormalMap_2411.x - NormalMap_2411.y * NormalMap_2411.y);

	NormalMap_2411.rgb = normalize(NormalMap_2411.rgb);

	float4 NormalMap_5583 = tex2D(NormalMap_5583Sampler, In.texCoord.xy);

	NormalMap_5583.xyzw = NormalMap_5583.wyzz;

	NormalMap_5583.xyz = NormalMap_5583.xyz * 2 - 1;

	NormalMap_5583.z = sqrt(1 - NormalMap_5583.x * NormalMap_5583.x - NormalMap_5583.y * NormalMap_5583.y);

	NormalMap_5583.rgb = normalize(NormalMap_5583.rgb);

	float3 MathLerp_1363 = lerp(NormalMap_2411.rgb, NormalMap_5583.rgb, INVertColor_8620.r); 

	float3 MathLerp_3078 = lerp(Normal, MathLerp_1363, UIConst_1094); 

	float3 input8 = MathLerp_3078; 


	float3 N = input8;

	float3 diffuseColor = input2;

	float diffuse = saturate(dot(N,L));

	diffuseColor *= diffuse;

	ret += diffuseColor;

	float specularColor = input4;

	float glossiness = 20;

	float3 H = normalize(L + V);

	float NdotH = saturate(dot(N,H));

	specularColor *= pow(NdotH, glossiness);

	ret += specularColor;

	ret *= lightColor;

	float4 done = float4(ret, 1);

	return done; 

} 


technique Complete  

{  

	pass light1  

	{		 

	VertexShader = compile vs_1_1 v(light1Pos); 

	ZEnable = true; 

	CullMode = cw; 

	ZWriteEnable = true; 

	DestBlend = One; 

	AlphaBlendEnable = false; 

	PixelShader = compile ps_2_0 f(light1Color); 

	}  


}  


Link to comment
Share on other sites

Hi !!

When I try to access the material DX9, not me out in the list. I have to choose "Incompatible" and I get gray.

dx91rv5.th.jpg

When it is selected, I do not find entries that will appear to you, put it in the image.

dx92wb2.th.jpg

Should I activate any other option or install some kind of program?

Thank you :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...