Texture 2 faces

Questions à propos du scripting Shader.
Avatar de l’utilisateur
kealkeal
Messages : 925
Inscription : 16 Juil 2010 17:31
Localisation : Paris

Texture 2 faces

Message par kealkeal » 26 Juil 2010 14:20

J'ai un plan qur lequel est appliqué une simple couleur.

Dans UNITY, ce meme plan est coloré sur une seule face. L'autre face étant totalement transparente.

Comment puis je avoir de la couleur sur les deux faces de mon plan ?

Merci.
kealkeal

Avatar de l’utilisateur
giyomuSan
Messages : 1799
Inscription : 09 Déc 2009 14:52
Localisation : Japon

Re: Texture 2 faces

Message par giyomuSan » 26 Juil 2010 16:28

il ya deja eu ca de poser de le forum

ds le code du shader que t utilise tu peu changer l aligen ou il ya marquer "Cull" a off

tiens j ai retrouver le lien qui en parle >>

viewtopic.php?f=2&t=343&p=1113&hilit=culling#p1113

Avatar de l’utilisateur
kealkeal
Messages : 925
Inscription : 16 Juil 2010 17:31
Localisation : Paris

Re: Texture 2 faces

Message par kealkeal » 26 Juil 2010 17:31

Je pense que c'est ce que cherche.

Mais je ne comprends pas lorsque tu demande de modifier le code du shader.

Ou trouves tu ce code et avec quel logiciel édites tu ce document ?
kealkeal

Avatar de l’utilisateur
giyomuSan
Messages : 1799
Inscription : 09 Déc 2009 14:52
Localisation : Japon

Re: Texture 2 faces

Message par giyomuSan » 27 Juil 2010 01:29

il est dans unity,

tu l'edite depuis unity,

les fichiers de shader ont une extension >> .shader

Avatar de l’utilisateur
kealkeal
Messages : 925
Inscription : 16 Juil 2010 17:31
Localisation : Paris

Re: Texture 2 faces

Message par kealkeal » 27 Juil 2010 09:34

Désolé mais je n'arrive pas éditer le code du shader.

Dans WONDOWS EXPLORER je retrouve bien un fichier qui s'appel : etage1_a-orig_08 - default 1 mais quand je l'ouvre cela lance ACCESS.

Je ne peux donc pas ouvrir ce fichier.

Merci pour votre aide.
Dernière édition par kealkeal le 10 Oct 2011 20:15, édité 1 fois.
kealkeal

Avatar de l’utilisateur
tekkpaf
Messages : 205
Inscription : 31 Mars 2010 10:59
Localisation : Besançon
Contact :

Re: Texture 2 faces

Message par tekkpaf » 27 Juil 2010 16:02

Tu peux récupérer les codes sources des shaders ici :

Code : Tout sélectionner

http://unity3d.com/support/resources/assets/built-in-shaders
Tu fais une copie du normal-diffuse que tu renommes normal-diffudse2sided par exemple, tu le modifies comme giyomuSan t'as expliqué et tu le mets dans tes assets pour le réutiliser.

EDIT :

cadeau :

Code : Tout sélectionner

Shader "Diffuse2sided" {
Properties {
	_Color ("Main Color", Color) = (1,1,1,1)
	_MainTex ("Base (RGB)", 2D) = "white" {}
}

Category {
	Tags { "RenderType"="Opaque" }
	LOD 200
	Blend AppSrcAdd AppDstAdd
	Fog { Color [_AddFog] }
	
	// ------------------------------------------------------------------
	// ARB fragment program
	Cull Off
	SubShader {
		// Ambient pass
		Pass {
			Name "BASE"
			Tags {"LightMode" = "PixelOrNone"}
			Color [_PPLAmbient]
			SetTexture [_MainTex] {constantColor [_Color] Combine texture * primary DOUBLE, texture * constant}
		}
		// Vertex lights
		Pass { 
			Name "BASE"
			Tags {"LightMode" = "Vertex"}
			Lighting On
			Material {
				Diffuse [_Color]
				Emission [_PPLAmbient]
			}
			SetTexture [_MainTex] { constantColor [_Color] Combine texture * primary DOUBLE, texture * constant}
		}
		// Pixel lights
		Pass {
			Name "PPL"
			Tags { "LightMode" = "Pixel" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_builtin
#pragma fragmentoption ARB_fog_exp2
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
#include "AutoLight.cginc"

struct v2f {
	V2F_POS_FOG;
	LIGHTING_COORDS
	float2	uv;
	float3	normal;
	float3	lightDir;
};

uniform float4 _MainTex_ST;

v2f vert (appdata_base v)
{
	v2f o;
	PositionFog( v.vertex, o.pos, o.fog );
	o.normal = v.normal;
	o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
	o.lightDir = ObjSpaceLightDir( v.vertex );
	TRANSFER_VERTEX_TO_FRAGMENT(o);
	return o;
}

uniform sampler2D _MainTex;

float4 frag (v2f i) : COLOR
{
	// The eternal tradeoff: do we normalize the normal?
	//float3 normal = normalize(i.normal);
	float3 normal = i.normal;
		
	half4 texcol = tex2D( _MainTex, i.uv );
	
	return DiffuseLight( i.lightDir, normal, texcol, LIGHT_ATTENUATION(i) );
}
ENDCG
		}
	}
	
 	// ------------------------------------------------------------------
	// Radeon 9000

	SubShader {
		// Ambient pass
		Pass {
			Name "BASE"
			Tags {"LightMode" = "PixelOrNone"}
			Color [_PPLAmbient]
			SetTexture [_MainTex] {constantColor [_Color] Combine texture * primary DOUBLE, texture * constant}
		}
		// Vertex lights
		Pass { 
			Name "BASE"
			Tags {"LightMode" = "Vertex"}
			Lighting On
			Material {
				Diffuse [_Color]
				Emission [_PPLAmbient]
			}
			SetTexture [_MainTex] { constantColor [_Color] Combine texture * primary DOUBLE, texture * constant}
		}
		
		// Pixel lights with 0 light textures
		Pass { 
			Name "PPL"
			Tags { 
				"LightMode" = "Pixel" 
				"LightTexCount" = "0"
			}

CGPROGRAM
#pragma vertex vert
#include "UnityCG.cginc"

struct v2f {
	V2F_POS_FOG;
	float2 uv		: TEXCOORD0;
	float3 normal	: TEXCOORD1;
	float3 lightDir	: TEXCOORD2;
};

uniform float4 _MainTex_ST;

v2f vert(appdata_base v)
{
	v2f o;
	PositionFog( v.vertex, o.pos, o.fog );
	o.normal = v.normal;
	o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
	o.lightDir = ObjSpaceLightDir( v.vertex );
	return o; 
}
ENDCG
			Program "" {
				SubProgram {
					Local 0, [_ModelLightColor0]
					Local 1, (0,0,0,0)

"!!ATIfs1.0
StartConstants;
	CONSTANT c0 = program.local[0];
	CONSTANT c1 = program.local[1];
EndConstants;

StartOutputPass;
	SampleMap r0, t0.str;			# main texture
	SampleMap r1, t2.str;			# normalized light dir
	PassTexCoord r2, t1.str;		# normal
	
	DOT3 r5.sat, r2, r1.2x.bias;	# R5 = diffuse (N.L)
	
	MUL r0, r0, r5;
	MUL r0.rgb.2x, r0, c0;
	MOV r0.a, c1;
EndPass; 
"
				}
			}
			SetTexture[_MainTex] {combine texture}
			SetTexture[_CubeNormalize] {combine texture}
		}
		
		// Pixel lights with 1 light texture
		Pass {
			Name "PPL"
			Tags { 
				"LightMode" = "Pixel" 
				"LightTexCount" = "1"
			}

CGPROGRAM
#pragma vertex vert
#include "UnityCG.cginc"

uniform float4 _MainTex_ST;
uniform float4x4 _SpotlightProjectionMatrix0;

struct v2f {
	V2F_POS_FOG;
	float2 uv		: TEXCOORD0;
	float3 normal	: TEXCOORD1;
	float3 lightDir	: TEXCOORD2;
	float4 LightCoord0 : TEXCOORD3;
};

v2f vert(appdata_tan v)
{
	v2f o;
	PositionFog( v.vertex, o.pos, o.fog );
	o.normal = v.normal;
	o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
	o.lightDir = ObjSpaceLightDir( v.vertex );
	
	o.LightCoord0 = mul(_SpotlightProjectionMatrix0, v.vertex);
	
	return o; 
}
ENDCG
			Program "" {
				SubProgram {
					Local 0, [_ModelLightColor0]
					Local 1, (0,0,0,0)

"!!ATIfs1.0
StartConstants;
	CONSTANT c0 = program.local[0];
	CONSTANT c1 = program.local[1];
EndConstants;

StartOutputPass;
	SampleMap r0, t0.str;			# main texture
	SampleMap r1, t2.str;			# normalized light dir
	PassTexCoord r4, t1.str;		# normal
	SampleMap r2, t3.str;			# a = attenuation
	
	DOT3 r5.sat, r4, r1.2x.bias;	# R5 = diffuse (N.L)
	
	MUL r0, r0, r5;
	MUL r0.rgb.2x, r0, c0;
	MUL r0.rgb, r0, r2.a;			# attenuate
	MOV r0.a, c1;
EndPass; 
"
				}
			}
			SetTexture[_MainTex] {combine texture}
			SetTexture[_CubeNormalize] {combine texture}
			SetTexture[_LightTexture0] {combine texture}
		}
		
		// Pixel lights with 2 light textures
		Pass {
			Name "PPL"
			Tags {
				"LightMode" = "Pixel"
				"LightTexCount" = "2"
			}
CGPROGRAM
#pragma vertex vert
#include "UnityCG.cginc"

uniform float4 _MainTex_ST;
uniform float4x4 _SpotlightProjectionMatrix0;
uniform float4x4 _SpotlightProjectionMatrixB0;

struct v2f {
	V2F_POS_FOG;
	float2 uv		: TEXCOORD0;
	float3 normal	: TEXCOORD1;
	float3 lightDir	: TEXCOORD2;
	float4 LightCoord0 : TEXCOORD3;
	float4 LightCoordB0 : TEXCOORD4;
};

v2f vert(appdata_tan v)
{
	v2f o;
	PositionFog( v.vertex, o.pos, o.fog );
	o.normal = v.normal;
	o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
	o.lightDir = ObjSpaceLightDir( v.vertex );
	
	o.LightCoord0 = mul(_SpotlightProjectionMatrix0, v.vertex);
	o.LightCoordB0 = mul(_SpotlightProjectionMatrixB0, v.vertex);
	
	return o; 
}
ENDCG
			Program "" {
				SubProgram {
					Local 0, [_ModelLightColor0]
					Local 1, (0,0,0,0)

"!!ATIfs1.0
StartConstants;
	CONSTANT c0 = program.local[0];
	CONSTANT c1 = program.local[1];
EndConstants;

StartOutputPass;
	SampleMap r0, t0.str;			# main texture
	SampleMap r1, t2.str;			# normalized light dir
	PassTexCoord r4, t1.str;		# normal
	SampleMap r2, t3.stq_dq;		# a = attenuation 1
	SampleMap r3, t4.stq_dq;		# a = attenuation 2
	
	DOT3 r5.sat, r4, r1.2x.bias;	# R5 = diffuse (N.L)
	
	MUL r0, r0, r5;
	MUL r0.rgb.2x, r0, c0;
	MUL r0.rgb, r0, r2.a;			# attenuate
	MUL r0.rgb, r0, r3.a;
	MOV r0.a, c1;
EndPass; 
"
				}
			}
			SetTexture[_MainTex] {combine texture}
			SetTexture[_CubeNormalize] {combine texture}
			SetTexture[_LightTexture0] {combine texture}
			SetTexture[_LightTextureB0] {combine texture}
		}
	}
	
	// ------------------------------------------------------------------
	// Radeon 7000
	
	Category {
		Material {
			Diffuse [_Color]
			Emission [_PPLAmbient]
		}
		Lighting On
		SubShader {
			// Ambient pass
			Pass {
				Name "BASE"
				Tags {"LightMode" = "PixelOrNone"}
				Color [_PPLAmbient]
				Lighting Off
				SetTexture [_MainTex] {Combine texture * primary DOUBLE, primary * texture}
			}
			// Vertex lights
			Pass { 
				Name "BASE"
				Tags {"LightMode" = "Vertex"}
				Lighting On
				Material {
					Diffuse [_Color]
					Emission [_PPLAmbient]
				}
				SetTexture [_MainTex] {Combine texture * primary DOUBLE, primary * texture}
			}
			// Pixel lights with 2 light textures
			Pass {
				Name "PPL"
				Tags {
					"LightMode" = "Pixel"
					"LightTexCount"  = "2"
				}
				ColorMask RGB
				SetTexture [_LightTexture0]  { combine previous * texture alpha, previous }
				SetTexture [_LightTextureB0] { combine previous * texture alpha, previous }
				SetTexture [_MainTex] { combine previous * texture DOUBLE }
			}
			// Pixel lights with 1 light texture
			Pass {
				Name "PPL"
				Tags {
					"LightMode" = "Pixel"
					"LightTexCount"  = "1"
				}
				ColorMask RGB
				SetTexture [_LightTexture0] { combine previous * texture alpha, previous }
				SetTexture [_MainTex] { combine previous * texture DOUBLE }
			}
			// Pixel lights with 0 light textures
			Pass {
				Name "PPL"
				Tags {
					"LightMode" = "Pixel"
					"LightTexCount" = "0"
				}
				ColorMask RGB
				SetTexture[_MainTex] { combine previous * texture DOUBLE }
			}
		}
	}
}

Fallback "VertexLit", 2

}
C'est juste le shader diffus renommé et avec une ligne en plus. Je sais pas si c'est bien fais, si la ligne est au bon endroit mais ca marche chez moi :D
Après les shaders ne se programment pas de la même manière sur toutes les cartes graphiques, donc à tester.
Il 10 types de personnes, ceux qui comprennent le binaire, et ceux qui ne le comprennent pas.

Avatar de l’utilisateur
kealkeal
Messages : 925
Inscription : 16 Juil 2010 17:31
Localisation : Paris

Re: Texture 2 faces

Message par kealkeal » 27 Juil 2010 16:40

J'ai suivi ta procédure mais le SHADER devient tout noir.

Voila le code que j'ai mis dans la SHADER :

Code : Tout sélectionner

Shader "Diffuse" {
Properties {
	_Color ("Main Color", Color) = (1,1,1,1)
	_MainTex ("Base (RGB)", 2D) = "white" {}
	_Cull Off
}

J'ai changé les valeurs _Color ("Main Color", Color) = (1,1,1,1) mais rien ne se passe ...

Merci pour votre aide !
kealkeal

Avatar de l’utilisateur
kealkeal
Messages : 925
Inscription : 16 Juil 2010 17:31
Localisation : Paris

Re: Texture 2 faces

Message par kealkeal » 27 Juil 2010 17:17

Wohh great !

Ça fonctionne !

Merci beaucoup pour votre aide !
kealkeal

Avatar de l’utilisateur
ZJP
Messages : 5745
Inscription : 15 Déc 2009 06:00

Re: Texture 2 faces

Message par ZJP » 27 Juil 2010 17:43

Salut,

Penses a indiquer la procédure qui a permit de résoudre le problème. Ça aide ;)

@tekkpaf
Le CULL est placé dans une "Pass", d'après la documentation (l'exemple) officielle, après le Lighting. Il y a sans doute une raison. Meilleure "adaptation" au changement possible de lumière (dynamique ou autre)?. Faut voir. ;)

JP

Avatar de l’utilisateur
kealkeal
Messages : 925
Inscription : 16 Juil 2010 17:31
Localisation : Paris

Re: Texture 2 faces

Message par kealkeal » 27 Juil 2010 17:55

J'ai simplement mis le code donné par tekkpaf.

Ensuite j'ai pus modifié la couleur de mon SHADER avec la pipette. ;)
kealkeal

Répondre

Revenir vers « les Shaders »