IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

API graphiques Discussion :

Difficulté de compréhension du tutos n°6 sur l'éclairage par Michel de Verdelhan


Sujet :

API graphiques

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Février 2006
    Messages
    156
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2006
    Messages : 156
    Points : 95
    Points
    95
    Par défaut Difficulté de compréhension du tutos n°6 sur l'éclairage par Michel de Verdelhan
    Salut.

    Je voudrais modifier un shader écrit en Cg, qui permet des effets de paralax mapping, pour rajouter des reflets au moyen d'une gloss map.
    Cependant je pige pas de quel manière on doit coder ça. Dans le tutos l'exemple est en ASM et ça aide pas beaucoup.
    Avant ma modification, le shader calculait la spécularité de facon uniforme en utilisant la fonction puissance (enfin je crois).

    float3 specular = saturate(dot(normal, halfAngle),16)* lightSpecular;
    Perso j'ai modifié le shader pour prendre en compte la gloss map, MAIS je ne sais pas du tout si c'est "juste".

    float3 specular = pow(saturate(dot(normal, halfAngle)),16) *lightSpecular*tex2D(glossMap, uv).xyz;/

    Voici le code source entier (modifié par mes soins pour prendre en compte la spécularité à l'aide de la gloss map)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    /* Bump mapping with Parallax offset vertex program 
       In this program, we want to calculate the tangent space light end eye vectors 
       which will get passed to the fragment program to produce the per-pixel bump map 
       with parallax offset effect. 
    */ 
     
    /* Vertex program that moves light and eye vectors into texture tangent space at vertex */ 
     
    void main_vp(float4 position   : POSITION, 
                  float3 normal      : NORMAL, 
                  float2 uv         : TEXCOORD0, 
                  float3 tangent     : TEXCOORD1, 
                  // outputs 
                  out float4 oPosition    : POSITION, 
                  out float2 oUv          : TEXCOORD0, 
                  out float3 oLightDir    : TEXCOORD1, // tangent space 
                 out float3 oEyeDir       : TEXCOORD2, // tangent space 
                 out float3 oHalfAngle    : TEXCOORD3, // 
                  // parameters 
                  uniform float3 lightPosition, // object space 
                  uniform float3 eyePosition,   // object space 
                  uniform float4x4 worldViewProj) 
    {  
       // calculate output position 
       oPosition = mul(worldViewProj, position); 
     
       // pass the main uvs straight through unchanged 
       oUv = uv; 
     
       // calculate tangent space light vector 
       // Get object space light direction 
       float3 lightDir = lightPosition - position.xyz; 
       float3 eyeDir = eyePosition - position.xyz; 
     
       // Calculate the binormal (NB we assume both normal and tangent are 
       // already normalised) 
       // NB looks like nvidia cross params are BACKWARDS to what you'd expect 
       // this equates to NxT, not TxN 
       float3 binormal = cross(tangent, normal); 
     
       // Form a rotation matrix out of the vectors 
       float3x3 rotation = float3x3(tangent, binormal, normal); 
     
       // Transform the light vector according to this matrix 
       lightDir = normalize(mul(rotation, lightDir)); 
       eyeDir = normalize(mul(rotation, eyeDir)); 
     
       oLightDir = lightDir; 
       oEyeDir = eyeDir; 
       oHalfAngle = normalize(eyeDir + lightDir); 
    }
     
    // General functions
     
    // Expand a range-compressed vector
    float3 expand(float3 v)
    {
    	return (v - 0.5) * 2;
    }
     
    void main_fp(float2 uv : TEXCOORD0,
    	float3 lightDir : TEXCOORD1,
    	float3 eyeDir : TEXCOORD2,
    	float3 halfAngle : TEXCOORD3,
    	uniform float3 lightDiffuse,
    	uniform float3 lightSpecular,
    	uniform float4 scaleBias,	
    	uniform sampler2D normalHeightMap,
    	uniform sampler2D diffuseMap,
    	uniform sampler2D glossMap,//LA GLOSS MAP
    	out float4 oColor : COLOR)
    {
    	// get the height using the tex coords
    	float height = tex2D(normalHeightMap, uv).a;
     
    	// scale and bias factors	
    	float scale = scaleBias.x;
    	float bias = scaleBias.y;
     
    	// calculate displacement	
    	float displacement = (height * scale) + bias;
     
    	float3 uv2 = float3(uv, 1);
     
    	// calculate the new tex coord to use for normal and diffuse
    	float2 newTexCoord = ((eyeDir * displacement) + uv2).xy;
     
    	// get the new normal and diffuse values
    	float3 normal = expand(tex2D(normalHeightMap, newTexCoord).xyz);
    	float3 diffuse = tex2D(diffuseMap, newTexCoord).xyz;
     
    	float3 specular = pow(saturate(dot(normal, halfAngle)),16) *lightSpecular*tex2D(glossMap, uv).xyz;//voila c'est comme ça que je  calcule la spécularité 
     
    	//float3 specular = saturate(dot(normal, halfAngle))* lightSpecular;
     
    	float3 col = (diffuse * saturate(dot(normal, lightDir)) * lightDiffuse + specular);
     
    	oColor = float4(col, 1);
    }
    ps : le lien: http://mdeverdelhan.developpez.com/tutoriel/dynamiclight/tutoriel6/

  2. #2
    Rédacteur
    Avatar de bafman
    Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    2 574
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Industrie

    Informations forums :
    Inscription : Novembre 2003
    Messages : 2 574
    Points : 5 323
    Points
    5 323
    Par défaut
    le calcul me semble correct. quel est le problème que tu rencontre précisement ?
    * Il est infiniment plus simple de faire rapidement un code qui marche que de faire un code rapide qui marche
    * pour faciliter les recherches, n'oubliez pas de voter pour les réponses pertinentes
    Mes articles

  3. #3
    Membre régulier
    Profil pro
    Inscrit en
    Février 2006
    Messages
    156
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2006
    Messages : 156
    Points : 95
    Points
    95
    Par défaut
    j'en ai pas spécialement mais je me demandais si je ne m'étais pas trompé, car je vois pas trop la différence.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 2
    Dernier message: 28/03/2015, 23h42
  2. Compréhension d'un algorithme sur le problème du sac à dos
    Par Treuze dans le forum Algorithmes et structures de données
    Réponses: 3
    Dernier message: 18/12/2006, 15h26
  3. Réponses: 3
    Dernier message: 31/10/2006, 10h34

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo