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 :

Différence Rendu Direct3D OpenGL


Sujet :

API graphiques

  1. #1
    Expert éminent sénior

    Avatar de dragonjoker59
    Homme Profil pro
    Software Developer
    Inscrit en
    Juin 2005
    Messages
    2 045
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Software Developer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2005
    Messages : 2 045
    Points : 11 368
    Points
    11 368
    Billets dans le blog
    10
    Par défaut Différence Rendu Direct3D OpenGL
    Bonjour !

    Sur mon petit Castor3D, je fignole l'implémentation du rendu via Direct3D 9.
    Je finalise les shaders et pour cela j'ai traduit en HLSL le shader de Relief mapping que j'ai en GLSL, et qui ne fonctionne pas trop mal.
    Cependant je remarque quelque chose qui me chiffonne : sur Direct3D le rendu de la lumière spéculaire est pixellisé contrairement à OpenGl où il est bien lisse.
    Je vous mets 2 copies d'écrans afin que vous voyiez où je veux en venir (il faut regarder les reflets spéculaires en rouge/rose)

    Rendu OpenGL :


    Rendu Direct3D 9 :


    Savez-vous d'où ça peut provenir ? (je ne suis pas très calé en Direct3D, j'ai peut être oublié quelque chose à faire, notamment au niveau de la création des textures)

    Je vous mets les codes des shaders GLSL et HLSL qui ont servi pour ces rendus :

    GLSL
    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
     
    //VERTEX SHADER
    #version 140
     
    in vec3 tangent;
    in vec4 vertex;
    in vec3 normal;
    in vec2 texture;
     
    uniform mat4 ProjectionModelViewMatrix;
    uniform mat4 ModelViewMatrix;
    uniform mat3 NormalMatrix;
     
    uniform vec4 in_LightsPosition[8];
    uniform vec4 in_LightsSpecular[8];
    uniform vec4 in_LightsDiffuse[8];
    uniform vec4 in_LightsAmbient[8];
    uniform vec4 in_AmbientLight;
    uniform vec4 in_MatAmbient;
    uniform vec4 in_MatDiffuse;
    uniform vec4 in_MatSpecular;
    uniform float in_MatShininess;
     
    out vec2 ex_TexCoord;
    out vec3 ex_EyeSpaceVert;
    out vec3 ex_EyeSpaceTangent;
    out vec3 ex_EyeSpaceBinormal;
    out vec3 ex_EyeSpaceNormal;
    out vec3 ex_EyeSpaceLight;
     
    out vec4 ex_AmbientLight;
    out vec4 ex_MatAmbient;
    out vec4 ex_MatDiffuse;
    out vec4 ex_MatSpecular;
    out float ex_MatShininess;
    out vec4 ex_LightSpecular;
    out vec4 ex_LightDiffuse;
    out vec4 ex_LightAmbient;
     
    float length( vec3 p_vector)
    {
    	return sqrt( p_vector.x * p_vector.x + p_vector.y * p_vector.y + p_vector.z * p_vector.z);
    }
     
    void main()
    {
    	vec3 binormal = cross( tangent, normal);
     
    	ex_EyeSpaceTangent = NormalMatrix * tangent;
    	ex_EyeSpaceBinormal = NormalMatrix * binormal;
    	ex_EyeSpaceNormal = NormalMatrix * normal;
     
    	ex_AmbientLight = in_AmbientLight;
    	ex_MatAmbient = in_MatAmbient;
    	ex_MatDiffuse = in_MatDiffuse;
    	ex_MatSpecular = in_MatSpecular;
    	ex_MatShininess = in_MatShininess;
     
    	ex_TexCoord = texture.xy;
     
    	ex_LightSpecular = vec4( 0.0);
    	ex_LightDiffuse = vec4( 0.0);
    	ex_LightAmbient = vec4( 0.0);
     
    	ex_EyeSpaceVert = (ModelViewMatrix * vertex).xyz;
    	ex_EyeSpaceLight = (ModelViewMatrix * in_LightsPosition[0]).xyz;
     
    	ex_LightSpecular += in_LightsSpecular[0] * in_MatSpecular;
    	ex_LightDiffuse += in_LightsDiffuse[0] * in_MatDiffuse;
    	ex_LightAmbient += in_LightsAmbient[0] * in_MatAmbient;
     
    	gl_Position = ProjectionModelViewMatrix * vertex;
    }
     
    //FRAGMENT SHADER
     
    #version 140
     
    uniform float Depth;
    uniform float Tile;
    uniform int LinearSearchSteps;
    uniform int BinarySearchSteps;
     
    in vec2 ex_TexCoord;
    in vec3 ex_EyeSpaceVert;
    in vec3 ex_EyeSpaceTangent;
    in vec3 ex_EyeSpaceBinormal;
    in vec3 ex_EyeSpaceNormal;
    in vec3 ex_EyeSpaceLight;
     
    uniform sampler2D DiffuseMap;
    uniform sampler2D NormalMap;
     
    in vec4 ex_AmbientLight;
    in vec4 ex_MatAmbient;
    in vec4 ex_MatDiffuse;
    in vec4 ex_MatSpecular;
    in float ex_MatShininess;
    in vec4 ex_LightSpecular;
    in vec4 ex_LightDiffuse;
    in vec4 ex_LightAmbient;
     
    out vec4 out_FragColor;
     
    float RayIntersectRM( in vec2 dp, in vec2 ds);
     
    void main()
    {
    	vec4 l_vAmbient = ex_AmbientLight * ex_MatAmbient;
    	vec4 l_vSpecular = vec4( 0.0);
    	vec4 l_vDiffuse = vec4( 0.0);
    	float l_fShine = ex_MatShininess;
     
    	l_vAmbient += ex_LightAmbient;
    	l_vSpecular += ex_LightSpecular;
    	l_vDiffuse += ex_LightDiffuse;
     
    	vec4 l_vTextureRelief;
    	vec4 l_vTextureColour;
    	vec3 l_vTmp1;
    	vec3 l_vTmp2;
    	vec3 l_eyeSpaceVertex;
    	vec3 l_vLightDirection;
    	vec2 l_vUV;
    	float l_fDot;
    	float d;
    	vec2 dp, ds;
     
    	// ray intersect in view direction
    	l_vTmp2  = ex_EyeSpaceVert;
    	l_eyeSpaceVertex = normalize( l_vTmp2);
    	l_fDot  = dot( ex_EyeSpaceNormal, -l_eyeSpaceVertex);
    	l_vTmp1  = normalize( vec3( dot( l_eyeSpaceVertex, ex_EyeSpaceTangent), dot( l_eyeSpaceVertex, ex_EyeSpaceBinormal), l_fDot));
    	l_vTmp1  *= Depth / l_fDot;
    	dp = ex_TexCoord * Tile;
    	ds = l_vTmp1.xy;
    	d  = RayIntersectRM( dp, ds);
     
    	// get rm and color texture points
    	l_vUV = dp + ds * d;
    	l_vTextureRelief = texture2D( NormalMap, l_vUV);
    	l_vTextureColour = texture2D( DiffuseMap, l_vUV);
     
    	// expand normal from normal map in local polygon space
    	l_vTextureRelief.xy = l_vTextureRelief.xy * 2.0 - 1.0;
    	l_vTextureRelief.z = sqrt( 1.0 - dot( l_vTextureRelief.xy, l_vTextureRelief.xy));
    	l_vTextureRelief.xyz = normalize( l_vTextureRelief.x * ex_EyeSpaceTangent + l_vTextureRelief.y * ex_EyeSpaceBinormal + l_vTextureRelief.z * ex_EyeSpaceNormal);
     
    	// compute light direction
    	l_vTmp2 += l_eyeSpaceVertex * d * l_fDot;
    	l_vLightDirection = normalize( l_vTmp2 - ex_EyeSpaceLight.xyz);
     
    	// ray intersect in light direction
    	dp += ds * d;
    	l_fDot  = dot( ex_EyeSpaceNormal, -l_vLightDirection);
    	l_vTmp1  = normalize( vec3( dot( l_vLightDirection, ex_EyeSpaceTangent), dot( l_vLightDirection, ex_EyeSpaceBinormal), l_fDot));
    	l_vTmp1 *= Depth / l_fDot;
    	ds = l_vTmp1.xy;
    	dp -= ds * d;
    	float dl = RayIntersectRM( dp, l_vTmp1.xy);
    	float l_fShadow = 1.0;
    	vec3 l_vSpecularShadow = l_vSpecular.xyz;
     
    	if (dl < d - 0.05) // if pixel in shadow
    	{
    		l_fShadow = dot( l_vAmbient.xyz, vec3( 1.0)) * 0.333333;
    		l_vSpecularShadow = vec3( 0.0);
    	}
     
    	// compute diffuse and specular terms
    	float l_fAttenuation = max( 0.0, dot( -l_vLightDirection, ex_EyeSpaceNormal));
    	float l_fDiffuseTerm = l_fShadow * max( 0.0, dot( -l_vLightDirection, l_vTextureRelief.xyz));
    	float l_fSpecularTerm = max( 0.0, dot( normalize( -l_vLightDirection - l_eyeSpaceVertex), l_vTextureRelief.xyz));
     
    	// compute final color
    	vec4 l_vFinalColour;
    	l_vFinalColour.xyz = l_vAmbient.xyz * l_vTextureColour.xyz + l_fAttenuation * (l_vTextureColour.xyz * l_vDiffuse.xyz * l_fDiffuseTerm + l_vSpecularShadow * pow( l_fSpecularTerm, l_fShine));
    	l_vFinalColour.w = 1.0;
    	out_FragColor = vec4( l_vFinalColour.rgb, 1.0);
    }
     
    float RayIntersectRM( in vec2 p_vDP, in vec2 p_vDS)
    {
    	float l_fDepthStep = 1.0 / float( LinearSearchSteps);
     
    	// current size of search window
    	float l_fSize = l_fDepthStep;
    	// current depth position
    	float l_fDepth = 0.0;
    	// best match found (starts with last position 1.0)
    	float l_fDepthReturn = 1.0;
    	vec4 l_vTexColour;
     
    	// search front to back for first point inside object
    	for (int i = 0 ; i < LinearSearchSteps - 1 ; i++)
    	{
    		l_fDepth += l_fSize;
    		l_vTexColour = texture2D( NormalMap, p_vDP + p_vDS * l_fDepth);
     
    		if (l_fDepthReturn > 0.996)   // if no depth found yet
    		{
    			if (l_fDepth >= l_vTexColour.w)
    			{
    				l_fDepthReturn = l_fDepth;   // store best depth
    			}
    		}
    	}
     
    	l_fDepth = l_fDepthReturn;
     
    	// recurse around first point (l_fDepth) for closest match
    	for (int i = 0 ; i < BinarySearchSteps ; i++)
    	{
    		l_fSize *= 0.5;
    		l_vTexColour = texture2D( NormalMap, p_vDP + p_vDS * l_fDepth);
     
    		if (l_fDepth >= l_vTexColour.w)
    		{
    			l_fDepthReturn = l_fDepth;
    			l_fDepth -= 2.0 * l_fSize;
    		}
     
    		l_fDepth += l_fSize;
    	}
     
    	return l_fDepthReturn;
    }
    HLSL :
    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
    float4x4 ProjectionModelViewMatrix;
    float4x4 ProjectionMatrix;
    float4x4 ModelViewMatrix;
    float3x3 NormalMatrix;
     
    float4 in_LightsPosition[8];
    float4 in_LightsSpecular[8];
    float4 in_LightsDiffuse[8];
    float4 in_LightsAmbient[8];
    float4 in_AmbientLight;
    float4 in_MatAmbient;
    float4 in_MatDiffuse;
    float4 in_MatSpecular;
    float in_MatShininess;
     
    float Depth;
    float Tile;
    int LinearSearchSteps;
    int BinarySearchSteps;
     
    sampler2D DiffuseMap;
    sampler2D NormalMap;
     
    struct VtxInput
    {
    	float3 tangent	:	TANGENT;
    	float4 vertex	:	POSITION0;
    	float3 normal	:	NORMAL0;
    	float2 Texture	:	TEXCOORD0;
    };
     
    struct VtxOutput
    {
    	float4 Position		:	POSITION0;
    	float3 vertex		:	POSITION1;
    	float3 tangent		:	NORMAL0;
    	float3 binormal		:	NORMAL1;
    	float3 normal		:	NORMAL2;
    	float2 Texture		:	TEXCOORD0;
    };
     
    float RayIntersectRM( in float2 dp, in float2 ds);
     
    float length( float3 p_vector)
    {
    	return sqrt( p_vector.x * p_vector.x + p_vector.y * p_vector.y + p_vector.z * p_vector.z);
    }
     
    VtxOutput mainVx( in VtxInput p_input)
    {
    	VtxOutput l_output;
    	float3 binormal = cross( p_input.tangent, p_input.normal);
    	float3x3 l_normalMatrix = (float3x3)NormalMatrix;
     
    	l_output.tangent = mul( p_input.tangent, l_normalMatrix);
    	l_output.binormal = mul( binormal, l_normalMatrix);
    	l_output.normal = mul( p_input.normal, l_normalMatrix);
    	l_output.vertex = mul( p_input.vertex, ModelViewMatrix).xyz;
    	l_output.Texture = p_input.Texture;
    	l_output.Position = mul( p_input.vertex, ProjectionModelViewMatrix);
     
    	return l_output;
    }
     
    float4 mainPx( in VtxOutput p_input) : COLOR0
    {
    	float4 l_vAmbient = in_LightsAmbient[0] * in_MatAmbient;
    	float3 l_vLight = mul( in_LightsPosition[0], ModelViewMatrix).xyz;
    	float4 l_vSpecular = float4( 0, 0, 0, 0);
    	float4 l_vDiffuse = float4( 0, 0, 0, 0);
    	float l_fShine = in_MatShininess;
     
    	l_vAmbient += in_MatAmbient * in_LightsAmbient[0];
    	l_vSpecular += in_MatSpecular * in_LightsSpecular[0];
    	l_vDiffuse += in_MatDiffuse * in_LightsDiffuse[0];
     
    	float4 l_vTextureRelief;
    	float4 l_vTextureColour;
    	float3 l_vTmp1;
    	float3 l_vTmp2;
    	float3 l_eyeSpaceVertex;
    	float3 l_vLightDirection;
    	float2 l_vUV;
    	float l_fDot;
    	float d;
    	float2 dp, ds;
     
    	// ray intersect in view direction
    	l_vTmp2  = p_input.vertex;
    	l_eyeSpaceVertex = normalize( l_vTmp2);
    	l_fDot  = dot( p_input.normal, -l_eyeSpaceVertex);
    	l_vTmp1  = normalize( float3( dot( l_eyeSpaceVertex, p_input.tangent), dot( l_eyeSpaceVertex, p_input.binormal), l_fDot));
    	l_vTmp1  *= Depth / l_fDot;
    	dp = p_input.Texture * Tile;
    	ds = l_vTmp1.xy;
    	d  = RayIntersectRM( dp, ds);
     
    	// get rm and color texture points
    	l_vUV = dp + ds * d;
    	l_vTextureRelief = tex2D( NormalMap, l_vUV);
    	l_vTextureColour = tex2D( DiffuseMap, l_vUV);
     
    	// expand normal from normal map in local polygon space
    	l_vTextureRelief.xy = l_vTextureRelief.xy * 2.0 - 1.0;
    	l_vTextureRelief.z = sqrt( 1.0 - dot( l_vTextureRelief.xy, l_vTextureRelief.xy));
    	l_vTextureRelief.rgb = normalize( l_vTextureRelief.x * p_input.tangent + l_vTextureRelief.y * p_input.binormal + l_vTextureRelief.z * p_input.normal);
     
    	// compute light direction
    	l_vTmp2 += l_eyeSpaceVertex * d * l_fDot;
    	l_vLightDirection = normalize( l_vTmp2 - l_vLight.xyz);
     
    	// ray intersect in light direction
    	dp += ds * d;
    	l_fDot  = dot( p_input.normal, -l_vLightDirection);
    	l_vTmp1  = normalize( float3( dot( l_vLightDirection, p_input.tangent), dot( l_vLightDirection, p_input.normal), l_fDot));
    	l_vTmp1 *= Depth / l_fDot;
    	ds = l_vTmp1.xy;
    	dp -= ds * d;
    	float dl = RayIntersectRM( dp, l_vTmp1.xy);
    	float l_fShadow = 1.0;
    	float3 l_vSpecularShadow = l_vSpecular.rgb;
     
    	if (dl < d - 0.05) // if pixel in shadow
    	{
    		l_fShadow = dot( l_vAmbient.rgb, float3( 1, 1, 1)) * 0.333333;
    		l_vSpecularShadow = float3( 0, 0, 0);
    	}
     
    	// compute diffuse and specular terms
    	float l_fAttenuation = max( 0.0, dot( -l_vLightDirection, p_input.normal));
    	float l_fDiffuseTerm = l_fShadow * max( 0.0, dot( -l_vLightDirection, l_vTextureRelief.rgb));
    	float l_fSpecularTerm = max( 0.0, dot( normalize( -l_vLightDirection - l_eyeSpaceVertex), l_vTextureRelief.rgb));
     
    	// compute final color
    	float4 l_vFinalColour;
    	l_vFinalColour.rgb = l_vAmbient.rgb * l_vTextureColour.rgb + l_fAttenuation * (l_vTextureColour.rgb * l_vDiffuse.rgb * l_fDiffuseTerm + l_vSpecularShadow * pow( l_fSpecularTerm, l_fShine));
    	l_vFinalColour.a = 1;
    	return l_vFinalColour;
    }
     
     
    float RayIntersectRM( in float2 p_vDP, in float2 p_vDS)
    {
    	float l_fDepthStep = 1.0 / float( LinearSearchSteps);
     
    	// current size of search window
    	float l_fSize = l_fDepthStep;
    	// current depth position
    	float l_fDepth = 0.0;
    	// best match found (starts with last position 1.0)
    	float l_fDepthReturn = 1.0;
    	float4 l_vTexColour;
    	int i;
     
    	// search front to back for first point inside object
    	for (i = 0 ; i < LinearSearchSteps - 1 ; i++)
    	{
    		l_fDepth += l_fSize;
    		l_vTexColour = tex2Dlod( NormalMap, float4( p_vDP + p_vDS * l_fDepth, 0, 0));
     
    		if (l_fDepthReturn > 0.996)   // if no depth found yet
    		{
    			if (l_fDepth >= l_vTexColour.w)
    			{
    				l_fDepthReturn = l_fDepth;   // store best depth
    			}
    		}
    	}
     
    	l_fDepth = l_fDepthReturn;
     
    	// recurse around first point (l_fDepth) for closest match
    	for (i = 0 ; i < BinarySearchSteps ; i++)
    	{
    		l_fSize *= 0.5;
    		l_vTexColour = tex2Dlod( NormalMap, float4( p_vDP + p_vDS * l_fDepth, 0, 0));
     
    		if (l_fDepth >= l_vTexColour.w)
    		{
    			l_fDepthReturn = l_fDepth;
    			l_fDepth -= 2.0 * l_fSize;
    		}
     
    		l_fDepth += l_fSize;
    	}
     
    	return l_fDepthReturn;
    }
    Si vous ne trouvez plus rien, cherchez autre chose...

    Vous trouverez ici des tutoriels OpenGL moderne.
    Mon moteur 3D: Castor 3D, presque utilisable (venez participer, il y a de la place)!
    Un projet qui ne sert à rien, mais qu'il est joli (des fois) : ProceduralGenerator (Génération procédurale d'images, et post-processing).

  2. #2
    Expert éminent sénior
    Avatar de Mat.M
    Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2006
    Messages
    8 352
    Détails du profil
    Informations personnelles :
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Novembre 2006
    Messages : 8 352
    Points : 20 359
    Points
    20 359
    Par défaut
    Salut euhhh ou je vois mal ou je suis neuneu mais je ne vois pas de différences notoires
    Peut-être que cela vient de la fonction DXLoadTextureFromFile; il faut la paramêtrer de certaines manières ( format ARGB, RGBA ...c'est un peu prise-de-tête il faut l'avouer)

  3. #3
    Inactif  


    Homme Profil pro
    Inscrit en
    Novembre 2008
    Messages
    5 288
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Secteur : Santé

    Informations forums :
    Inscription : Novembre 2008
    Messages : 5 288
    Points : 15 620
    Points
    15 620
    Par défaut
    on voit mieux en faisant un zoom...
    Images attachées Images attachées  

  4. #4
    Expert éminent sénior

    Avatar de dragonjoker59
    Homme Profil pro
    Software Developer
    Inscrit en
    Juin 2005
    Messages
    2 045
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Software Developer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2005
    Messages : 2 045
    Points : 11 368
    Points
    11 368
    Billets dans le blog
    10
    Par défaut
    Pour le chargement des textures, je vous mets le code en question, je ne me sers pas de DXLoadTextureFromFile car je charge l'image moi-même ailleurs.

    Côté Direct3D
    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
     
    IDirect3DDevice9 * l_pDevice = Dx9RenderSystem::GetDevice();
    CheckDxError( l_pDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU,  D3dEnum::Get( m_target->GetWrapMode( 0))), CU_T( "SetSamplerState - D3DSAMP_ADDRESSU"), false);
    CheckDxError( l_pDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV,  D3dEnum::Get( m_target->GetWrapMode( 1))), CU_T( "SetSamplerState - D3DSAMP_ADDRESSV"), false);
    CheckDxError( l_pDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3dEnum::Get( m_target->GetInterpolationMode( 0))), CU_T( "SetSamplerState - D3DSAMP_MINFILTER"), false);
    CheckDxError( l_pDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3dEnum::Get( m_target->GetInterpolationMode( 1))), CU_T( "SetSamplerState - D3DSAMP_MAGFILTER"), false);
    CheckDxError( l_pDevice->SetSamplerState( 0, D3DSAMP_MIPFILTER, D3DTEXF_NONE), CU_T( "SetSamplerState - D3DSAMP_MIPFILTER"), false);
    CheckDxError( l_pDevice->CreateTexture( m_target->GetWidth(), m_target->GetHeight(), 0, D3DUSAGE_AUTOGENMIPMAP, D3dEnum::Get( m_target->GetPixelFormat()), D3DPOOL_MANAGED, & m_pTextureObject, NULL), CU_T( "Can't create texture"), true);
     
    D3DLOCKED_RECT l_lockedRect;
    RECT l_rcLock = { 0, 0, m_target->GetWidth(), m_target->GetHeight() };
    CheckDxError( m_pTextureObject->LockRect( 0, & l_lockedRect, & l_rcLock, 0), CU_T( "LockRect"), false);
    unsigned char * l_pDestPix = reinterpret_cast<unsigned char *>( l_lockedRect.pBits);
    const unsigned char * l_pSrcPix = m_target->GetImagePixels();
    unsigned int l_uiBpp = Castor::Resources::GetBytesPerPixel( m_target->GetPixelFormat());
    std::copy( l_pSrcPix, l_pSrcPix + m_target->GetWidth() * l_uiBpp * m_target->GetHeight(), l_pDestPix);
    CheckDxError( m_pTextureObject->UnlockRect( 0), CU_T( "UnlockRect"), false);
    Côté OpenGL
    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
     
    int l_textureType = GlEnum::Get( m_target->GetTextureType());
    CheckGlError( glBindTexture( l_textureType, m_glTexName), CU_T( "glBindTexture"));
     
    CheckGlError( glTexParameteri( l_textureType, GL_TEXTURE_WRAP_S, GlEnum::Get( m_target->GetWrapMode( 0))), CU_T( "glTexParameteri - GL_TEXTURE_WRAP_S"));
    CheckGlError( glTexParameteri( l_textureType, GL_TEXTURE_WRAP_T, GlEnum::Get( m_target->GetWrapMode( 1))), CU_T( "GglTexParameteri - GL_TEXTURE_WRAP_T"));
    CheckGlError( glTexParameteri( l_textureType, GL_TEXTURE_MIN_FILTER, GlEnum::Get( m_target->GetInterpolationMode( 0))), CU_T( "glTexParameteri - GL_TEXTURE_MIN_FILTER"));
    CheckGlError( glTexParameteri( l_textureType, GL_TEXTURE_MAG_FILTER, GlEnum::Get( m_target->GetInterpolationMode( 1))), CU_T( "glTexParameteri - GL_TEXTURE_MAG_FILTER"));
     
    GlEnum::GlPixelFmt l_glPixelFmt = GlEnum::Get( m_target->GetPixelFormat());
    CheckGlError( glTexImage2D( l_textureType, 0, l_glPixelFmt .Internal, m_target->GetWidth(), m_target->GetHeight(), 0, l_glPixelFmt .Format, l_glPixelFmt .Type, m_target->GetImagePixels()), CU_T( "glTexImage2D"));
     
    if (glGenerateMipmap == NULL)
    {
    	CheckGlError( glGenerateMipmapEXT( l_textureType), CU_T( "glGenerateMipmapEXT"));
    }
    else
    {
    	CheckGlError( glGenerateMipmap( l_textureType), CU_T( "glGenerateMipmap"));
    }
    Si vous ne trouvez plus rien, cherchez autre chose...

    Vous trouverez ici des tutoriels OpenGL moderne.
    Mon moteur 3D: Castor 3D, presque utilisable (venez participer, il y a de la place)!
    Un projet qui ne sert à rien, mais qu'il est joli (des fois) : ProceduralGenerator (Génération procédurale d'images, et post-processing).

  5. #5
    Membre expérimenté

    Profil pro
    Programmeur
    Inscrit en
    Août 2002
    Messages
    1 091
    Détails du profil
    Informations personnelles :
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : Programmeur

    Informations forums :
    Inscription : Août 2002
    Messages : 1 091
    Points : 1 679
    Points
    1 679
    Par défaut
    Tu n'utilises pas un point filter là où il faudrait un bilinear filter ?

    aussi si tu affiches une texture alignée sur les pixels de l'écran à bien faire attention aux conventions différentes d'OpenGL et D3D (un gros piège à noob.. et parfois moins noobs http://developer.nvidia.com/object/M...ls_Pixels.html )

    Mon site web | Mon blog | Mes photos | Groupe USA
    > BONJOUR, JE SUIS NOUVEAU SUR CE FORUM
    > presse la touche caps lock, stp
    > OH.. MERCI C EST BEAUCOUP PLUS FACILE COMME CA

  6. #6
    Expert éminent sénior

    Avatar de dragonjoker59
    Homme Profil pro
    Software Developer
    Inscrit en
    Juin 2005
    Messages
    2 045
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Software Developer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2005
    Messages : 2 045
    Points : 11 368
    Points
    11 368
    Billets dans le blog
    10
    Par défaut
    Pour le filtre, j'utilise bien un linear (j'ai aussi essayé avec anisotropic, mais sans résultat). Pour ma texture, elle est juste mappée sur un cube avec un UV tout con (0 ou 1 en x et en y en fonction du vertex)
    Si vous ne trouvez plus rien, cherchez autre chose...

    Vous trouverez ici des tutoriels OpenGL moderne.
    Mon moteur 3D: Castor 3D, presque utilisable (venez participer, il y a de la place)!
    Un projet qui ne sert à rien, mais qu'il est joli (des fois) : ProceduralGenerator (Génération procédurale d'images, et post-processing).

  7. #7
    Membre actif
    Avatar de Mikmacer
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2006
    Messages
    116
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2006
    Messages : 116
    Points : 241
    Points
    241
    Par défaut
    Est-ce que tu as essayé de forcer le filtre bilinéaire/Trilinéaire dans le shader directement?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    texture MaTexture;
    sampler2D monSampler = sampler_state
    {
        Texture = (MaTexture);
        AddressU = clamp;
        AddressV = clamp;
        MagFilter = LINEAR;
        MinFilter = LINEAR;
        Mipfilter = LINEAR;
    };

  8. #8
    Expert éminent sénior

    Avatar de dragonjoker59
    Homme Profil pro
    Software Developer
    Inscrit en
    Juin 2005
    Messages
    2 045
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Software Developer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2005
    Messages : 2 045
    Points : 11 368
    Points
    11 368
    Billets dans le blog
    10
    Par défaut
    Merci pour cette astuce, je testerai ça. Je vous tiens au courant
    Si vous ne trouvez plus rien, cherchez autre chose...

    Vous trouverez ici des tutoriels OpenGL moderne.
    Mon moteur 3D: Castor 3D, presque utilisable (venez participer, il y a de la place)!
    Un projet qui ne sert à rien, mais qu'il est joli (des fois) : ProceduralGenerator (Génération procédurale d'images, et post-processing).

  9. #9
    Membre éprouvé Avatar de oxyde356
    Homme Profil pro
    Ingénieur Recherche Imagerie
    Inscrit en
    Février 2006
    Messages
    797
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur Recherche Imagerie

    Informations forums :
    Inscription : Février 2006
    Messages : 797
    Points : 1 087
    Points
    1 087
    Par défaut
    C'est clairement un problème de filtre. Si tu regarde en bas a droite de ta texture elle n'est pas lissée de la même façon (je ne parle pas du reflet simplement de la texture). Du coup, le calcul lumineux est bien le même mais dans le cas de directx il n'est pas lissé alors qu'avec opengl il l'est.

  10. #10
    Expert éminent sénior

    Avatar de dragonjoker59
    Homme Profil pro
    Software Developer
    Inscrit en
    Juin 2005
    Messages
    2 045
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Software Developer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2005
    Messages : 2 045
    Points : 11 368
    Points
    11 368
    Billets dans le blog
    10
    Par défaut
    C'est ce que j'avais remarqué aussi, mais je ne pensais devoir forcer le filtrage dans le shader. Je n'ai pas encore pu tester ça malgré tout (taf, famille, tout ça...)
    Si vous ne trouvez plus rien, cherchez autre chose...

    Vous trouverez ici des tutoriels OpenGL moderne.
    Mon moteur 3D: Castor 3D, presque utilisable (venez participer, il y a de la place)!
    Un projet qui ne sert à rien, mais qu'il est joli (des fois) : ProceduralGenerator (Génération procédurale d'images, et post-processing).

  11. #11
    Expert éminent sénior

    Avatar de dragonjoker59
    Homme Profil pro
    Software Developer
    Inscrit en
    Juin 2005
    Messages
    2 045
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Software Developer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2005
    Messages : 2 045
    Points : 11 368
    Points
    11 368
    Billets dans le blog
    10
    Par défaut
    Bon, ben après test, ce n'est toujours pas ça ...
    Là je suis perdu, car il me semblait aussi que ça venait du filtre, mais il est linéaire au niveau de la création de la texture, forcé linéaire au niveau du shader, et j'ai toujours le problème ... argh !
    Si vous ne trouvez plus rien, cherchez autre chose...

    Vous trouverez ici des tutoriels OpenGL moderne.
    Mon moteur 3D: Castor 3D, presque utilisable (venez participer, il y a de la place)!
    Un projet qui ne sert à rien, mais qu'il est joli (des fois) : ProceduralGenerator (Génération procédurale d'images, et post-processing).

  12. #12
    Membre éprouvé Avatar de oxyde356
    Homme Profil pro
    Ingénieur Recherche Imagerie
    Inscrit en
    Février 2006
    Messages
    797
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur Recherche Imagerie

    Informations forums :
    Inscription : Février 2006
    Messages : 797
    Points : 1 087
    Points
    1 087
    Par défaut
    Essaye de faire en sorte de retomber sur le même problème du côté d'OpenGL (dès fois cela permet de trouver le problème et ça solution).

  13. #13
    Expert éminent sénior

    Avatar de dragonjoker59
    Homme Profil pro
    Software Developer
    Inscrit en
    Juin 2005
    Messages
    2 045
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Software Developer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2005
    Messages : 2 045
    Points : 11 368
    Points
    11 368
    Billets dans le blog
    10
    Par défaut
    En fait je n'arrive pas à retomber sur le même problème en OpenGL.
    Si je passe en filtre nearest (ou point en Direct3D) je n'ai pas le même rendu qu'actuellement, donc il s'agit d'un problème indépendant du filtre.
    Par contre je me pose une question con : j'utilise 'tex2Dlod' dans la fonction 'RayIntersectRM' du code HLSL. tex2D ne peut pas être utilisé car j'ai l'erreur suivante :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    warning X3553: can't use gradient instructions in loops with break, forcing loop to unroll
    error X3511: unable to unroll loop, loop does not appear to terminate in a timely manner (1024 iterations)
    Est-ce que le problème pourrait venir de là ?
    Si vous ne trouvez plus rien, cherchez autre chose...

    Vous trouverez ici des tutoriels OpenGL moderne.
    Mon moteur 3D: Castor 3D, presque utilisable (venez participer, il y a de la place)!
    Un projet qui ne sert à rien, mais qu'il est joli (des fois) : ProceduralGenerator (Génération procédurale d'images, et post-processing).

Discussions similaires

  1. [Windows] Différence d'affichage OpenGL entre Windows XP et Linux/Seven
    Par Rémininho dans le forum Plateformes
    Réponses: 3
    Dernier message: 29/07/2010, 12h14
  2. Rendu avec OpenGL (et normales de face vs de points)
    Par gilouu dans le forum Développement 2D, 3D et Jeux
    Réponses: 2
    Dernier message: 13/12/2009, 23h25
  3. Rendu cartoon OpenGl
    Par fafacpp dans le forum OpenGL
    Réponses: 4
    Dernier message: 15/03/2007, 18h29
  4. Rendu neutre sous Direct3D
    Par Freakazoid dans le forum DirectX
    Réponses: 20
    Dernier message: 17/08/2004, 14h35
  5. Rendu OpenGL offscreen sous Windows
    Par rincevent_123 dans le forum OpenGL
    Réponses: 3
    Dernier message: 28/11/2003, 10h23

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