ATS Snow Shader

Questions à propos du scripting Shader.
Avatar de l’utilisateur
ZJP
Messages : 5748
Inscription : 15 Déc 2009 06:00

ATS Snow Shader

Message par ZJP » 17 Août 2012 00:49

Salut,

Un shader gratuit qui permet d'ajouter un effet "neige" sur les terrains, arbres et GameObjet. Gratuit... Donc..

JP

Avatar de l’utilisateur
Franck
Bricoleur
Bricoleur
Messages : 2884
Inscription : 08 Jan 2011 18:43
Localisation : Tours

Re: ATS Snow Shader

Message par Franck » 17 Août 2012 08:34

Trés bien fait.
Dés fois j'bug, dés fois j'bug pas.

Avatar de l’utilisateur
axel
Messages : 1924
Inscription : 26 Avr 2012 09:10
Localisation : Lille - Dunkerque
Contact :

Re: ATS Snow Shader

Message par axel » 17 Août 2012 16:21

excellent, merci pour le lien :D

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

Re: ATS Snow Shader

Message par ZJP » 17 Août 2012 19:56

Tu vas pouvoir ajouter de la neige à ton projet d'urbanisme. ;)

JP

Avatar de l’utilisateur
axel
Messages : 1924
Inscription : 26 Avr 2012 09:10
Localisation : Lille - Dunkerque
Contact :

Re: ATS Snow Shader

Message par axel » 20 Août 2012 07:49

j'y travaille justement pour intégrer de la neige.
Dans notre interface il est possible de choisir l'heure de la journée et le mois de l'année.
J'ai fais un test en intégrant l'ATS Snow Shader, et en faisant varier le "snow amont" en fonction du slider de la date. ça a l'air de fonctionner.
Reste à affiner le système, et à ne prendre que ce dont j'ai besoin, car pour tester j'ai intégrer tout le package "ATS Snow Shader" dans mon projet. Il faut aussi que je vois comment ça marche pour les arbres.

Mais c'est une excellente trouvaille tu as fait là, merci ;)

Image

Avatar de l’utilisateur
axel
Messages : 1924
Inscription : 26 Avr 2012 09:10
Localisation : Lille - Dunkerque
Contact :

Re: ATS Snow Shader

Message par axel » 21 Août 2012 15:27

J'aurai une question.
Dans la doc de l'ATS snow shader, il est écrit que les shaders utilisés sont des shaders de base pour être facilement modifiés.
Le shader fournit est un diffuse+bump, j'aurais souhaité avoir un diffuse+bump+specular.

J'ai reccupéré le built-in shader sur le site de Unity pour voir comment est fait le shader diffuse+bump+specular puis j'ai tenté de modifier l'ATS snow shader.

Évidement je n'y suis pas parvenu sinon je n'aurais pas posté ici :).

Voici le shader original:

Code : Tout sélectionner

Shader "snowShader Bumped Diffuse" {
Properties {
	_Color ("Main Color", Color) = (1,1,1,1)
	_MainTex ("Base (RGB)", 2D) = "white" {}
	_BumpMap ("Normalmap", 2D) = "bump" {}
}

SubShader {
	Tags { "RenderType"="Opaque" }
	LOD 300

CGPROGRAM
#pragma surface surf Lambert vertex:snow
#pragma exclude_renderers flash
//#pragma target 3.0

sampler2D _MainTex;
sampler2D _SnowTex;
sampler2D _BumpMap;
fixed4 _Color;

float _snowShininess;
float _SnowAmount;
float _SnowStartHeight;
sampler2D _SnowTexture;

struct Input {
	float2 uv_MainTex;
	float2 uv_BumpMap;
	fixed4 color : COLOR;
	float3 worldPos;
	fixed3 MyWorldNormal;
};

void snow (inout appdata_full v, out Input o) {	
    o.MyWorldNormal = normalize(mul((float3x3)_Object2World, v.normal));
}

void surf (Input IN, inout SurfaceOutput o) {

	fixed4 col = tex2D(_MainTex, IN.uv_MainTex) * _Color;
	fixed4 snow = tex2D(_SnowTex, IN.uv_MainTex);
	o.Alpha = col.a;
	o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
	
	// get snow texture // distribution might be stored in alpha
	half4 snowtex = tex2D( _SnowTexture, IN.uv_MainTex);
	
	// clamp(IN.MyWorldNormal.y + 0.6, 0, 1) = allows snow even on orthogonal surfaces // (1-col.b) = take the blue channel to get some kind of heightmap
	float snowAmount = (_SnowAmount * (clamp(IN.MyWorldNormal.y + 0.6, 0, 1)) * (1-col.b) *.8 + clamp(o.Normal.y, 0, 1) * _SnowAmount * .25);

	// clamp snow to _SnowStartHeight
	snowAmount = snowAmount * clamp((IN.worldPos.y - _SnowStartHeight)*.0125, 0, 1);
	
	// sharpen snow mask
	snowAmount = clamp(pow(snowAmount,6)*256, 0, 1);
	
	o.Alpha = 0.0;	

	// mix 
	o.Albedo = col.rgb * (1-snowAmount) + snowtex.rgb*snowAmount;
	o.Gloss = half(snowAmount*(1-snowtex.rgb));
	o.Specular = _snowShininess;
	
	// smooth normal
	o.Normal = normalize(lerp(o.Normal, float3(0,0,1), snowAmount*.50));
	
}
ENDCG  
}

FallBack "Diffuse"
}

Et voici, la version modifiée:

Code : Tout sélectionner

Shader "snowShader Bumped Diffuse" {
Properties {
	_Color ("Main Color", Color) = (1,1,1,1)
	_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
	_Shininess ("Shininess", Range (0.03, 1)) = 0.078125	
	_MainTex ("Base (RGBA)", 2D) = "white" {}
	_BumpMap ("Normalmap", 2D) = "bump" {}
}

SubShader {
	Tags { "RenderType"="Opaque" }
	LOD 300

CGPROGRAM
#pragma surface surf BlinnPhong vertex:snow
#pragma exclude_renderers flash
//#pragma target 3.0

sampler2D _MainTex;
sampler2D _SnowTex;
sampler2D _BumpMap;
fixed4 _Color;
half _Shininess;

float _snowShininess;
float _SnowAmount;
float _SnowStartHeight;
sampler2D _SnowTexture;

struct Input {
	float2 uv_MainTex;
	float2 uv_BumpMap;
	fixed4 color : COLOR;
	float3 worldPos;
	fixed3 MyWorldNormal;
};

void snow (inout appdata_full v, out Input o) {	
    o.MyWorldNormal = normalize(mul((float3x3)_Object2World, v.normal));
}

void surf (Input IN, inout SurfaceOutput o) {

	fixed4 col = tex2D(_MainTex, IN.uv_MainTex) * _Color;
	fixed4 snow = tex2D(_SnowTex, IN.uv_MainTex);
	o.Gloss = col.a;
	o.Specular = _Shininess;
	o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
	
	// get snow texture // distribution might be stored in alpha
	half4 snowtex = tex2D( _SnowTexture, IN.uv_MainTex);
	
	// clamp(IN.MyWorldNormal.y + 0.6, 0, 1) = allows snow even on orthogonal surfaces // (1-col.b) = take the blue channel to get some kind of heightmap
	float snowAmount = (_SnowAmount * (clamp(IN.MyWorldNormal.y + 0.6, 0, 1)) * (1-col.b) *.8 + clamp(o.Normal.y, 0, 1) * _SnowAmount * .25);

	// clamp snow to _SnowStartHeight
	snowAmount = snowAmount * clamp((IN.worldPos.y - _SnowStartHeight)*.0125, 0, 1);
	
	// sharpen snow mask
	snowAmount = clamp(pow(snowAmount,6)*256, 0, 1);
	
	o.Alpha = 0.0;	

	// mix 
	o.Albedo = col.rgb * (1-snowAmount) + snowtex.rgb*snowAmount;
	
	o.Gloss = half(snowAmount*(1-snowtex.rgb));

	
	// smooth normal
	o.Normal = normalize(lerp(o.Normal, float3(0,0,1), snowAmount*.50));
	
}
ENDCG  
}
FallBack "Bumped Specular"
}
Avec une erreur au niveau de la ligne: #pragma surface surf BlinnPhong vertex:snow

Comme je n'y connais rien au langage des shaders si quelqu'un à une piste je l'en remercie d'avance.

Avatar de l’utilisateur
cayou66
Codeur
Codeur
Messages : 6450
Inscription : 30 Juin 2011 14:45
Localisation : Montréal

Re: ATS Snow Shader

Message par cayou66 » 21 Août 2012 15:48

Dans SubShader tu peux peut être rajouter:

Code : Tout sélectionner

 UsePass "Specular"
Je suis pas fort en shader, mais ça pourrait peut être marcher, pour peu que tu reprennes les mêmes properties que le specular.

Avatar de l’utilisateur
axel
Messages : 1924
Inscription : 26 Avr 2012 09:10
Localisation : Lille - Dunkerque
Contact :

Re: ATS Snow Shader

Message par axel » 21 Août 2012 15:53

Yes!!! ça marche.

Merci :D

Avatar de l’utilisateur
axel
Messages : 1924
Inscription : 26 Avr 2012 09:10
Localisation : Lille - Dunkerque
Contact :

Re: ATS Snow Shader

Message par axel » 21 Août 2012 15:56

ah j'ai répondu trop vite, maintenant le shader ne se couvre plus de neige.

Avatar de l’utilisateur
cayou66
Codeur
Codeur
Messages : 6450
Inscription : 30 Juin 2011 14:45
Localisation : Montréal

Re: ATS Snow Shader

Message par cayou66 » 21 Août 2012 15:58

axel a écrit :ah j'ai répondu trop vite, maintenant le shader ne se couvre plus de neige.
C'est le souci, ça rend parfois les choses incompatibles...
Je peux pas t'en dire plus :(

Répondre

Revenir vers « les Shaders »