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

DirectX Discussion :

Shader d'eau en HLSL pour une application 3D codée en Vrml


Sujet :

DirectX

  1. #21
    Futur Membre du Club
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    20
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 20
    Points : 5
    Points
    5
    Par défaut
    J apporte une rectification a mon dernier message. Smashy, tu as bien raison de me le faire remarquer, il ne s'agit pas de clip map mais plutot de clip plane. Autant pour moi, milles excuses. J'étais tellement focalisé sur les cube maps que j'ai associé leurs noms aux clip planes. Voilà, désolé pour ceux qui ont cherché.

  2. #22
    Futur Membre du Club
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    20
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 20
    Points : 5
    Points
    5
    Par défaut
    La question reste toujours posée donc si vous pouvez m'aider n'hésitez pas

    Peut on créer des clip planes directement dans des shaders en hlsl ??
    Je vous pose la question car j ai fais des recherches et j ai vu que cette methode est souvent utilisée mais comme je l ai dis précédemment, je dois intégrer mon shader dans du vrml et je ne dispose pas de tous les éléments nécessaire a mon shader et je ne crois pas qu on puisse faire du clipping avec du vrml (reprenez moi si je me trompe).

  3. #23
    Membre habitué
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    100
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 100
    Points : 150
    Points
    150
    Par défaut
    M'est avis que le clipping plane peut se faire en VRML de base, pas besoin de shader pour ca.

    A la rigueur, dans ton shader (vertex), tu compares la position de ta vue a la position de ton vertex, et si il est trop loin, tu le supprimes. Ca ressemblera plus a un clipping sphere, mais bon. Et encore, je ne sais meme pas si c faisable, car il faut renvoyer le vertex en sortie, on ne peut pas le supprimer dans le shader il me semble. Il faudrait que ca soit effectué avant le rendu dans ce cas.

  4. #24
    Futur Membre du Club
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    20
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 20
    Points : 5
    Points
    5
    Par défaut
    Salut à tous,
    C'est encore moi. Désolé mais j'ai vraiment besoin d'aide, car là je pige pas du tout. Voilà, j'ai écris mon vertexshader et mon pixelshader sous formes de fichier fx (MonShaderVS.fx et MonShaderPS.fx). J'ai compilé ces 2 shaders avec la commande "fxc.exe" du sdk de directX 9 (vs_2_0 et ps_2_0 car ma carte graphique supporte cette version de shader: ATI Radeon xpress 200M). Jusque là, tout va bien, ça compile et j'ai mes fichiers vsh et psh. Le problème c'est qu'il ne se passe rien dans ma scène, comme si mon shader n'était pas pris en compte ou ne faisait rien. Pourtant je lui passe les bonnes textures dans le code vrml. Pour ceux qui connaissent le vrml, j'ai un noeud
    vertexShader DEF VertexShader1 VertexShader
    {
    exposedField SFNode ccc USE ccc
    exposedField SFNode g_BumpTexture USE g_BumpTexture
    exposedField SFNode normalTexture USE normalTexture
    exposedField SFNode fresnelTexture USE fresnelTexture
    exposedField SFFloat fTime 1.0
    exposedField SFNode texture0 USE texture0

    url ["hlsl: MonShaderVS.fx"]
    }
    idem pour le fragment shader (pixelshader).
    Pour ce qui est du code hlsl de mes shaders, c'est le suivant:
    Vertex shader
    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
     
    float4x4	mViewProj : VIEWPROJECTION;
    float4x4	mView : VIEW;
    float4		view_position : VIEWPOSITION;
     
    struct VS_INPUT
    {
    	float4 inPos : POSITION;
    	float3 texcoord : TEXCOORD;
    	float3 normal : NORMAL;
    	float3 inCol : COLOR;
    };
     
    struct VS_OUTPUT
    {
    	float4 outPos : POSITION;
    	float3 tc : TEXCOORD0;
    	float3 norm : TEXCOORD1;
    	float3 dt : TEXCOORD2;
    //	float3 bm : TEXCOORD3;
    	float3 color : COLOR;
    };
     
    VS_OUTPUT vs_main(VS_INPUT IN)
    {
    	VS_OUTPUT Out = (VS_OUTPUT)0;
    	Out.color = IN.inCol;
     
    	Out.outPos = mul(mViewProj,float4(IN.inPos.xyz,1));
     
    	//Out.tc = tex2D(mer,IN.texcoord);
    	Out.tc = IN.texcoord;
     
    	float3 N = normalize(IN.normal);
    	float3 V = normalize(IN.inPos.xyz - view_position.xyz/view_position.w);
    	Out.norm = reflect(V,N);
     
    //	Out.bm = refract(V,N);
     
    	Out.dt = dot(Out.norm,N);
     
    	return Out;
    }
     
    technique t1
    {
    	pass P0
    	{
    		vertexshader = compile vs_2_0 vs_main();
    	}
    }
    et le pixel shader
    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
    100
    101
    102
    103
    104
    105
     
    float4x4	mViewProj : VIEWPROJECTION;
    float4x4	mView : VIEW;
    float4		view_position : VIEWPOSITION;
     
    texture texture0;
    texture g_BumpTexture;
    texture normalTexture;
    texture fresnelTexture;
     
    texture ccc;
     
    uniform samplerCUBE envCubeMap = sampler_state
    {
    	Texture = <ccc>;
    	MIPFILTER = LINEAR;
    	MAGFILTER = LINEAR;
    	MINFILTER = LINEAR;
    };
     
    sampler envMapTexture = sampler_state
    {
    	texture = <texture0>;
    	AddressU  = WRAP;		
    	AddressV  = WRAP;
    	MIPFILTER = LINEAR; //POINT;//
    	MINFILTER = LINEAR;
    	MAGFILTER = LINEAR;
    };
     
     
    sampler bmap = sampler_state
    {
    	texture = <g_BumpTexture>;
    	AddressU  = WRAP;		
    	AddressV  = WRAP;
    	MIPFILTER = LINEAR; //POINT;//
    	MINFILTER = LINEAR;
    	MAGFILTER = LINEAR;
    };
     
    sampler nmap = sampler_state
    {
    	texture = <normalTexture>;
    	AddressU  = WRAP;		
    	AddressV  = WRAP;
    	MIPFILTER = LINEAR; //POINT;//
    	MINFILTER = LINEAR;
    	MAGFILTER = LINEAR;
    };
     
    sampler fmap = sampler_state
    {  
        Texture = <fresnelTexture>; 
        MipFilter = NONE; 
        MinFilter = LINEAR; 
        MagFilter = LINEAR; 
    	AddressU  = CLAMP;		
    	AddressV  = CLAMP;		
    };
     
    struct VS_INPUT
    {
    	float4 inPos : POSITION;
    	float3 texcoord : TEXCOORD;
    	float3 normal : NORMAL;
    	float3 inCol : COLOR;
    };
     
    struct VS_OUTPUT
    {
    	float4 outPos : POSITION;
    	float3 tc : TEXCOORD0;
    	float3 norm : TEXCOORD1;
    	float3 dot : TEXCOORD2;
    //	float3 bm : TEXCOORD3;
    	float3 color : COLOR;
    };
     
    float4 ps_main(VS_OUTPUT o) : COLOR
    {
    	float4 col;
    	col.a = 1;
     
    	float fresn = tex1D(fmap,o.dot);
    	float3 cub = texCUBE(envCubeMap,o.norm);
    	float3 Norm = tex2D(nmap,o.norm);
    	float3 bum = tex2D(bmap,o.norm);
    //	float3 bm = tex2D(bmap,o.bm);
     
    	float4 local = tex2D(envMapTexture,o.tc);
    	float3 refl = lerp(cub,Norm,local.a);
     
    	col.rgb = lerp(refl,bum,fresn);
     
    	return col;
    }
     
    technique t1
    {
    	pass P0
    	{
    		pixelshader = compile ps_2_0 ps_main();
    	}
    }
    donc voilà. Si vous pouvez m'expliquer pourquoi ça n'agit pas sur ma scène, je vous en serait très reconnaissant.
    J'avais essayé aussi ce simple shader pour animer l'eau et ça ne donnait rien aussi:
    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
     
     
    uniform float4x4 Mvp : WORLDVIEW;
    uniform float4x4 Projection : PROJECTION;
    uniform float3 cameraPos: VIEWPOSITION;
    float fTime;
     
    struct IN_PUT
    {
    	float4 inPos : POSITION;
    	float3 inNormal: NORMAL;
    	float2 Text : TEXCOORD;
    };
     
    struct OUT_PUT
    {
    	float4 outPos : POSITION;
    	float3 outTexCube : TEXCOORD0;
    };
     
    OUT_PUT VP_cube_reflect( struct IN_PUT IN)
    {
    	OUT_PUT Out = (OUT_PUT)0;
     
    	IN.inPos.y = cos(IN.inPos.x) * cos(IN.inPos.z) * sin(fTime) * 0.2f;
     
    	IN.inPos.x = IN.inPos.x + 0.02f * sin(fTime);
    	IN.inPos.z = IN.inPos.z + 0.02f * sin(fTime);
     
    	// transform vertex position by combined view projection matrix
        float3 P = mul(IN.inPos,(float4x3)Mvp);
    	float3 N = normalize(mul(IN.inNormal,(float3x3)Mvp));
    	Out.outPos = mul(float4(P,1),Projection);
     
        // create ray from camera position to the vertex, in world space
        float3 V = IN.inPos - cameraPos;
     
        // compute the reflection vector, and assign it to texcoord 0
        //Out.outTexCube.x = IN.Text.x;
        //Out.outTexCube.y = IN.Text.y + 100.01f * sin(fTime * 0.5f);
        Out.outTexCube = reflect(V, IN.inNormal);
     
        return Out;
    }
     
     
     
    //--------------------------------------------------------------------------------------
    // Renders scene to render target
    //--------------------------------------------------------------------------------------
    technique RenderRefractionMask14
    {
    	 pass P0
    	 {
    		VertexShader = compile vs_1_1 VP_cube_reflect();
    	 }
    }
    et le pixel shader
    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
     
    texture ccc;
     
    uniform samplerCUBE EnvCubeMap = sampler_state
    {
    	Texture = (ccc);
    	MIPFILTER = LINEAR;
    	MAGFILTER = LINEAR;
    	MINFILTER = LINEAR;
    };
     
    void FP_cube_reflect( float3 inTexCube : TEXCOORD0,
                          out float4 outCol : COLOR)
    {
        // sample cubemap with the reflection vector
        outCol = texCUBE(EnvCubeMap, inTexCube);
    }
     
    //--------------------------------------------------------------------------------------
    // Renders scene to render target
    //--------------------------------------------------------------------------------------
    technique RenderRefractionMask14
    {
    	pass P0
    	{
    		PixelShader  = compile ps_1_4 FP_cube_reflect();
    	}
    }
    ça aussi ça ne fait rien.
    HELP PLEASE!!!

  5. #25
    Futur Membre du Club
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    20
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 20
    Points : 5
    Points
    5
    Par défaut Erreur inconnue ???
    Apparamment, y aurait un problème avec ma carte graphique (ATI radéon xpress 200M) car j'ai testé la démo de parallelgraphics qui se trouve en fin de page de ce site:
    http://www.parallelgraphics.com/deve...sions/shaders/
    et j'ai constaté que le shader n'est pas pris en compte or sur un autre pc muni d'une GeForce FX 5200, on voit bien les effets du shader. Mes shaders (cf. message précédent) ne fonctionnent pas sur ma machine. Par contre, je les ai essayé sur cette même machine (celle munie de la GeForce), après les avoir compilé avec succès à l'aide de la commande fxc.exe du SDK de directX9 et y a cette erreur qui a apparue:
    renderer error (3): HLSL::CompileShader() for target vs_2_0 :
    (1): error X3000: syntax error: unexpected token '/'


    HLSL::CompileShader() for target vs_1_1 :
    (1): error X3000: syntax error: unexpected token '/'
    Je ne sais pas pourquoi il me met cette erreur alors qu'il a compilé sans problème et j'ai vérifié le code de nvidia suivant:
    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
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    /*********************************************************************NVMH3****
    Path:  NVSDK\Common\media\cgfx
    File:  ocean.fx
     
    Copyright NVIDIA Corporation 2003
    TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED
    *AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS
    OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
    AND FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS
    BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES
    WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,
    BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS)
    ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS
    BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
     
     
    Comments:
            Simple ocean shader with animated bump map and geometric waves
            Based partly on "Effective Water Simulation From Physical Models", GPU Gems
     
    hg minor changes
     
    ******************************************************************************/
     
    float4x4 worldMatrix : World < string UIWidget = "none";>;	           	// World or Model matrix
    float4x4 wvpMatrix : WorldViewProjection < string UIWidget = "none";>;	// Model*View*Projection
    float4x4 worldViewMatrix : WorldView < string UIWidget = "none";>;
    float4x4 viewInverseMatrix : ViewInverse < string UIWidget = "none";>;
     
    float time : Time < string UIWidget = "none"; >;
     
    texture normalMap : Normal
    <
    	string ResourceName = "normalMap";
    	string TextureType = "2D";
    >;
     
    texture cubeMap : Environment
    <
    	string ResourceName = "cubeMap";
    	string TextureType = "cube";
    >;
     
    sampler2D normalMapSampler = sampler_state
    {
    	Texture = <normalMap>;
    #if 0
    	// this is a trick from Halo - use point sampling for sparkles
    	MagFilter = Linear;	
    	MinFilter = Point;
    	MipFilter = None;
    #else
    	MagFilter = Linear;	
    	MinFilter = Linear;
    	MipFilter = Linear;
    #endif
    };
     
    samplerCUBE envMapSampler = sampler_state
    {
    	Texture = <cubeMap>;
    	MinFilter = Linear;
    	MagFilter = Linear;
    	MipFilter = Linear;
        AddressU = Clamp;
        AddressV = Clamp;
    };
     
    float bumpHeight
    <
    	string UIWidget = "slider";
    	float UIMin = 0.0; float UIMax = 2.0; float UIStep = 1;
    	string UIName = "Bump Height";
    > = 0.1;
     
    float2 textureScale
    <
        string UIName = "Texture scale";
    > = { 8.0, 4.0 };
     
    float2 bumpSpeed
    <
        string UIName = "Bumpmap translation speed";
    > = { -0.05, 0.0 };
     
    float fresnelBias
    <
        string UIName = "Fresnel bias";
    	string UIWidget = "slider";
    	float UIMin = 0.0; float UIMax = 1.0; float UIStep = 0.01;
    > = 0.1;
     
    float fresnelPower
    <
        string UIName = "Fresnel exponent";
    	string UIWidget = "slider";
    	float UIMin = 1.0; float UIMax = 10.0; float UIStep = 0.01;
    > = 4.0;
     
    float hdrMultiplier
    <
        string UIName = "HDR multiplier";
    	string UIWidget = "slider";
    	float UIMin = 0.0; float UIMax = 100.0; float UIStep = 0.01;
    > = 3.0;
     
    float4 deepColor : Diffuse
    <
        string UIName = "Deep water color";
    > = {0.0f, 0.0f, 0.1f, 1.0f};
     
    float4 shallowColor : Diffuse
    <
        string UIName = "Shallow water color";
    > = {0.9f, 0.5f, 0.5f, 1.0f};
     
    float4 reflectionColor : Specular
    <
        string UIName = "Reflection color";
    > = {1.0f, 0.2f, 1.0f, 1.0f};
     
    // these are redundant, but makes the ui easier:
    float reflectionAmount
    <
        string UIName = "Reflection amount";
    	string UIWidget = "slider";    
    	float UIMin = 0.0; float UIMax = 2.0; float UIStep = 0.01;    
    > = 1.0f;
     
    float waterAmount
    <
        string UIName = "Water color amount";
    	string UIWidget = "slider";    
    	float UIMin = 0.5; float UIMax = 2.0; float UIStep = 0.01;    
    > = 1.0f;
     
    float waveAmp
    <
        string UIName = "Wave amplitude";
    	string UIWidget = "slider";
    	float UIMin = 0.0; float UIMax = 10.0; float UIStep = 0.1;
    > = 1.0;
     
    float waveFreq
    <
        string UIName = "Wave frequency";
    	string UIWidget = "slider";
    	float UIMin = 0.0; float UIMax = 1.0; float UIStep = 0.001;
    > = 0.1;
     
     
     
    struct a2v {
    	float4 Position : POSITION;   // in object space
    	float3 Normal   : NORMAL;
    	float2 TexCoord : TEXCOORD0;
    	float3 Tangent  : TEXCOORD1;
    	float3 Binormal : TEXCOORD2;
    };
     
    struct v2f {
    	float4 Position  : POSITION;  // in clip space
    	float2 TexCoord  : TEXCOORD0;
    	float3 TexCoord1 : TEXCOORD1; // first row of the 3x3 transform from tangent to cube space
    	float3 TexCoord2 : TEXCOORD2; // second row of the 3x3 transform from tangent to cube space
    	float3 TexCoord3 : TEXCOORD3; // third row of the 3x3 transform from tangent to cube space
     
    	float2 bumpCoord0 : TEXCOORD4;
    	float2 bumpCoord1 : TEXCOORD5;
    	float2 bumpCoord2 : TEXCOORD6;
     
    	float3 eyeVector  : TEXCOORD7;
    };
     
    // wave functions
     
    struct Wave {
      float freq;  // 2*PI / wavelength
      float amp;   // amplitude
      float phase; // speed * 2*PI / wavelength
      float2 dir;
    };
     
    #define NWAVES 2
    Wave wave[NWAVES] = {
    	{ 1.0, 1.0, 0.5, float2(-1, 0) },
    	{ 2.0, 0.5, 1.3, float2(-0.7, 0.7) }	
    };
     
    float evaluateWave(Wave w, float2 pos, float t)
    {
      return w.amp * sin( dot(w.dir, pos)*w.freq + t*w.phase);
    }
     
    // derivative of wave function
    float evaluateWaveDeriv(Wave w, float2 pos, float t)
    {
      return w.freq*w.amp * cos( dot(w.dir, pos)*w.freq + t*w.phase);
    }
     
    // sharp wave functions
    float evaluateWaveSharp(Wave w, float2 pos, float t, float k)
    {
      return w.amp * pow(sin( dot(w.dir, pos)*w.freq + t*w.phase)* 0.5 + 0.5 , k);
    }
     
    float evaluateWaveDerivSharp(Wave w, float2 pos, float t, float k)
    {
      return k*w.freq*w.amp * pow(sin( dot(w.dir, pos)*w.freq + t*w.phase)* 0.5 + 0.5 , k - 1) * cos( dot(w.dir, pos)*w.freq + t*w.phase);
    }
     
    v2f BumpReflectWaveVS(a2v IN,
    					  uniform float4x4 WorldViewProj,
    					  uniform float4x4 World,
    					  uniform float4x4 ViewIT,
    					  uniform float BumpScale,
    					  uniform float2 textureScale,
    					  uniform float2 bumpSpeed,
    					  uniform float time,
    					  uniform float waveFreq,
    					  uniform float waveAmp
                    	  )
    {
    	v2f OUT;
     
        wave[0].freq = waveFreq;
        wave[0].amp = waveAmp;
     
        wave[1].freq = waveFreq*2.0;
        wave[1].amp = waveAmp*0.5;
     
    	time *=100.0f;
     
        float4 P = IN.Position;
     
    	// sum waves	
    	P.y = 0.0;
    	float ddx = 0.0, ddy = 0.0;
    	for(int i=0; i<NWAVES; i++) {
        	P.y += evaluateWave(wave[i], P.xz, time);
        	float deriv = evaluateWaveDeriv(wave[i], P.xz, time);
        	ddx += deriv * wave[i].dir.x;
        	ddy += deriv * wave[i].dir.y;
        }
     
    	// compute tangent basis
        float3 B = float3(1, ddx, 0);
        float3 T = float3(0, ddy, 1);
        float3 N = float3(-ddx, 1, -ddy);
     
    	OUT.Position = mul(P, WorldViewProj);
     
    	// pass texture coordinates for fetching the normal map
    	OUT.TexCoord.xy = IN.TexCoord*textureScale;
     
    	time = fmod(time, 100.0);
    	OUT.bumpCoord0.xy = IN.TexCoord*textureScale + time*bumpSpeed;
    	OUT.bumpCoord1.xy = IN.TexCoord*textureScale*2.0 + time*bumpSpeed*4.0;
    	OUT.bumpCoord2.xy = IN.TexCoord*textureScale*4.0 + time*bumpSpeed*8.0;
     
    	// compute the 3x3 tranform from tangent space to object space
    	float3x3 objToTangentSpace;
    	// first rows are the tangent and binormal scaled by the bump scale
    	objToTangentSpace[0] = BumpScale * normalize(T);
    	objToTangentSpace[1] = BumpScale * normalize(B);
    	objToTangentSpace[2] = normalize(N);
     
    	OUT.TexCoord1.xyz = mul(objToTangentSpace, World[0].xyz);
    	OUT.TexCoord2.xyz = mul(objToTangentSpace, World[1].xyz);
    	OUT.TexCoord3.xyz = mul(objToTangentSpace, World[2].xyz);
     
    	// compute the eye vector (going from shaded point to eye) in cube space
    	float4 worldPos = mul(P, World);
    	OUT.eyeVector = ViewIT[3] - worldPos; // view inv. transpose contains eye position in world space in last row
    	return OUT;
    }
     
     
    // Pixel Shaders
     
     
     
    float4 BumpReflectPS20(v2f IN,
    					   uniform sampler2D NormalMap,
    					   uniform samplerCUBE EnvironmentMap) : COLOR
    {
    	// fetch the bump normal from the normal map
    	float4 N = tex2D(NormalMap, IN.TexCoord.xy)*2.0 - 1.0;
     
    	float3x3 m; // tangent to world matrix
    	m[0] = IN.TexCoord1;
    	m[1] = IN.TexCoord2;
    	m[2] = IN.TexCoord3;
    	float3 Nw = mul(m, N.xyz);
     
    	float3 E = IN.eyeVector;
        float3 R = reflect(-E, Nw);
     
    	return texCUBE(EnvironmentMap, R);
    }
     
    float4 OceanPS20(v2f IN,
    				 uniform sampler2D NormalMap,
    				 uniform samplerCUBE EnvironmentMap,
    				 uniform half4 deepColor,
    				 uniform half4 shallowColor,
    				 uniform half4 reflectionColor,
    				 uniform half4 reflectionAmount,
    				 uniform half4 waterAmount,
    				 uniform half fresnelPower,
    				 uniform half fresnelBias,
    				 uniform half hdrMultiplier
    				 ) : COLOR
    {
    	// sum normal maps
        half4 t0 = tex2D(NormalMap, IN.bumpCoord0.xy)*2.0-1.0;
        half4 t1 = tex2D(NormalMap, IN.bumpCoord1.xy)*2.0-1.0;
        half4 t2 = tex2D(NormalMap, IN.bumpCoord2.xy)*2.0-1.0;
        half3 N = t0.xyz + t1.xyz + t2.xyz;
     
     
        half3x3 m; // tangent to world matrix
        m[0] = IN.TexCoord1;
        m[1] = IN.TexCoord2;
        m[2] = IN.TexCoord3;
        half3 Nw = mul(m, N.xyz);
        Nw = normalize(Nw);
     
    	// reflection
        float3 E = normalize(IN.eyeVector);
        half3 R = reflect(-E, Nw);
     
        half4 reflection = texCUBE(EnvironmentMap, R);
        // hdr effect (multiplier in alpha channel)
        reflection.rgb *= (1.0 + reflection.a*hdrMultiplier);
     
    	// fresnel - could use 1D tex lookup for this
        half facing = 1.0 - max(dot(E, Nw), 0);
        half fresnel = fresnelBias + (1.0-fresnelBias)*pow(facing, fresnelPower);
     
        half4 waterColor = lerp(deepColor, shallowColor, facing);
     
    	return waterColor*waterAmount + reflection*reflectionColor*reflectionAmount*fresnel;
     
    }
     
     
     
     
    technique PS20
    {
    	pass p0
    	{
    		VertexShader = compile vs_2_0 BumpReflectWaveVS(
    					wvpMatrix, worldMatrix, viewInverseMatrix,
                                            bumpHeight, textureScale, bumpSpeed, time,
                                            waveFreq, waveAmp);
     
    		PixelShader = compile ps_2_0 OceanPS20(normalMapSampler, envMapSampler,
                                                  deepColor, shallowColor, reflectionColor, reflectionAmount, waterAmount,
                                                   fresnelPower, fresnelBias, hdrMultiplier);
    	}
    }
     
    // hg try on PS13 fallback 
     
    float4 BumpReflectPS1(v2f IN,
    					   uniform sampler2D NormalMap,
    					   uniform samplerCUBE EnvironmentMap,
    					   uniform half4 deepColor,
    					   uniform half4 shallowColor) : COLOR
    {
    	// fetch the bump normal from the normal map
    	half3 N = tex2D(NormalMap, IN.TexCoord.xy)*2.0 - 1.0;
     
    	return deepColor+0.5*texCUBE(EnvironmentMap, N);
    }
     
    technique PS13
    {
    	// hg fallback 
    	pass p0
    	{
    		VertexShader = compile vs_1_1 BumpReflectWaveVS(wvpMatrix, worldMatrix, viewInverseMatrix,
                                                            bumpHeight, textureScale, bumpSpeed, time,
                                                            waveFreq, waveAmp);
     
    		PixelShader = compile ps_1_3 BumpReflectPS1(normalMapSampler, envMapSampler,deepColor, shallowColor);
    	}
    }
    et je n'ai pas trouvé de "/" qui traine. Donc, si vous avec déjà rencontré ce genre d'erreur, faites moi savoir à quoi ça correspond et comment la corriger. Merci.

  6. #26
    Membre averti
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    366
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 366
    Points : 440
    Points
    440
    Par défaut
    il peut etre interressant de connaitre les profiles de shader acceptes par ton GPU:

    -tes PS shaders utilisent des "dependant texture lookup" qui ne sont acceptes a partir de pixel shader 1.4

    -tu utilises des fonctions trigonometriques ... a verifier, si elles sont supportes

    Question subsidiaire : tes drivers sont ils a jours ... ?

  7. #27
    Membre actif
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    267
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2005
    Messages : 267
    Points : 275
    Points
    275
    Par défaut
    En ce qui concerne l'erreur:
    (1): error X3000: syntax error: unexpected token '/'
    (1) correspond à la ligne de ton shader.

    La ligne 1 correspond à un commentaire. Il y a bien un "/"!
    Je ne sais pas pourquoi il te sort cette erreur, mais tu n'as qu'à virer tous les commentaires (provisoirement du moins...).

  8. #28
    Futur Membre du Club
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    20
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 20
    Points : 5
    Points
    5
    Par défaut
    Je pense avoir trouver l'erreur, j'ai regarder dans les préférences du plugin de Cortona (que j'utilise pour visualser ma scène) dans la rubrique "Renderer" j'ai décoché l'option "Wireframe rendring mode" et depuis je n'ai plus l'erreur. Mais je trouve ça quand même bizarre qu'il m'ait sorti cette erreur vu que les '//' et les '/* */' sont des commentaires en hlsl.
    Albenejean:
    Je ne sais pas pourquoi il te sort cette erreur, mais tu n'as qu'à virer tous les commentaires (provisoirement du moins...).
    Je l'avais fait mais l'erreur avait persisté.
    smashy:
    il peut etre interressant de connaitre les profiles de shader acceptes par ton GPU
    Le pc sur lequel je teste mes shaders possède un GeForce FX 5200 qui supporte les shaders de profils 2.a pour les vertex/pixelShader.
    smashy:
    Question subsidiaire : tes drivers sont ils a jours ... ?
    Ben à ma connaissance, ils sont tous à jour mais pourrais-tu me préciser lesquels précisément ?

  9. #29
    Membre actif
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    267
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2005
    Messages : 267
    Points : 275
    Points
    275
    Par défaut
    ATI radéon xpress 200M:
    support des vs 2.0 et ps 2.0

    Les drivers dont parle smashy sont bien entendu ceux de ta carte graphique (voir le site de nvidia et celui d'ATI).

  10. #30
    Futur Membre du Club
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    20
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 20
    Points : 5
    Points
    5
    Par défaut
    Y a quand même un autre truc qui me chagrine. Dans les annotations en hlsl:
    - Est-ce que "UIWidget" représente un point d'entrée pour le shader ? c'est à dire ce qui va me permettre de faire le lien avec mon paramètre provenant du code vrml ?
    - Est-il indispensable pour le passage des parmètres du programme principal (en vrml) vers le shader ?
    Mon problème étant le passage de mes données (variables, texture, time, etc...) à partir du vrml pour le shader. Un exemple concret, par exemple:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    float4x4 viewInverseMatrix : ViewInverse < string UIWidget = "none";>;
     
    float time : Time < string UIWidget = "none"; >;
    ou encore
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    float fresnelBias
    <
        string UIName = "Fresnel bias";
    	string UIWidget = "slider";
    	float UIMin = 0.0; float UIMax = 1.0; float UIStep = 0.01;
    > = 0.1;
    Dans tous ces cas, faut-il impérativement écrire cette annotation (pour le time, par exemple) et faut-il remplacer le "none" par le nom de mon paramètre provenant du code vrml (float time : Time < string UIWidget = "none"; > ?

  11. #31
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    20
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 20
    Points : 14
    Points
    14
    Par défaut
    Non, tout ce qui est UIWidget etc sont en fait des paramètres que les logiciels utilisant les .fx (FX Composer, 3DS max etc...) comprennent. Celà permet de dire à FX composer que par exemple ta matrice "world" est bel est bien la matrice de monde, qu'elle doit être de telle façon dans la représentation 3D, que ton paramètre y doit être paramétrable par un slider qui va de 0f à 1f par exemple, etc... En gros c'est juste pour interfacer le .fx avec les logiciels l'utilisant. C'est totalement optionnel.

    Ton code VRML doit avoir une manière de spécifier la valeur de toutes tes variables et constantes de ton shader normalement.

  12. #32
    Membre à l'essai
    Inscrit en
    Juin 2005
    Messages
    10
    Détails du profil
    Informations forums :
    Inscription : Juin 2005
    Messages : 10
    Points : 12
    Points
    12
    Par défaut
    Je sais que le topic remonte à l'an dernier, mais si çà peut aider:
    http://17de.com/vrml/test/waterRTT.html

    C'est justement un shader d'eau pour VRML avec le code code disponible.

Discussions similaires

  1. Comment faire des etats pour une application web ?
    Par ovh dans le forum Autres outils décisionnels
    Réponses: 6
    Dernier message: 06/07/2021, 03h25
  2. [Executable]creation d'un batch pour une application
    Par tarik75 dans le forum Général Java
    Réponses: 4
    Dernier message: 03/08/2005, 15h33
  3. [Tomcat] définir un port pour une application
    Par Mrlud dans le forum Tomcat et TomEE
    Réponses: 10
    Dernier message: 14/06/2005, 17h33
  4. [Compilation] A quel moment pour une application ?
    Par Rick1602 dans le forum Eclipse Java
    Réponses: 2
    Dernier message: 04/03/2004, 20h36

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